Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -84,28 +84,47 @@ for cat_prompts in style_prompts.values():
|
|
| 84 |
all_prompts.extend(cat_prompts)
|
| 85 |
style_prompts_end_index = len(all_prompts) # Mark where style prompts end dont mess up loop
|
| 86 |
all_prompts.extend(clothing_prompts)
|
| 87 |
-
print(f"Total prompts for CLIP: {len(all_prompts)}")
|
| 88 |
|
| 89 |
# Response Templates maybe not call out specific item all the time?
|
| 90 |
response_templates = {
|
| 91 |
'drippy': [
|
| 92 |
-
"You're Drippy, bruh – fire {item}!",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
],
|
| 94 |
'mid': [
|
| 95 |
-
"Drop the {item} and you might get a text back.",
|
| 96 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
],
|
| 98 |
'not_drippy': [
|
| 99 |
-
"Bro thought that {item} was tuff!",
|
|
|
|
| 100 |
"Crimes against fashion, especially that {item}! Also… maybe get a haircut.",
|
| 101 |
"Never walk out the house again with that {item}.",
|
| 102 |
-
"Your drip is trash, try again.",
|
| 103 |
"This ain't it chief. The overall style needs work.",
|
| 104 |
-
"Didn't need an AI to tell you to go back to the wardrobe"
|
|
|
|
|
|
|
|
|
|
| 105 |
]
|
| 106 |
}
|
| 107 |
CATEGORY_LABEL_MAP = { "drippy": "drippy", "mid": "mid", "not_drippy": "trash" }
|
| 108 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
# --- Helper Functions ---
|
| 110 |
def get_top_clip_clothing(probs, n=1):
|
| 111 |
"""Gets the top N clothing items based on CLIP probabilities."""
|
|
@@ -216,7 +235,7 @@ def analyze_outfit(input_img: Image.Image):
|
|
| 216 |
|
| 217 |
# Determine overall style category AND DEFINE score_label
|
| 218 |
score_label = "Style Score" # Initialize with a default/fallback
|
| 219 |
-
if drip_score > mid_score and drip_score > not_score:
|
| 220 |
category_key = 'drippy'
|
| 221 |
final_score = drip_score
|
| 222 |
score_label = "Drip Score" # <<< DEFINE score_label
|
|
@@ -287,31 +306,11 @@ def analyze_outfit(input_img: Image.Image):
|
|
| 287 |
# 5) Generate Response and TTS
|
| 288 |
try:
|
| 289 |
response_pool = response_templates[category_key]
|
|
|
|
|
|
|
| 290 |
|
| 291 |
-
#
|
| 292 |
-
|
| 293 |
-
# Give higher chance to generic trash responses if category is 'not_drippy'
|
| 294 |
-
if category_key == 'not_drippy':
|
| 295 |
-
# Mix specific item templates with generic ones
|
| 296 |
-
specific_templates = [t for t in response_pool if '{item}' in t]
|
| 297 |
-
generic_templates = [t for t in response_pool if '{item}' not in t]
|
| 298 |
-
# e.g., 70% chance generic, 30% chance specific item mention (even if generic item name)
|
| 299 |
-
if random.random() < 0.7 or generic_response_needed:
|
| 300 |
-
chosen_template = random.choice(generic_templates if generic_templates else response_pool)
|
| 301 |
-
else:
|
| 302 |
-
chosen_template = random.choice(specific_templates if specific_templates else response_pool)
|
| 303 |
-
else: # Mid or Drippy, but generic needed
|
| 304 |
-
chosen_template = random.choice([t for t in response_pool if '{item}' in t] if not generic_response_needed else response_pool)
|
| 305 |
-
|
| 306 |
-
else: # Drippy or Mid, and we have a specific item
|
| 307 |
-
chosen_template = random.choice([t for t in response_pool if '{item}' in t])
|
| 308 |
-
|
| 309 |
-
# Format the response, substituting the determined item name
|
| 310 |
-
# Handle cases where the chosen template might be generic and doesn't have {item}
|
| 311 |
-
if '{item}' in chosen_template:
|
| 312 |
-
response_text = chosen_template.format(item=final_clothing_item)
|
| 313 |
-
else:
|
| 314 |
-
response_text = chosen_template # Use the generic template as is
|
| 315 |
|
| 316 |
tts_path = os.path.join(tempfile.gettempdir(), f"drip_{uuid.uuid4().hex}.mp3")
|
| 317 |
tts = gTTS(text=response_text, lang='en', tld='com', slow=False)
|
|
@@ -325,10 +324,9 @@ def analyze_outfit(input_img: Image.Image):
|
|
| 325 |
<p class='result-score'>{score_label}: {percentage_score_str}</p>
|
| 326 |
</div>
|
| 327 |
"""
|
| 328 |
-
#<p class='result-score'>Style Score: {final_score_str}</p>
|
| 329 |
return category_html, tts_path, response_text
|
| 330 |
|
| 331 |
-
|
| 332 |
print(f"Error during response/TTS generation: {e}")
|
| 333 |
percentage_score = max(0, final_score * 100)
|
| 334 |
percentage_score_str = f"{percentage_score:.0f}%"
|
|
|
|
| 84 |
all_prompts.extend(cat_prompts)
|
| 85 |
style_prompts_end_index = len(all_prompts) # Mark where style prompts end dont mess up loop
|
| 86 |
all_prompts.extend(clothing_prompts)
|
| 87 |
+
#print(f"Total prompts for CLIP: {len(all_prompts)}")
|
| 88 |
|
| 89 |
# Response Templates maybe not call out specific item all the time?
|
| 90 |
response_templates = {
|
| 91 |
'drippy': [
|
| 92 |
+
"You're Drippy, bruh – fire {item}!",
|
| 93 |
+
"{item} goes crazy, on god!",
|
| 94 |
+
"Certified drippy with that {item}.",
|
| 95 |
+
"Your {item} just walked a Paris runway.",
|
| 96 |
+
"That {item}? Straight from the future.",
|
| 97 |
+
"You just turned a sidewalk into a runway."
|
| 98 |
],
|
| 99 |
'mid': [
|
| 100 |
+
"Drop the {item} and you might get a text back.",
|
| 101 |
+
"It's alright, but I'd upgrade the {item}.",
|
| 102 |
+
"Mid fit alert. That {item} is holding you back.",
|
| 103 |
+
"We can do better come on now",
|
| 104 |
+
"I don't think you want it enough",
|
| 105 |
+
"You're teetering on drip... fix the {item}.",
|
| 106 |
+
"You're in the gray zone. That {item} ain't helping."
|
| 107 |
],
|
| 108 |
'not_drippy': [
|
| 109 |
+
"Bro thought that {item} was tuff!",
|
| 110 |
+
"Oh hell nah! Burn that {item}!",
|
| 111 |
"Crimes against fashion, especially that {item}! Also… maybe get a haircut.",
|
| 112 |
"Never walk out the house again with that {item}.",
|
| 113 |
+
"Your drip is trash, try again.",
|
| 114 |
"This ain't it chief. The overall style needs work.",
|
| 115 |
+
"Didn't need an AI to tell you to go back to the wardrobe",
|
| 116 |
+
"Someone call the fashion police. That {item} needs arresting.",
|
| 117 |
+
"Your outfit just gave me a 404 error.",
|
| 118 |
+
"That {item} made my GPU overheat in shame."
|
| 119 |
]
|
| 120 |
}
|
| 121 |
CATEGORY_LABEL_MAP = { "drippy": "drippy", "mid": "mid", "not_drippy": "trash" }
|
| 122 |
|
| 123 |
+
def format_detected_items(item_list):
|
| 124 |
+
if not item_list:
|
| 125 |
+
return ""
|
| 126 |
+
return "<p class='result-items'>Detected items: " + ", ".join(item_list) + "</p>"
|
| 127 |
+
|
| 128 |
# --- Helper Functions ---
|
| 129 |
def get_top_clip_clothing(probs, n=1):
|
| 130 |
"""Gets the top N clothing items based on CLIP probabilities."""
|
|
|
|
| 235 |
|
| 236 |
# Determine overall style category AND DEFINE score_label
|
| 237 |
score_label = "Style Score" # Initialize with a default/fallback
|
| 238 |
+
if drip_score > 0.41 and drip_score > mid_score and drip_score > not_score:
|
| 239 |
category_key = 'drippy'
|
| 240 |
final_score = drip_score
|
| 241 |
score_label = "Drip Score" # <<< DEFINE score_label
|
|
|
|
| 306 |
# 5) Generate Response and TTS
|
| 307 |
try:
|
| 308 |
response_pool = response_templates[category_key]
|
| 309 |
+
# Choose a random template from the entire response pool
|
| 310 |
+
chosen_template = random.choice(response_pool)
|
| 311 |
|
| 312 |
+
# Format the response, substituting the item name if needed
|
| 313 |
+
response_text = chosen_template.format(item=final_clothing_item) if '{item}' in chosen_template else chosen_template
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 314 |
|
| 315 |
tts_path = os.path.join(tempfile.gettempdir(), f"drip_{uuid.uuid4().hex}.mp3")
|
| 316 |
tts = gTTS(text=response_text, lang='en', tld='com', slow=False)
|
|
|
|
| 324 |
<p class='result-score'>{score_label}: {percentage_score_str}</p>
|
| 325 |
</div>
|
| 326 |
"""
|
|
|
|
| 327 |
return category_html, tts_path, response_text
|
| 328 |
|
| 329 |
+
except Exception as e:
|
| 330 |
print(f"Error during response/TTS generation: {e}")
|
| 331 |
percentage_score = max(0, final_score * 100)
|
| 332 |
percentage_score_str = f"{percentage_score:.0f}%"
|