File size: 22,333 Bytes
3ef3914
 
 
 
 
 
 
813214c
3ef3914
 
1a91629
3ef3914
2abda68
813214c
270c439
 
1a91629
270c439
 
 
 
 
 
 
 
 
 
 
 
 
1a91629
3ef3914
d0d6795
813214c
 
 
 
d0d6795
 
 
 
 
 
 
 
 
1a91629
 
 
 
 
 
813214c
d0d6795
1a91629
813214c
1a91629
 
 
813214c
1a91629
d0d6795
 
 
 
 
1a91629
3ef3914
1a91629
f774fdf
 
 
 
 
 
 
 
9b880d1
 
 
 
 
 
 
 
 
 
57c11ed
1a91629
f774fdf
 
 
 
 
 
 
 
57c11ed
1a91629
f774fdf
 
 
 
 
 
 
 
57c11ed
3ef3914
f774fdf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3ef3914
813214c
aad2489
 
 
 
 
 
 
813214c
aad2489
 
 
813214c
aad2489
3ef3914
813214c
 
3ef3914
1a91629
9dfabc5
 
 
 
 
 
57c11ed
1a91629
9dfabc5
 
9e044ab
9dfabc5
 
 
 
57c11ed
1a91629
9dfabc5
 
57c11ed
d0d6795
9dfabc5
2556624
9dfabc5
 
 
 
57c11ed
3ef3914
aad2489
 
9dfabc5
 
 
 
 
813214c
d0d6795
aad2489
 
 
 
 
813214c
 
d0d6795
aad2489
813214c
d0d6795
 
813214c
d0d6795
 
813214c
d0d6795
 
31f4a97
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
731d945
813214c
731d945
 
 
 
 
 
 
813214c
731d945
 
 
 
 
 
 
 
 
 
 
813214c
731d945
813214c
731d945
 
 
813214c
731d945
 
813214c
731d945
 
 
813214c
731d945
 
 
 
 
 
 
 
 
813214c
731d945
 
813214c
731d945
 
 
 
 
 
 
813214c
731d945
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
813214c
c4c27a4
731d945
 
 
10bd4e9
731d945
 
 
 
 
 
 
 
 
813214c
731d945
 
 
 
2472dd3
731d945
 
813214c
731d945
ef3e7d3
f774fdf
0455d4a
 
 
 
f774fdf
f4a11cd
ad2d71d
e5b956f
f4a11cd
c4c27a4
ad2d71d
f4a11cd
c2e328d
0455d4a
f4a11cd
904253d
f774fdf
 
904253d
f774fdf
 
 
 
 
 
 
0455d4a
 
731d945
ad2d71d
813214c
731d945
 
 
813214c
731d945
 
813214c
731d945
 
 
813214c
731d945
813214c
731d945
 
 
 
 
 
 
813214c
731d945
 
c4c27a4
60f051f
731d945
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
813214c
731d945
 
813214c
731d945
 
 
 
 
 
 
 
 
 
 
 
 
 
f38a310
f15ec02
731d945
 
 
 
 
 
 
 
 
 
 
09efa89
f15ec02
731d945
 
 
 
 
aad2489
e57fcc3
 
 
 
 
 
 
 
 
 
 
 
 
383142e
e57fcc3
 
 
 
 
 
 
1aad467
e57fcc3
383142e
e57fcc3
 
52000a1
e57fcc3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52000a1
e57fcc3
 
 
52000a1
e57fcc3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1aad467
e57fcc3
 
 
 
 
 
 
 
 
 
 
 
 
1aad467
1a91629
813214c
52000a1
813214c
52000a1
1a91629
52000a1
1a91629
ade8c4e
cdd0348
52000a1
76d5e1f
52000a1
96dc8e9
813214c
76d5e1f
52000a1
 
 
 
76d5e1f
52000a1
d0d6795
52000a1
 
 
76d5e1f
52000a1
76d5e1f
1a91629
9c1e7e7
76d5e1f
 
1a91629
813214c
57c11ed
813214c
d0d6795
 
 
 
 
813214c
d0d6795
813214c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
import gradio as gr
import torch
import clip
import numpy as np
import random
import os
from PIL import Image
from ultralytics import YOLO 
from gtts import gTTS
import uuid
import time
import tempfile
from huggingface_hub import hf_hub_download

HF_TOKEN = os.environ.get("HF_TOKEN")

DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
YOLO_PERSON_MODEL_PATH = hf_hub_download(
    repo_id="dzmu/dripai-models",
    filename="yolov8n.pt",
    token=HF_TOKEN,
    repo_type="model"
)

YOLO_FASHION_MODEL_PATH = hf_hub_download(
    repo_id="dzmu/dripai-models",
    filename="best.pt",
    token=HF_TOKEN,
    repo_type="model"
)
CLIP_MODEL_NAME = "ViT-B/32"

# Confidence Thresholds
YOLO_PERSON_CONF_THRESHOLD = 0.4      
YOLO_FASHION_CONF_THRESHOLD = 0.4     
YOLO_FASHION_HIGH_CONF_THRESHOLD = 0.6 


FASHION_CLASSES = {
    0: 'long sleeve top', 1: 'skirt', 2: 'trousers', 3: 'short sleeve top',
    4: 'long sleeve outwear', 5: 'short sleeve dress', 6: 'shorts',
    7: 'vest dress', 8: 'sling dress', 9: 'vest', 10: 'long sleeve dress',
    11: 'sling', 12: 'short sleeve outwear'
}
print(f"Defined {len(FASHION_CLASSES)} fashion categories for {YOLO_FASHION_MODEL_PATH}")

print(f"Using device: {DEVICE}")
try:
    clip_model, clip_preprocess = clip.load(CLIP_MODEL_NAME, device=DEVICE)
    print(f"CLIP model ({CLIP_MODEL_NAME}) loaded successfully.")
except Exception as e:
    print(f"Error loading CLIP model: {e}")


try:
    yolo_person_model = YOLO(YOLO_PERSON_MODEL_PATH) 
    print(f"YOLO person detection model ({YOLO_PERSON_MODEL_PATH}) loaded successfully.")
except Exception as e:
    print(f"Error loading YOLO person model: {e}")


try:
    yolo_fashion_model = YOLO(YOLO_FASHION_MODEL_PATH) # No .to(DEVICE) needed here
    print(f"YOLO fashion detection model ({YOLO_FASHION_MODEL_PATH}) loaded successfully.")
except Exception as e:
    print(f"Error loading YOLO fashion model: {e}")

style_prompts = {
    'drippy': [
        "High-fashion runway look with designer labels",
        "Coordinated color palette with premium fabrics",
        "Trend-forward streetwear with luxury accessories",
        "Tailored silhouettes with intentional layering",
        "Seasonal trend elements executed flawlessly",
        "Cohesive outfit with statement pieces",
        "Celebrity red carpet-level styling",
        "Bold pattern mixing that works harmoniously"
        "Well-put-together casual outfit",
        "Confident personal style",
        "Good color coordination",
        "Flattering fit and proportions",
        "Appropriate for the occasion",
        "Clean and well-maintained clothing",
        "Interesting texture combinations",
        "Balanced silhouette",
        "Thoughtful accessory choices",
        "Modern but not overly trendy"
    ],
    'mid': [
        "Basic wardrobe staples without flair",
        "Safe color combinations with minimal accessories",
        "Mass-market fast fashion pieces",
        "Functional over fashionable aesthetic",
        "Trend-adjacent but poorly executed",
        "Mismatched proportions in clothing",
        "Overly casual for the occasion",
        "Decade-outdated trend revival"
    ],
    'not_drippy': [
        "Severely mismatched color schemes",
        "Pilled/stained/faded clothing items",
        "Ill-fitting garments in multiple pieces",
        "Clashing patterns without cohesion",
        "Inappropriate footwear for outfit context",
        "Overly literal costume-like styling",
        "Multiple competing trends in one outfit",
        "Wrinkled/unkempt fabric presentation"
    ]
}
style_prompts['drippy'] += [
    "coordinated color scheme",
    "perfect garment proportions", 
    "current fashion trends",
    "high-quality materials",
    "complementary accessories"
]

style_prompts['not_drippy'] += [
    "clashing colors",
    "poor fit proportions",
    "outdated trends",
    "cheap-looking fabrics",
    "missing accessories"
]


clothing_prompts = [
    "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"
]


all_prompts = []
for cat_prompts in style_prompts.values():
    all_prompts.extend(cat_prompts)
style_prompts_end_index = len(all_prompts) 
all_prompts.extend(clothing_prompts)



