Pontonkid commited on
Commit
5ea3481
Β·
verified Β·
1 Parent(s): 964392f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -41
app.py CHANGED
@@ -1,29 +1,29 @@
1
  import gradio as gr
2
  import torch
3
- from diffusers import StableDiffusionPipeline
4
 
5
- # Load the Stable Diffusion XL model
6
  model_id = "stabilityai/stable-diffusion-xl-base-1.0"
7
- pipe = StableDiffusionPipeline.from_pretrained(
8
  model_id,
9
  torch_dtype=torch.float16,
 
10
  )
11
  pipe = pipe.to("cuda" if torch.cuda.is_available() else "cpu")
12
 
13
- # Function to generate outfit image + suggestion with error handling
14
  def generate_outfit(weather, activity, style):
15
  try:
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
  result = pipe(prompt, guidance_scale=7.5)
24
- image = result.images[0] # Ensure we take the first PIL image
25
 
26
- # Simple outfit suggestion text
27
  suggestion_text = (
28
  f"πŸ’‘ Suggested outfit for {weather} weather, {activity} activity, {style} style:\n"
29
  "- Top: light breathable shirt or jacket depending on weather\n"
@@ -32,39 +32,18 @@ def generate_outfit(weather, activity, style):
32
  "- Accessories: hat, sunglasses, or scarf depending on weather"
33
  )
34
  return image, suggestion_text
 
35
  except Exception as e:
36
- # If something fails, return a placeholder and error text
37
  return None, f"❌ Error generating outfit: {str(e)}"
38
 
39
  # Gradio UI
40
  custom_css = """
41
- body {
42
- background: linear-gradient(135deg, #232526, #414345);
43
- color: white;
44
- font-family: 'Poppins', sans-serif;
45
- }
46
- .gradio-container {
47
- max-width: 900px !important;
48
- margin: auto;
49
- }
50
- h1, h2, h3 {
51
- text-align: center;
52
- color: #fff;
53
- }
54
- .gr-button {
55
- background-color: #00bfa6 !important;
56
- color: white !important;
57
- font-weight: bold;
58
- border-radius: 12px !important;
59
- transition: all 0.3s ease-in-out;
60
- }
61
- .gr-button:hover {
62
- background-color: #007f70 !important;
63
- }
64
- .gr-image {
65
- border-radius: 12px;
66
- box-shadow: 0 0 20px rgba(0,255,255,0.1);
67
- }
68
  """
69
 
70
  with gr.Blocks(css=custom_css) as app:
@@ -73,15 +52,29 @@ with gr.Blocks(css=custom_css) as app:
73
 
74
  with gr.Row():
75
  with gr.Column(scale=1):
76
- weather = gr.Dropdown(["Hot", "Cold", "Rainy", "Snowy", "Mild", "Humid"], label="🌀 Weather", value="Hot")
77
- activity = gr.Dropdown(["Casual", "Work", "Party", "Sporty"], label="πŸƒ Activity", value="Casual")
78
- style = gr.Dropdown(["Casual", "Sporty", "Formal"], label="🎨 Style", value="Casual")
 
 
 
 
 
 
 
 
 
79
  generate_btn = gr.Button("Generate Outfit πŸ‘—", variant="primary")
 
80
  with gr.Column(scale=1):
81
  outfit_image = gr.Image(label="πŸ–Ό Generated Outfit")
82
  outfit_text = gr.Textbox(label="πŸ’‘ Outfit Suggestion", lines=8)
83
 
84
- generate_btn.click(generate_outfit, inputs=[weather, activity, style], outputs=[outfit_image, outfit_text])
 
 
 
 
85
 
86
  app.launch(share=True)
87
 
 
1
  import gradio as gr
2
  import torch
3
+ from diffusers import StableDiffusionXLPipeline
4
 
5
+ # Load SDXL model
6
  model_id = "stabilityai/stable-diffusion-xl-base-1.0"
7
+ pipe = StableDiffusionXLPipeline.from_pretrained(
8
  model_id,
9
  torch_dtype=torch.float16,
10
+ safety_checker=None # Disable safety checker for hackathon demo
11
  )
12
  pipe = pipe.to("cuda" if torch.cuda.is_available() else "cpu")
13
 
14
+ # Function to generate outfit image + suggestion
15
  def generate_outfit(weather, activity, style):
16
  try:
17
  # Build prompt
18
  prompt = (
19
  f"A realistic full-body outfit for {weather} weather, "
20
+ f"{activity} activity, {style} style, front view, 30-degree angle, highly detailed, full body"
21
  )
22
+ # SDXL generates output as a list of PIL images
 
23
  result = pipe(prompt, guidance_scale=7.5)
24
+ image = result.images[0] # take the first image
25
 
26
+ # Outfit suggestion
27
  suggestion_text = (
28
  f"πŸ’‘ Suggested outfit for {weather} weather, {activity} activity, {style} style:\n"
29
  "- Top: light breathable shirt or jacket depending on weather\n"
 
32
  "- Accessories: hat, sunglasses, or scarf depending on weather"
33
  )
34
  return image, suggestion_text
35
+
36
  except Exception as e:
 
37
  return None, f"❌ Error generating outfit: {str(e)}"
38
 
39
  # Gradio UI
40
  custom_css = """
41
+ body {background: linear-gradient(135deg, #232526, #414345); color: white; font-family: 'Poppins', sans-serif;}
42
+ .gradio-container {max-width: 900px !important; margin: auto;}
43
+ h1,h2,h3 {text-align:center; color:#fff;}
44
+ .gr-button {background-color:#00bfa6 !important; color:white !important; font-weight:bold; border-radius:12px !important;}
45
+ .gr-button:hover {background-color:#007f70 !important;}
46
+ .gr-image {border-radius:12px; box-shadow:0 0 20px rgba(0,255,255,0.1);}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
  """
48
 
49
  with gr.Blocks(css=custom_css) as app:
 
52
 
53
  with gr.Row():
54
  with gr.Column(scale=1):
55
+ weather = gr.Dropdown(
56
+ ["Hot", "Cold", "Rainy", "Snowy", "Mild", "Humid"],
57
+ label="🌀 Weather", value="Hot"
58
+ )
59
+ activity = gr.Dropdown(
60
+ ["Casual", "Work", "Party", "Sporty"],
61
+ label="πŸƒ Activity", value="Casual"
62
+ )
63
+ style = gr.Dropdown(
64
+ ["Casual", "Sporty", "Formal"],
65
+ label="🎨 Style", value="Casual"
66
+ )
67
  generate_btn = gr.Button("Generate Outfit πŸ‘—", variant="primary")
68
+
69
  with gr.Column(scale=1):
70
  outfit_image = gr.Image(label="πŸ–Ό Generated Outfit")
71
  outfit_text = gr.Textbox(label="πŸ’‘ Outfit Suggestion", lines=8)
72
 
73
+ generate_btn.click(
74
+ generate_outfit,
75
+ inputs=[weather, activity, style],
76
+ outputs=[outfit_image, outfit_text]
77
+ )
78
 
79
  app.launch(share=True)
80