dzmu commited on
Commit
72aacf9
·
verified ·
1 Parent(s): 7fbb944

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -50
app.py CHANGED
@@ -16,42 +16,20 @@ clip_model, clip_preprocess = clip.load("ViT-B/32", device=device)
16
  yolo_model = YOLO('yolov8n.pt').to(device)
17
  fashion_model = YOLO('best.pt').to(device)
18
 
19
- # Style prompts and categories
20
  style_prompts = {
21
- 'drippy': [
22
- "avant-garde streetwear", "high-fashion designer outfit", "trendsetting urban attire",
23
- "luxury sneakers and chic accessories", "cutting-edge, bold style"
24
- ],
25
- 'mid': [
26
- "casual everyday outfit", "modern minimalistic attire", "comfortable yet stylish look",
27
- "simple, relaxed streetwear", "balanced, practical fashion"
28
- ],
29
- 'not_drippy': [
30
- "disheveled outfit", "poorly coordinated fashion", "unfashionable, outdated attire",
31
- "tacky, mismatched ensemble", "sloppy, uninspired look"
32
- ]
33
  }
34
 
35
  clothing_prompts = [
36
- "t-shirt", "dress shirt", "blouse", "hoodie", "jacket", "sweater", "coat", "dress", "skirt",
37
- "pants", "jeans", "trousers", "shorts", "sneakers", "boots", "heels", "sandals", "cap", "hat",
38
- "scarf", "gloves", "bag", "accessory", "tank-top", "haircut"
39
  ]
40
 
41
  response_templates = {
42
- 'drippy': [
43
- "You're Drippy, bruh fire {item}!", "{item} goes crazy, on god!",
44
- "Certified drippy with that {item}."
45
- ],
46
- 'mid': [
47
- "Drop the {item} and you might get a text back.", "It's alright, but I'd upgrade the {item}.",
48
- "Mid fit alert. That {item} is holding you back."
49
- ],
50
- 'not_drippy': [
51
- "Bro thought that {item} was tuff!", "Oh hell nah! Burn that {item}!",
52
- "Crimes against fashion, especially that {item}! Also… maybe get a haircut.",
53
- "Never walk out the house again with that {item}."
54
- ]
55
  }
56
 
57
  CATEGORY_LABEL_MAP = {"drippy": "drippy", "mid": "mid", "not_drippy": "trash"}
@@ -84,7 +62,7 @@ def analyze_outfit(img: Image.Image):
84
  drip_len = len(style_prompts['drippy'])
85
  mid_len = len(style_prompts['mid'])
86
  not_len = len(style_prompts['not_drippy'])
87
-
88
  drip_score = np.mean(probs[:drip_len])
89
  mid_score = np.mean(probs[drip_len:drip_len + mid_len])
90
  not_score = np.mean(probs[drip_len + mid_len:drip_len + mid_len + not_len])
@@ -117,38 +95,29 @@ def analyze_outfit(img: Image.Image):
117
 
118
  return category_html, tts_path, response
119
 
120
- # Gradio UI layout
121
  with gr.Blocks(css="""
122
  .container { max-width: 600px; margin: 0 auto; padding: 2rem; }
123
  button { background-color: #1f04ff; color: white; border: none; padding: 0.75rem 1.5rem; border-radius: 6px; cursor: pointer; font-weight: bold; }
124
  button:hover { background-color: #1500cc; }
125
  #resultbox { border: 1px solid #e3e3e3; border-radius: 10px; padding: 1rem; background: #fafafa; }
126
  """) as demo:
127
-
128
  with gr.Group(elem_classes=["container"]):
129
- input_image = gr.Image(
130
- type='pil',
131
- label="Upload or Take a Picture",
132
- sources=["upload", "webcam", "clipboard"],
133
- image_mode="RGB",
134
- elem_id="custom-image-input"
135
- )
136
- gr.Markdown("""
137
- <p style='margin-top:-10px; font-size: 0.9rem; color: #555;'>
138
- Click the 📷 camera icon to take a photo, the 📁 file icon to upload one, or the 📋 clipboard icon to paste.
139
- </p>
140
- """)
141
- analyze_button = gr.Button("🔥 Analyze My Fit")
142
 
143
  category_html = gr.HTML()
144
  audio_output = gr.Audio(autoplay=True, label="")
145
  response_box = gr.Textbox(label="Response", lines=2, interactive=False)