response_templates = {
    'drippy': [
        "You're Drippy, bruh – fire {item}!",
        "{item} goes crazy, on god!",
        "Certified drippy with that {item}.",
        "Your {item} just walked a Paris runway.",
        "That {item}? Straight from the future.",
        "You just turned a sidewalk into a runway."
    ],
    'mid': [
        "Drop the {item} and you might get a text back.",
        "It's alright, but I'd upgrade the {item}.",
        "Mid fit alert. {item} is holding you back.",
        "We can do better come on now",
        "I don't think you want it enough",
        "You're teetering on drip... fix the {item}.",
        "You're in the gray zone. That {item} ain't helping."
    ],
    '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}.",
        "Your drip is trash, try again.",
        "This ain't it chief. The overall style needs work.",
        "Didn't need an AI to tell you to go back to the wardrobe",
        "Someone call the fashion police. That {item} needs arresting.",
        "Your outfit just gave me a 404 error.",
        "That {item} made my GPU overheat in shame."
    ]
}
CATEGORY_LABEL_MAP = { "drippy": "drippy", "mid": "mid", "not_drippy": "trash" }

def format_detected_items(item_list):
    if not item_list:
        return ""
    return "<p class='result-items'>Detected items: " + ", ".join(item_list) + "</p>"


def get_top_clip_clothing(probs, n=1):
    """Gets the top N clothing items based on CLIP probabilities."""
    clothing_probs_start_index = style_prompts_end_index
    clothing_probs = probs[clothing_probs_start_index:]
    actual_n = min(n, len(clothing_prompts))
    if actual_n <= 0:
        return [] 


    top_indices_in_slice = np.argsort(clothing_probs)[-actual_n:]
    
    top_global_indices = [idx + clothing_probs_start_index for idx in top_indices_in_slice]


    top_items_with_probs = [
        (clothing_prompts[i], clothing_probs[i])
        for i in reversed(top_indices_in_slice) 
    ]
    return top_items_with_probs
def wrapped_analyze(input_img):
    return analyze_outfit(
        input_img,
        yolo_person_model,
        yolo_fashion_model,
        clip_model,
        clip_preprocess,
        all_prompts,
        style_prompts_end_index,
        FASHION_CLASSES,
        CATEGORY_LABEL_MAP,
        response_templates,
        YOLO_PERSON_CONF_THRESHOLD,
        YOLO_FASHION_CONF_THRESHOLD,
        YOLO_FASHION_HIGH_CONF_THRESHOLD,
        DEVICE
    )
