Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# ClothCast - AI Outfit Forecaster (Hackathon MVP)
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import torch
|
| 4 |
+
from diffusers import StableDiffusionPipeline
|
| 5 |
+
|
| 6 |
+
# Load Stable Diffusion XL Base model
|
| 7 |
+
model_id = "stabilityai/stable-diffusion-xl-base-1.0"
|
| 8 |
+
pipe = StableDiffusionPipeline.from_pretrained(
|
| 9 |
+
model_id,
|
| 10 |
+
torch_dtype=torch.float16
|
| 11 |
+
)
|
| 12 |
+
pipe = pipe.to("cuda" if torch.cuda.is_available() else "cpu")
|
| 13 |
+
|
| 14 |
+
# Function to generate outfit image and suggestion
|
| 15 |
+
def generate_outfit(weather, activity, style):
|
| 16 |
+
# Build prompt
|
| 17 |
+
prompt = (
|
| 18 |
+
f"A realistic full-body outfit for {weather} weather, "
|
| 19 |
+
f"{activity} activity, {style} style, front view, 30-degree angle, 4k detail"
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
# Generate image
|
| 23 |
+
image = pipe(prompt, guidance_scale=7.5).images[0]
|
| 24 |
+
|
| 25 |
+
# Simple outfit suggestion text
|
| 26 |
+
suggestion_text = (
|
| 27 |
+
f"π‘ Suggested outfit for {weather} weather, {activity} activity, {style} style:\n"
|
| 28 |
+
"- Top: light breathable shirt or jacket depending on weather\n"
|
| 29 |
+
"- Bottom: comfortable pants or shorts\n"
|
| 30 |
+
"- Shoes: suitable for activity\n"
|
| 31 |
+
"- Accessories: hat, sunglasses, or scarf depending on weather"
|
| 32 |
+
)
|
| 33 |
+
return image, suggestion_text
|
| 34 |
+
|
| 35 |
+
# Custom CSS for polished UI
|
| 36 |
+
custom_css = """
|
| 37 |
+
body {
|
| 38 |
+
background: linear-gradient(135deg, #232526, #414345);
|
| 39 |
+
color: white;
|
| 40 |
+
font-family: 'Poppins', sans-serif;
|
| 41 |
+
}
|
| 42 |
+
.gradio-container {
|
| 43 |
+
max-width: 900px !important;
|
| 44 |
+
margin: auto;
|
| 45 |
+
}
|
| 46 |
+
h1, h2, h3 {
|
| 47 |
+
text-align: center;
|
| 48 |
+
color: #fff;
|
| 49 |
+
}
|
| 50 |
+
.gr-button {
|
| 51 |
+
background-color: #00bfa6 !important;
|
| 52 |
+
color: white !important;
|
| 53 |
+
font-weight: bold;
|
| 54 |
+
border-radius: 12px !important;
|
| 55 |
+
transition: all 0.3s ease-in-out;
|
| 56 |
+
}
|
| 57 |
+
.gr-button:hover {
|
| 58 |
+
background-color: #007f70 !important;
|
| 59 |
+
}
|
| 60 |
+
.gr-image {
|
| 61 |
+
border-radius: 12px;
|
| 62 |
+
box-shadow: 0 0 20px rgba(0,255,255,0.1);
|
| 63 |
+
}
|
| 64 |
+
"""
|
| 65 |
+
|
| 66 |
+
# Gradio UI
|
| 67 |
+
with gr.Blocks(css=custom_css) as app:
|
| 68 |
+
gr.Markdown("<h1 style='text-align:center;'>π ClothCast - AI Outfit Forecaster</h1>")
|
| 69 |
+
gr.Markdown("<p style='text-align:center;'>Select your weather, activity, and style to generate an AI outfit!</p>")
|
| 70 |
+
|
| 71 |
+
with gr.Row():
|
| 72 |
+
with gr.Column(scale=1):
|
| 73 |
+
weather = gr.Dropdown(
|
| 74 |
+
["Hot", "Cold", "Rainy", "Snowy", "Mild", "Humid"],
|
| 75 |
+
label="π€ Weather", value="Hot"
|
| 76 |
+
)
|
| 77 |
+
activity = gr.Dropdown(
|
| 78 |
+
["Casual", "Work", "Party", "Sporty"],
|
| 79 |
+
label="π Activity", value="Casual"
|
| 80 |
+
)
|
| 81 |
+
style = gr.Dropdown(
|
| 82 |
+
["Casual", "Sporty", "Formal"],
|
| 83 |
+
label="π¨ Style", value="Casual"
|
| 84 |
+
)
|
| 85 |
+
generate_btn = gr.Button("Generate Outfit π", variant="primary")
|
| 86 |
+
|
| 87 |
+
with gr.Column(scale=1):
|
| 88 |
+
outfit_image = gr.Image(label="πΌ Generated Outfit")
|
| 89 |
+
outfit_text = gr.Textbox(label="π‘ Outfit Suggestion", lines=8)
|
| 90 |
+
|
| 91 |
+
# Connect button to function
|
| 92 |
+
generate_btn.click(
|
| 93 |
+
generate_outfit,
|
| 94 |
+
inputs=[weather, activity, style],
|
| 95 |
+
outputs=[outfit_image, outfit_text]
|
| 96 |
+
)
|
| 97 |
+
|
| 98 |
+
# Launch the app
|
| 99 |
+
app.launch(share=True)
|