146
 
147
- analyze_button.click(
148
- fn=analyze_outfit,
149
- inputs=input_image,
150
- outputs=[category_html, audio_output, response_box],
151
- )
152
 
153
  if __name__ == '__main__':
154
  demo.launch()
 
 
16
  yolo_model = YOLO('yolov8n.pt').to(device)
17
  fashion_model = YOLO('best.pt').to(device)
18
 
 
19
  style_prompts = {
20
+ 'drippy': ["avant-garde streetwear", "high-fashion designer outfit", "trendsetting urban attire", "luxury sneakers and chic accessories", "cutting-edge, bold style"],
21
+ 'mid': ["casual everyday outfit", "modern minimalistic attire", "comfortable yet stylish look", "simple, relaxed streetwear", "balanced, practical fashion"],
22
+ 'not_drippy': ["disheveled outfit", "poorly coordinated fashion", "unfashionable, outdated attire", "tacky, mismatched ensemble", "sloppy, uninspired look"]
 
 
 
 
 
 
 
 
 
23
  }
24
 
25
  clothing_prompts = [
26
+ "t-shirt", "dress shirt", "blouse", "hoodie", "jacket", "sweater", "coat", "dress", "skirt", "pants", "jeans", "trousers", "shorts", "sneakers", "boots", "heels", "sandals", "cap", "hat", "scarf", "gloves", "bag", "accessory", "tank-top", "haircut"
 
 
27
  ]
28
 
29
  response_templates = {
30
+ 'drippy': ["You're Drippy, bruh – fire {item}!", "{item} goes crazy, on god!", "Certified drippy with that {item}."],
31
+ 'mid': ["Drop the {item} and you might get a text back.", "It's alright, but I'd upgrade the {item}.", "Mid fit alert. That {item} is holding you back."],
32
+ 'not_drippy': ["Bro thought that {item} was tuff!", "Oh hell nah! Burn that {item}!", "Crimes against fashion, especially that {item}! Also… maybe get a haircut.", "Never walk out the house again with that {item}."]
 
 
 
 
 
 
 
 
 
 
33
  }
34
 
35
  CATEGORY_LABEL_MAP = {"drippy": "drippy", "mid": "mid", "not_drippy": "trash"}
 
62
  drip_len = len(style_prompts['drippy'])
63
  mid_len = len(style_prompts['mid'])
64
  not_len = len(style_prompts['not_drippy'])
65
+
66
  drip_score = np.mean(probs[:drip_len])
67
  mid_score = np.mean(probs[drip_len:drip_len + mid_len])
68
  not_score = np.mean(probs[drip_len + mid_len:drip_len + mid_len + not_len])
 
95
 
96
  return category_html, tts_path, response
97
 
98
+ # Gradio Interface
99
  with gr.Blocks(css="""
100
  .container { max-width: 600px; margin: 0 auto; padding: 2rem; }
101
  button { background-color: #1f04ff; color: white; border: none; padding: 0.75rem 1.5rem; border-radius: 6px; cursor: pointer; font-weight: bold; }
102
  button:hover { background-color: #1500cc; }
103
  #resultbox { border: 1px solid #e3e3e3; border-radius: 10px; padding: 1rem; background: #fafafa; }
104
  """) as demo:
 
105
  with gr.Group(elem_classes=["container"]):
106
+ gr.Markdown("### Upload or Snap a Photo")
107
+
108
+ upload_input = gr.Image(type="pil", label="Upload Image", image_mode="RGB")
109
+ webcam_input = gr.Image(type="pil", source="webcam", label="Take a Photo", image_mode="RGB")
110
+
111
+ analyze_button_upload = gr.Button("Analyze Uploaded Fit")
112
+ analyze_button_webcam = gr.Button("Analyze Webcam Fit")
 
 
 
 
 
 
113
 
114
  category_html = gr.HTML()
115
  audio_output = gr.Audio(autoplay=True, label="")
116
  response_box = gr.Textbox(label="Response", lines=2, interactive=False)
117
 
118
+ analyze_button_upload.click(fn=analyze_outfit, inputs=upload_input, outputs=[category_html, audio_output, response_box])
119
+ analyze_button_webcam.click(fn=analyze_outfit, inputs=webcam_input, outputs=[category_html, audio_output, response_box])
 
 
 
120
 
121
  if __name__ == '__main__':
122
  demo.launch()
123
+