def analyze_outfit(input_img):
   
    if isinstance(input_img, str):
        try:
            input_img = Image.open(input_img)
        except Exception as e:
            return (f"<p style='color: #FF5555;'>Error loading image: {str(e)}</p>",
                    None, "Image loading error")
    

    if input_img is None:
        return ("<p style='color: #FF5555; text-align: center;'>Please upload an image.</p>",
                None, "Error: No image provided.")
                
    img = input_img.convert("RGB").copy()

    person_results = yolo_person_model(img, verbose=False, conf=YOLO_PERSON_CONF_THRESHOLD)
    boxes = person_results[0].boxes.xyxy.cpu().numpy()
    classes = person_results[0].boxes.cls.cpu().numpy()
    confidences = person_results[0].boxes.conf.cpu().numpy()


    person_indices = np.where(classes == 0)[0]
    cropped_img = img 
    person_detected = False

    if len(person_indices) > 0:
        
        max_conf_person_idx = person_indices[np.argmax(confidences[person_indices])]
        x1, y1, x2, y2 = map(int, boxes[max_conf_person_idx])
        
        x1, y1 = max(0, x1), max(0, y1)
        x2, y2 = min(img.width, x2), min(img.height, y2)

        if x1 < x2 and y1 < y2: 
            cropped_img = img.crop((x1, y1, x2, y2))
            print(f"Person detected and cropped: Box {x1, y1, x2, y2}")
            person_detected = True
        else:
            print("Warning: Invalid person bounding box after clipping. Using full image.")
            cropped_img = img
    else:
        print("No person detected by yolo_person_model. Analyzing full image.")

    
    detected_fashion_item_name = None
    detected_fashion_item_conf = 0.0
    if person_detected or True: 
        try:
            fashion_results = yolo_fashion_model(cropped_img, verbose=False, conf=YOLO_FASHION_CONF_THRESHOLD)
            fashion_boxes = fashion_results[0].boxes.xyxy.cpu().numpy()
            fashion_classes = fashion_results[0].boxes.cls.cpu().numpy().astype(int)
            fashion_confidences = fashion_results[0].boxes.conf.cpu().numpy()

            if len(fashion_classes) > 0:
                
                best_fashion_idx = np.argmax(fashion_confidences)
                detected_class_id = fashion_classes[best_fashion_idx]
                detected_fashion_item_conf = fashion_confidences[best_fashion_idx]

                if detected_class_id in FASHION_CLASSES:
                    detected_fashion_item_name = FASHION_CLASSES[detected_class_id]
                    print(f"Fashion model detected: '{detected_fashion_item_name}' "
                          f"with confidence {detected_fashion_item_conf:.2f}")
                else:
                    print(f"Warning: Detected fashion class ID {detected_class_id} not in FASHION_CLASSES map.")
            else:
                print("No fashion items detected above threshold by yolo_fashion_model.")

        except Exception as e:
            print(f"Error during YOLO fashion model analysis: {e}")
            # Continue without fashion model input

    
    clip_detected_item = "look" # Default fallback item name
    clip_detected_item_prob = 0.0
    category_key = 'mid' # Default category
    final_score_str = "N/A"
    final_score = 0.0

    try:
        image_tensor = clip_preprocess(cropped_img).unsqueeze(0).to(DEVICE)
        text_tokens = clip.tokenize(all_prompts).to(DEVICE)

        with torch.no_grad():
            logits, _ = clip_model(image_tensor, text_tokens)
            all_probs = logits.softmax(dim=-1).cpu().numpy()[0]

        
        drip_len = len(style_prompts['drippy'])
        mid_len = len(style_prompts['mid'])

        score_label = "Style Score" # Initialize with a default/fallback


        category_label = CATEGORY_LABEL_MAP[category_key]
       
        percentage_score = max(0, final_score * 100)
        percentage_score_str = f"{percentage_score:.0f}%"

        # Calculate average probabilities for each category
        drip_score = np.mean(all_probs[0 : drip_len])
        mid_score = np.mean(all_probs[drip_len : drip_len + mid_len])
        not_score = np.mean(all_probs[drip_len + mid_len : style_prompts_end_index])
        
  
        
        raw_weighted_score = (drip_score * 1) + (mid_score * 0.5) + (not_score * 0.1)

        final_score = raw_weighted_score * 100 + 10
        

        final_score = min(max(final_score, 0), 100)
        

        if final_score >= 50:
            category_key = 'drippy'
            score_label = "Drip Score"
        elif final_score >= 20:
            category_key = 'mid'
            score_label = "Mid Score"
        else:
            category_key = 'not_drippy'
            score_label = "Trash Score"
        
        category_label = CATEGORY_LABEL_MAP[category_key]
        percentage_score_str = f"{final_score:.0f}%"



      
        print(f"Style analysis: Category={category_label}, Score = {score_label}={percentage_score_str} (Raw Score: {final_score:.4f})")

        # Get top clothing item from CLIP
        top_3_clip_items = get_top_clip_clothing(all_probs, n=3) 

        if top_3_clip_items:
            
            detected_items_str = ", ".join([f"{item[0]} ({item[1]*100:.1f}%)" for item in top_3_clip_items]) # Show item and probability
            print(f"I think I detected: {detected_items_str}")

            
            clip_detected_item, clip_detected_item_prob = top_3_clip_items[0]
           
        else:
             print("I couldn't confidently identify specific clothing items via CLIP.")
             clip_detected_item = "piece" # Use a different fallback if CLIP fails
             clip_detected_item_prob = 0.0 # Ensure prob is defined

    except Exception as e:
        print(f"Error during CLIP analysis: {e}")
        
        return ("<p style='color: #FF5555;'>Error during CLIP analysis.</p>",
                None, f"Analysis Error: {e}")
    
    # Determine the Final Item to Mention in Response
    final_clothing_item = "style" # Ultimate fallback generic term
    generic_response_needed = False

    if detected_fashion_item_name and detected_fashion_item_conf >= YOLO_FASHION_HIGH_CONF_THRESHOLD:
        # Priority 1: High-confidence fashion model detection
        final_clothing_item = detected_fashion_item_name
        print(f"Using highly confident fashion model item: '{final_clothing_item}'")
    elif detected_fashion_item_name and detected_fashion_item_conf >= YOLO_FASHION_CONF_THRESHOLD:
         # Priority 2: Medium-confidence fashion model detection (still prefer over CLIP)
         final_clothing_item = detected_fashion_item_name
         print(f"Using medium confidence fashion model item: '{final_clothing_item}'")
    elif clip_detected_item and clip_detected_item_prob > 0.05: # Check if CLIP prob is somewhat reasonable
        # Priority 3: CLIP detection (if fashion model didn't provide a strong candidate)
        final_clothing_item = clip_detected_item
        print(f"Using CLIP detected item: '{final_clothing_item}'")
    else:
        # Priority 4: Generic response needed (no confident detection from either model)
        final_clothing_item = random.choice(["fit", "look", "style", "vibe"]) # Randomize generic term
        generic_response_needed = True
        print(f"Using generic fallback item: '{final_clothing_item}'")


 
    try:
        response_pool = response_templates[category_key]
        
        chosen_template = random.choice(response_pool)

        # Format the response, substituting the item name if needed
        response_text = chosen_template.format(item=final_clothing_item) if '{item}' in chosen_template else chosen_template

        tts_path = os.path.join(tempfile.gettempdir(), f"drip_{uuid.uuid4().hex}.mp3")
        tts = gTTS(text=response_text, lang='en', tld='com', slow=False)
        tts.save(tts_path)
        print(f"Generated TTS response: '{response_text}' saved to {tts_path}")

        # --- Updated HTML Output ---
        category_html = f"""
            <div class='results-container'>
                <h2 class='result-category'>RATING: {category_label.upper()}</h2>
                <p class='result-score'>Overall Fit Rating: {percentage_score_str}/100%</p>
                <p class='result-confidence'>Detected Item: {final_clothing_item.title()}</p>
            </div>
        """
        return category_html, tts_path, response_text

    except Exception as e:
        print(f"Error during response/TTS generation: {e}")
        percentage_score = max(0, final_score * 100)
        percentage_score_str = f"{percentage_score:.0f}%"
        category_html = f"""
            <div class='results-container'>
                <h2 class='result-category'>Result: {category_label.upper()}</h2>
                <p class='result-score'>Overall Fit Rating: {percentage_score_str}/100</p>
                <p class='result-confidence'>Detected Item: {final_clothing_item.title()}</p>
                <p class='result-error' style='color: #FFAAAA; font-size: 0.9em;'>Error generating audio/full response.</p>
            </div>
        """
        # Still provide category info, but indicate TTS/response error
        return category_html, None, f"Analysis complete ({category_label}), but error generating audio/response."

custom_css = """:root {
      --primary-bg-color: #0D0D0D;
      --secondary-bg-color: #1A1A1A;
      --text-color: #FFFFFF;
      --accent-color: #7F5AF0; /* Electric purple */
      --accent-hover: #C084FC;
      --success-color: #2CB67D;
      --error-color: #F25F4C;
      --border-color: #2F2F2F;
      --input-bg-color: #1A1A1A;
      --button-text-color: #FFFFFF;
      --body-text-size: 16px;
      }
    

    body,
    .gradio-container {
      background-color: var(--primary-bg-color) !important;
      color: var(--text-color) !important;
      font-family: 'Inter', 'Segoe UI', sans-serif;
      font-size: var(--body-text-size);
    }
    
    
    footer {
      display: none !important;
    }
    
    .gr-block {
      background-color: var(--secondary-bg-color) !important;
      border: 1px solid var(--border-color) !important;
      border-radius: 16px !important;
      padding: 20px !important;
      box-shadow: 0 0 15px rgba(127, 90, 240, 0.1);
    }
    
    .gr-input,
    .gr-output,
    .gr-textbox textarea,
    .gr-dropdown select,
    .gr-checkboxgroup input {
      background-color: var(--input-bg-color) !important;
      color: var(--text-color) !important;
      border: 1px solid var(--border-color) !important;
      border-radius: 10px !important;
      padding: 10px;
    }
    
    .gr-textbox textarea::placeholder {
      color: #888888 !important;
    }
    
    .gr-label span,
    .gr-label .label-text {
      color: var(--text-color) !important;
      font-weight: 500 !important;
      font-size: 0.95em !important;
      margin-bottom: 8px !important;
    }
    
    .gr-image {
      background-color: var(--primary-bg-color) !important;
      border: 2px dashed var(--border-color) !important;
      border-radius: 12px !important;
      overflow: hidden;
    }
    
    .gr-image img {
      border-radius: 10px !important;
      object-fit: contain;
    }
    
    .gr-image .no-image,
    .gr-image .upload-button {
      color: #AAAAAA !important;
    }
    
    .gr-audio > div:first-of-type {
      border: 1px solid var(--border-color) !important;
      background-color: var(--secondary-bg-color) !important;
      border-radius: 10px !important;
      padding: 12px !important;
    }
    
    .gr-audio audio {
      width: 100%;
      filter: invert(1) hue-rotate(180deg);
    }
    
    .gr-button {
      border: none !important;
      border-radius: 10px !important;
      transition: background-color 0.2s ease, transform 0.1s ease;
      font-weight: 600 !important;
    }
    
    .gr-button-primary {
      background-color: var(--accent-color) !important;
      color: var(--button-text-color) !important;
      font-size: 1.1em !important;
      padding: 14px 24px !important;
      letter-spacing: 0.5px;
      text-transform: uppercase;
      box-shadow: 0 0 10px rgba(127, 90, 240, 0.2);
    }
    
    .gr-button-primary:hover {
      background-color: var(--accent-hover) !important;
      transform: scale(1.03);
      box-shadow: 0 0 15px 3px rgba(192, 132, 252, 0.6);
    }
    
    .gr-button-primary:active {
      transform: scale(0.97);
    }
    
    h1, h2, h3 {
      color: var(--text-color) !important;
      font-weight: 600;
      letter-spacing: 0.5px;
    }
    
    .prose h1 {
      text-align: center;
      margin-bottom: 25px !important;
      font-size: 2em !important;
      text-transform: uppercase;
      letter-spacing: 1.5px;
    }
    
    .prose p {
      color: #CCCCCC !important;
      font-size: 0.95em;
      text-align: center;
    }
    
    .results-container {
      text-align: center;
      padding: 20px;
      border: 1px solid var(--accent-color);
      border-radius: 16px;
      background: linear-gradient(145deg, var(--secondary-bg-color), #2a2a2a);
      backdrop-filter: blur(10px);
      box-shadow: 0 8px 32px rgba(0, 0, 0, 0.37);
    }
    
    .result-category {
      color: var(--accent-color) !important;
      font-size: 1.6em;
      margin-bottom: 5px;
      font-weight: 700;
      text-transform: uppercase;
      letter-spacing: 1px;
    }
    
    .result-score {
      color: var(--text-color) !important;
      font-size: 1.2em;
      margin-bottom: 5px;
    }
    
    .result-error {
      color: var(--error-color) !important;
      font-size: 0.9em;
      margin-top: 5px;
    }
    
    .gradio-container {
      max-width: 850px !important;
      margin: auto !important;
      padding-top: 30px;
    }
    
    .gr-row {
      gap: 25px !important;
    }"""


with gr.Blocks(css=custom_css, theme=gr.themes.Soft()) as demo:

    
    with gr.Row():
        with gr.Column(scale=1):
            input_image = gr.Image(
                type="pil",
                #type='pil',
                label="Upload Your Fit",
                sources=['upload', 'webcam', 'clipboard'],
                height=400,
                show_label=False
                
            )
            analyze_button = gr.Button("🔥 Analyze This Drip", variant="primary")
        
        with gr.Column(scale=1):
            category_html = gr.HTML()
            response_box = gr.Textbox(
                lines=2,
                label="Verbal Feedback",
                interactive=False,
                show_label=False,
                placeholder="Verbal feedback will show up here."
            )
            audio_output = gr.Audio(label="Audio Feedback", autoplay=True)

    analyze_button.click(
        fn=analyze_outfit,
        inputs=[input_image],
        outputs=[category_html, audio_output, response_box]
    )
    
if __name__ == "__main__":
    
    if not os.path.exists(YOLO_FASHION_MODEL_PATH):
        print(f"\n{'='*20} WARNING {'='*20}")
        print(f"Fashion model file '{YOLO_FASHION_MODEL_PATH}' not found!")
        print(f"The app will run but fashion item detection will be skipped.")
        print(f"{'='*50}\n")
        

    demo.launch(debug=False, show_error=True) # Set debug=False for deployment