RajaThor commited on
Commit
0a9f73c
Β·
verified Β·
1 Parent(s): eb85158

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +606 -0
app.py ADDED
@@ -0,0 +1,606 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import numpy as np
3
+ from PIL import Image
4
+ import random
5
+ import warnings
6
+ warnings.filterwarnings("ignore")
7
+
8
+ # Try to import AI dependencies
9
+ try:
10
+ import torch
11
+ from transformers import pipeline, BlipProcessor, BlipForConditionalGeneration
12
+ TRANSFORMERS_AVAILABLE = True
13
+ print("βœ… AI models available")
14
+ except ImportError:
15
+ TRANSFORMERS_AVAILABLE = False
16
+ print("⚠️ Using lightweight mode")
17
+
18
+ class FashionAI:
19
+ def __init__(self):
20
+ self.setup_ai_models()
21
+ self.load_fashion_data()
22
+
23
+ def setup_ai_models(self):
24
+ """Load AI models if available"""
25
+ if TRANSFORMERS_AVAILABLE:
26
+ try:
27
+ print("πŸ”„ Loading AI models...")
28
+ # Use smaller models for HF Spaces
29
+ self.caption_model = pipeline(
30
+ "image-to-text",
31
+ model="nlpconnect/vit-gpt2-image-captioning",
32
+ device=0 if torch.cuda.is_available() else -1
33
+ )
34
+
35
+ self.classifier = pipeline(
36
+ "zero-shot-classification",
37
+ model="facebook/bart-large-mnli",
38
+ device=0 if torch.cuda.is_available() else -1
39
+ )
40
+
41
+ self.use_ai = True
42
+ print("βœ… AI models loaded successfully!")
43
+
44
+ except Exception as e:
45
+ print(f"❌ AI model error: {e}")
46
+ self.use_ai = False
47
+ else:
48
+ self.use_ai = False
49
+ print("πŸ“± Running in lightweight mode")
50
+
51
+ def load_fashion_data(self):
52
+ """Load fashion knowledge base"""
53
+ self.color_seasons = {
54
+ "spring": {
55
+ "colors": ["coral", "peach", "bright yellow", "warm pink", "kelly green"],
56
+ "avoid": ["black", "burgundy", "navy", "cool blues"]
57
+ },
58
+ "summer": {
59
+ "colors": ["soft blue", "lavender", "rose pink", "powder blue", "mint"],
60
+ "avoid": ["orange", "bright yellow", "warm browns"]
61
+ },
62
+ "autumn": {
63
+ "colors": ["rust", "golden yellow", "olive green", "burnt orange", "chocolate"],
64
+ "avoid": ["bright pink", "cool blues", "pure white"]
65
+ },
66
+ "winter": {
67
+ "colors": ["true red", "bright white", "royal blue", "emerald", "black"],
68
+ "avoid": ["beige", "orange", "golden yellow"]
69
+ }
70
+ }
71
+
72
+ self.body_types = {
73
+ "pear": {
74
+ "focus": "shoulders and upper body",
75
+ "recommend": ["A-line tops", "boat necks", "structured jackets"],
76
+ "avoid": ["tight bottoms", "hip-emphasizing details"]
77
+ },
78
+ "apple": {
79
+ "focus": "legs and neckline",
80
+ "recommend": ["A-line dresses", "V-necks", "empire waist"],
81
+ "avoid": ["tight around waist", "horizontal stripes"]
82
+ },
83
+ "hourglass": {
84
+ "focus": "natural waist",
85
+ "recommend": ["fitted styles", "wrap dresses", "belted outfits"],
86
+ "avoid": ["loose shapeless clothes", "hiding waist"]
87
+ },
88
+ "rectangle": {
89
+ "focus": "creating curves",
90
+ "recommend": ["peplum tops", "layered looks", "ruffles"],
91
+ "avoid": ["straight cuts", "baggy clothes"]
92
+ }
93
+ }
94
+
95
+ def analyze_image(self, image):
96
+ """Analyze fashion image with AI or fallback"""
97
+ if image is None:
98
+ return "❌ Please upload an image first!"
99
+
100
+ try:
101
+ if self.use_ai:
102
+ return self.ai_image_analysis(image)
103
+ else:
104
+ return self.fallback_analysis(image)
105
+ except Exception as e:
106
+ return f"⚠️ Analysis error: {str(e)}\n\nUsing basic analysis...\n\n{self.fallback_analysis(image)}"
107
+
108
+ def ai_image_analysis(self, image):
109
+ """AI-powered image analysis"""
110
+ try:
111
+ # Generate caption
112
+ caption_result = self.caption_model(image)
113
+ caption = caption_result[0]['generated_text'] if caption_result else "fashion item"
114
+
115
+ # Classify style
116
+ style_labels = ["casual", "formal", "elegant", "sporty", "trendy", "professional"]
117
+ style_result = self.classifier(caption, style_labels)
118
+ style = style_result['labels'][0]
119
+
120
+ # Generate comprehensive analysis
121
+ analysis = f"""# πŸ” **AI Fashion Analysis**
122
+
123
+ πŸ‘€ **What I See**: {caption.capitalize()}
124
+
125
+ ✨ **Style Category**: {style.title()}
126
+
127
+ 🎨 **Color Recommendations**:
128
+ Based on the {style} style, I recommend:
129
+ β€’ {random.choice(['Navy & White', 'Black & Gold', 'Coral & Cream', 'Emerald & Silver'])}
130
+ β€’ {random.choice(['Soft pastels', 'Bold jewel tones', 'Neutral earth tones', 'Classic monochromes'])}
131
+
132
+ πŸ’‘ **Styling Tips**:
133
+ β€’ Perfect for {random.choice(['professional settings', 'casual outings', 'special occasions', 'everyday wear'])}
134
+ β€’ Pair with {random.choice(['statement accessories', 'classic heels', 'comfortable flats', 'a structured bag'])}
135
+ β€’ Consider {random.choice(['layering with a blazer', 'adding a belt', 'mixing textures', 'playing with proportions'])}
136
+
137
+ 🎯 **Best Occasions**: {', '.join(random.sample(['Work meetings', 'Dinner dates', 'Weekend brunches', 'Shopping trips', 'Social events'], 3))}
138
+
139
+ ✨ *AI-powered analysis complete!*"""
140
+
141
+ return analysis
142
+
143
+ except Exception as e:
144
+ return f"AI analysis failed: {e}"
145
+
146
+ def fallback_analysis(self, image):
147
+ """Rule-based fallback analysis"""
148
+ try:
149
+ # Basic color analysis
150
+ img_array = np.array(image)
151
+ avg_color = np.mean(img_array)
152
+
153
+ if avg_color > 180:
154
+ color_desc = "light and bright"
155
+ season = "spring"
156
+ elif avg_color < 80:
157
+ color_desc = "dark and dramatic"
158
+ season = "winter"
159
+ else:
160
+ color_desc = "balanced tones"
161
+ season = "autumn"
162
+
163
+ season_info = self.color_seasons[season]
164
+
165
+ return f"""# πŸ” **Fashion Analysis Results**
166
+
167
+ 🎨 **Color Profile**: {color_desc.title()}
168
+
169
+ 🌈 **Your Season**: {season.title()}
170
+ β€’ **Perfect Colors**: {', '.join(season_info['colors'][:3])}
171
+ β€’ **Avoid**: {', '.join(season_info['avoid'][:2])}
172
+
173
+ πŸ’‘ **Styling Suggestions**:
174
+ β€’ This piece has {color_desc} that work beautifully for {season} color palettes
175
+ β€’ Consider pairing with complementary {season} colors
176
+ β€’ Perfect for creating sophisticated, coordinated looks
177
+
178
+ 🎯 **Versatile Styling**:
179
+ β€’ Dress it up with heels and jewelry for evening
180
+ β€’ Keep it casual with flats and minimal accessories
181
+ β€’ Layer with complementary pieces for different occasions
182
+
183
+ ✨ *Analysis complete - you're ready to style!*"""
184
+
185
+ except Exception as e:
186
+ return f"Basic analysis: This appears to be a fashion item with styling potential! Consider the colors and silhouette when creating outfits."
187
+
188
+ def chat_response(self, message, history):
189
+ """Generate chat responses"""
190
+ msg_lower = message.lower()
191
+
192
+ responses = {
193
+ 'color': """🌈 **Color Magic!**
194
+
195
+ **Find Your Season:**
196
+ β€’ **Spring**: Warm, bright colors (coral, peach, bright yellow)
197
+ β€’ **Summer**: Cool, soft colors (lavender, powder blue, rose pink)
198
+ β€’ **Autumn**: Warm, rich colors (rust, golden yellow, olive green)
199
+ β€’ **Winter**: Cool, dramatic colors (true red, royal blue, black)
200
+
201
+ **Quick Test**: Look at your wrist veins:
202
+ β€’ Green veins = Warm undertones (Spring/Autumn)
203
+ β€’ Blue veins = Cool undertones (Summer/Winter)
204
+
205
+ What colors do you gravitate toward naturally?""",
206
+
207
+ 'body': """πŸ‘— **Body Type Styling Guide**
208
+
209
+ **Pear Shape** (smaller shoulders, fuller hips):
210
+ βœ… A-line tops, boat necks, structured jackets
211
+ ❌ Tight bottoms, hip details
212
+
213
+ **Apple Shape** (fuller midsection):
214
+ βœ… A-line dresses, V-necks, empire waist
215
+ ❌ Tight waistlines, horizontal stripes
216
+
217
+ **Hourglass** (balanced curves):
218
+ βœ… Fitted styles, wrap dresses, belts
219
+ ❌ Loose, shapeless clothing
220
+
221
+ **Rectangle** (straight up and down):
222
+ βœ… Peplum tops, layers, ruffles, belts
223
+ ❌ Straight cuts, baggy styles
224
+
225
+ Which shape sounds most like you?""",
226
+
227
+ 'work': """πŸ‘” **Professional Power Dressing**
228
+
229
+ **Essential Pieces:**
230
+ β€’ Well-fitted blazer (navy, black, gray)
231
+ β€’ Tailored pants or pencil skirt
232
+ β€’ Classic button-down shirts
233
+ β€’ Closed-toe shoes (modest heel)
234
+ β€’ Quality, minimal jewelry
235
+
236
+ **Color Strategy:**
237
+ β€’ Neutrals as base (black, navy, gray, white)
238
+ β€’ Add one accent color per outfit
239
+ β€’ Avoid overly bright or distracting patterns
240
+
241
+ **Pro Tips:**
242
+ β€’ Fit is EVERYTHING in professional wear
243
+ β€’ Invest in quality basics over trendy pieces
244
+ β€’ Keep makeup and accessories understated
245
+
246
+ Ready to build your power wardrobe?""",
247
+
248
+ 'date': """πŸ’• **Date Night Perfection**
249
+
250
+ **The Golden Rules:**
251
+ β€’ Wear something that makes YOU feel amazing
252
+ β€’ Comfort + confidence = irresistible combination
253
+ β€’ Match the vibe (casual coffee vs fancy dinner)
254
+
255
+ **Go-To Options:**
256
+ β€’ **Casual**: Great jeans + silk blouse + cute flats
257
+ β€’ **Dinner**: Little black dress + statement jewelry + heels
258
+ β€’ **Activity**: Cute sundress + comfortable wedges
259
+
260
+ **Final Touch:**
261
+ β€’ Subtle, flattering makeup
262
+ β€’ Signature scent (not overpowering!)
263
+ β€’ Genuine smile and positive energy
264
+
265
+ What kind of date are you planning?""",
266
+
267
+ 'default': """✨ **Your Fashion AI Assistant**
268
+
269
+ I'm here to help with all things style! I can assist with:
270
+
271
+ 🎨 **Color Analysis** - Find your perfect palette
272
+ πŸ‘— **Body Type Styling** - Flattering fits for your shape
273
+ πŸ’Ό **Professional Wardrobe** - Power dressing tips
274
+ πŸ’• **Special Occasions** - Perfect outfits for events
275
+ πŸ›οΈ **Wardrobe Building** - Smart shopping strategies
276
+ πŸ“Έ **Image Analysis** - Upload photos for personalized advice
277
+
278
+ **Popular Questions:**
279
+ "What colors suit me?" | "How to dress for my body type?" | "Professional outfit ideas" | "Date night styling"
280
+
281
+ What fashion challenge can I solve for you today?"""
282
+ }
283
+
284
+ # Match user intent
285
+ for keyword, response in responses.items():
286
+ if keyword != 'default' and keyword in msg_lower:
287
+ return response
288
+
289
+ return responses['default']
290
+
291
+ def personal_style_guide(self, skin_tone, body_type, style_prefs, occasion):
292
+ """Generate personalized style recommendations"""
293
+ guide = ["# 🌟 **Your Personal Style Guide**\n"]
294
+
295
+ # Color recommendations
296
+ if skin_tone != "Not sure":
297
+ color_map = {
298
+ "Warm": ("Spring/Autumn", ["coral", "peach", "golden yellow", "rust", "olive green"]),
299
+ "Cool": ("Summer/Winter", ["soft blue", "lavender", "true red", "royal blue", "emerald"]),
300
+ "Neutral": ("Flexible", ["navy", "black", "white", "gray", "most colors work"])
301
+ }
302
+
303
+ season, colors = color_map[skin_tone]
304
+ guide.append(f"## 🎨 Perfect Colors for {skin_tone} Undertones ({season})")
305
+ guide.append(f"**Your Palette**: {', '.join(colors)}")
306
+ guide.append("")
307
+
308
+ # Body type styling
309
+ if body_type != "Not sure":
310
+ body_key = body_type.lower().replace(' ', '_').replace('inverted_triangle', 'rectangle')
311
+ if body_key in self.body_types:
312
+ body_info = self.body_types[body_key]
313
+ guide.append(f"## πŸ‘— Styling for {body_type} Shape")
314
+ guide.append(f"**Focus on**: {body_info['focus']}")
315
+ guide.append(f"**Recommended**: {', '.join(body_info['recommend'])}")
316
+ guide.append(f"**Avoid**: {', '.join(body_info['avoid'])}")
317
+ guide.append("")
318
+
319
+ # Style preferences
320
+ if style_prefs:
321
+ guide.append(f"## ✨ Your Style DNA: {', '.join(style_prefs)}")
322
+
323
+ style_tips = {
324
+ "Casual": "Comfortable, versatile pieces that mix and match",
325
+ "Professional": "Tailored, classic pieces in quality fabrics",
326
+ "Elegant": "Refined silhouettes with luxurious details",
327
+ "Trendy": "Current styles with fashion-forward elements",
328
+ "Minimalist": "Clean lines, neutral colors, capsule wardrobe",
329
+ "Bohemian": "Flowing fabrics, artistic prints, layered accessories"
330
+ }
331
+
332
+ for style in style_prefs[:3]: # Limit to top 3
333
+ if style in style_tips:
334
+ guide.append(f"**{style}**: {style_tips[style]}")
335
+ guide.append("")
336
+
337
+ # Occasion-specific advice
338
+ occasion_guide = {
339
+ "Work/Professional": "Sharp blazers, tailored fits, neutral colors with subtle personality",
340
+ "Casual Day": "Comfortable yet put-together, versatile pieces that transition well",
341
+ "Date Night": "Something that makes you feel confident and authentic to your style",
342
+ "Party/Event": "Statement pieces, bold colors, interesting textures and details",
343
+ "Wedding Guest": "Elegant without upstaging, avoid white, consider the venue",
344
+ "Travel": "Comfortable layers, wrinkle-resistant fabrics, versatile pieces"
345
+ }
346
+
347
+ guide.append(f"## 🎯 Perfect for {occasion}")
348
+ guide.append(f"{occasion_guide.get(occasion, 'Versatile styling for any occasion')}")
349
+ guide.append("")
350
+
351
+ # Final styling tips
352
+ guide.append("## πŸ’‘ **Your Style Action Plan**")
353
+ guide.append("β€’ **Start with fit** - well-fitted basics are your foundation")
354
+ guide.append("β€’ **Build gradually** - invest in quality pieces over time")
355
+ guide.append("β€’ **Mix and match** - create multiple looks with fewer pieces")
356
+ guide.append("β€’ **Accessorize strategically** - transform outfits with small changes")
357
+ guide.append("β€’ **Stay true to you** - confidence is your best accessory!")
358
+
359
+ return "\n".join(guide)
360
+
361
+ # Create the Gradio interface
362
+ def create_fashion_interface():
363
+ fashion_ai = FashionAI()
364
+
365
+ # Modern styling
366
+ css = """
367
+ @import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');
368
+
369
+ .gradio-container {
370
+ font-family: 'Inter', sans-serif !important;
371
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
372
+ }
373
+
374
+ .main {
375
+ background: rgba(255, 255, 255, 0.95) !important;
376
+ border-radius: 25px !important;
377
+ backdrop-filter: blur(10px) !important;
378
+ box-shadow: 0 25px 50px rgba(0,0,0,0.15) !important;
379
+ margin: 20px !important;
380
+ }
381
+
382
+ button {
383
+ background: linear-gradient(135deg, #667eea, #764ba2) !important;
384
+ border: none !important;
385
+ border-radius: 25px !important;
386
+ color: white !important;
387
+ font-weight: 600 !important;
388
+ transition: all 0.3s ease !important;
389
+ box-shadow: 0 5px 15px rgba(102, 126, 234, 0.3) !important;
390
+ }
391
+
392
+ button:hover {
393
+ transform: translateY(-2px) !important;
394
+ box-shadow: 0 10px 25px rgba(102, 126, 234, 0.4) !important;
395
+ }
396
+
397
+ .tab-nav button.selected {
398
+ background: linear-gradient(135deg, #667eea, #764ba2) !important;
399
+ transform: translateY(-2px) !important;
400
+ }
401
+
402
+ img {
403
+ border-radius: 15px !important;
404
+ box-shadow: 0 10px 30px rgba(0,0,0,0.2) !important;
405
+ transition: all 0.3s ease !important;
406
+ }
407
+
408
+ .markdown {
409
+ background: white !important;
410
+ border-radius: 15px !important;
411
+ padding: 25px !important;
412
+ box-shadow: 0 5px 15px rgba(0,0,0,0.1) !important;
413
+ border-left: 4px solid #667eea !important;
414
+ }
415
+ """
416
+
417
+ with gr.Blocks(
418
+ title="πŸ€–βœ¨ Advanced Fashion AI Stylist",
419
+ theme=gr.themes.Soft(primary_hue="purple", secondary_hue="pink"),
420
+ css=css
421
+ ) as demo:
422
+
423
+ # Header
424
+ gr.HTML("""
425
+ <div style="text-align: center; padding: 40px; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; border-radius: 25px 25px 0 0; margin-bottom: 0;">
426
+ <h1 style="font-size: 3.5rem; margin: 0; text-shadow: 2px 2px 10px rgba(0,0,0,0.3);">πŸ€–βœ¨ Fashion AI Stylist</h1>
427
+ <p style="font-size: 1.4rem; margin: 15px 0; opacity: 0.9;">Advanced AI-Powered Fashion Analysis & Personal Styling</p>
428
+
429
+ <div style="display: flex; justify-content: center; gap: 30px; margin-top: 30px; flex-wrap: wrap;">
430
+ <div style="text-align: center; padding: 20px; background: rgba(255, 255, 255, 0.15); border-radius: 15px; min-width: 120px; backdrop-filter: blur(10px);">
431
+ <div style="font-size: 2.5rem; margin-bottom: 10px;">πŸ‘οΈ</div>
432
+ <div style="font-weight: 600;">AI Vision</div>
433
+ </div>
434
+ <div style="text-align: center; padding: 20px; background: rgba(255, 255, 255, 0.15); border-radius: 15px; min-width: 120px; backdrop-filter: blur(10px);">
435
+ <div style="font-size: 2.5rem; margin-bottom: 10px;">🎨</div>
436
+ <div style="font-weight: 600;">Color Analysis</div>
437
+ </div>
438
+ <div style="text-align: center; padding: 20px; background: rgba(255, 255, 255, 0.15); border-radius: 15px; min-width: 120px; backdrop-filter: blur(10px);">
439
+ <div style="font-size: 2.5rem; margin-bottom: 10px;">πŸ’¬</div>
440
+ <div style="font-weight: 600;">Smart Chat</div>
441
+ </div>
442
+ <div style="text-align: center; padding: 20px; background: rgba(255, 255, 255, 0.15); border-radius: 15px; min-width: 120px; backdrop-filter: blur(10px);">
443
+ <div style="font-size: 2.5rem; margin-bottom: 10px;">✨</div>
444
+ <div style="font-weight: 600;">Personal Style</div>
445
+ </div>
446
+ </div>
447
+ </div>
448
+ """)
449
+
450
+ with gr.Tabs():
451
+ # AI Image Analysis
452
+ with gr.TabItem("πŸ“Έ AI Image Analysis"):
453
+ gr.Markdown("## πŸ” Upload & Analyze Your Fashion Images")
454
+
455
+ with gr.Row():
456
+ with gr.Column(scale=1):
457
+ image_input = gr.Image(
458
+ label="πŸ“· Drop your fashion image here",
459
+ type="pil",
460
+ height=400
461
+ )
462
+ analyze_btn = gr.Button(
463
+ "✨ Analyze with AI",
464
+ variant="primary",
465
+ size="lg"
466
+ )
467
+
468
+ gr.Markdown("""
469
+ ### 🎯 **What I Can Analyze:**
470
+ - **Clothing items** and complete outfits
471
+ - **Color palettes** and seasonal recommendations
472
+ - **Style categories** and fashion themes
473
+ - **Styling suggestions** for different occasions
474
+ - **Mix & match** ideas with your existing wardrobe
475
+
476
+ *Upload any fashion image for instant AI-powered insights!*
477
+ """)
478
+
479
+ with gr.Column(scale=1):
480
+ analysis_output = gr.Markdown(
481
+ value="🎭 **Ready for Analysis!**\n\nUpload a fashion image and click '✨ Analyze with AI' to discover styling insights, color recommendations, and personalized fashion advice!\n\n*Your personal fashion consultant is just one click away...*"
482
+ )
483
+
484
+ analyze_btn.click(
485
+ fashion_ai.analyze_image,
486
+ inputs=[image_input],
487
+ outputs=[analysis_output]
488
+ )
489
+
490
+ # Smart Fashion Chat
491
+ with gr.TabItem("πŸ’¬ Fashion Chat"):
492
+ gr.Markdown("## πŸ€– Chat with Your Personal Fashion Stylist")
493
+
494
+ chatbot = gr.Chatbot(
495
+ value=[["", "πŸ‘‹ Hello gorgeous! I'm your personal AI fashion stylist. I'm here to help you discover your perfect style, find amazing color combinations, and create stunning outfits for any occasion!\n\nWhat fashion adventure shall we embark on today? ✨"]],
496
+ height=500
497
+ )
498
+
499
+ with gr.Row():
500
+ msg = gr.Textbox(
501
+ placeholder="Ask me anything! Colors, styling, body types, occasions, trends...",
502
+ show_label=False,
503
+ scale=4
504
+ )
505
+ send_btn = gr.Button("Send ✨", scale=1)
506
+
507
+ # Quick suggestion buttons
508
+ with gr.Row():
509
+ gr.Button("🌈 What colors suit me?", size="sm").click(
510
+ lambda: "What colors suit me best?", outputs=[msg]
511
+ )
512
+ gr.Button("πŸ’• Date night outfit ideas", size="sm").click(
513
+ lambda: "I need the perfect date night outfit!", outputs=[msg]
514
+ )
515
+ gr.Button("πŸ‘” Professional wardrobe help", size="sm").click(
516
+ lambda: "Help me build a professional wardrobe", outputs=[msg]
517
+ )
518
+ gr.Button("πŸ‘— Body type styling tips", size="sm").click(
519
+ lambda: "How should I dress for my body type?", outputs=[msg]
520
+ )
521
+
522
+ def respond(message, chat_history):
523
+ if message.strip():
524
+ bot_response = fashion_ai.chat_response(message, chat_history)
525
+ chat_history.append([message, bot_response])
526
+ return chat_history, ""
527
+
528
+ msg.submit(respond, [msg, chatbot], [chatbot, msg])
529
+ send_btn.click(respond, [msg, chatbot], [chatbot, msg])
530
+
531
+ # Personal Style Assistant
532
+ with gr.TabItem("✨ Personal Style"):
533
+ gr.Markdown("## 🌟 Create Your Personal Style Profile")
534
+
535
+ with gr.Row():
536
+ with gr.Column():
537
+ gr.Markdown("### πŸ‘€ Tell me about yourself")
538
+
539
+ skin_tone = gr.Radio(
540
+ choices=["Warm", "Cool", "Neutral", "Not sure"],
541
+ label="🌈 Skin Undertone (look at your wrist veins: green=warm, blue=cool)",
542
+ value="Not sure"
543
+ )
544
+
545
+ body_type = gr.Radio(
546
+ choices=["Pear", "Apple", "Hourglass", "Rectangle", "Inverted Triangle", "Not sure"],
547
+ label="πŸ‘— Body Type",
548
+ value="Not sure"
549
+ )
550
+
551
+ style_prefs = gr.CheckboxGroup(
552
+ choices=["Casual", "Professional", "Elegant", "Trendy", "Minimalist", "Bohemian"],
553
+ label="✨ Style Preferences (select all that resonate)",
554
+ value=[]
555
+ )
556
+
557
+ occasion = gr.Dropdown(
558
+ choices=["Work/Professional", "Casual Day", "Date Night", "Party/Event", "Wedding Guest", "Travel"],
559
+ label="🎯 Current Styling Need",
560
+ value="Casual Day"
561
+ )
562
+
563
+ style_btn = gr.Button("🌟 Create My Style Guide", variant="primary", size="lg")
564
+
565
+ with gr.Column():
566
+ personal_results = gr.Markdown(
567
+ value="✨ **Your Personal Style Journey Starts Here**\n\nFill out your preferences on the left to receive a comprehensive, personalized style guide tailored specifically for you!\n\n🎯 *Get ready to discover your perfect style formula...*"
568
+ )
569
+
570
+ style_btn.click(
571
+ fashion_ai.personal_style_guide,
572
+ inputs=[skin_tone, body_type, style_prefs, occasion],
573
+ outputs=[personal_results]
574
+ )
575
+
576
+ # Footer
577
+ gr.HTML(f"""
578
+ <div style="text-align: center; padding: 25px; margin-top: 20px; background: linear-gradient(135deg, #f8f9fa, #e9ecef); border-radius: 0 0 25px 25px; border-top: 1px solid #dee2e6;">
579
+ <div style="margin-bottom: 15px;">
580
+ <span style="font-size: 1.2rem; margin: 0 15px;">πŸ€–</span>
581
+ <span style="font-size: 1.2rem; margin: 0 15px;">✨</span>
582
+ <span style="font-size: 1.2rem; margin: 0 15px;">πŸ‘—</span>
583
+ <span style="font-size: 1.2rem; margin: 0 15px;">🎨</span>
584
+ <span style="font-size: 1.2rem; margin: 0 15px;">πŸ’«</span>
585
+ </div>
586
+ <p style="margin: 0; color: #666; font-size: 1rem; font-weight: 500;">
587
+ <strong>πŸš€ AI Mode:</strong> {'Advanced AI Enhanced' if TRANSFORMERS_AVAILABLE else 'Lightweight & Fast'} β€’
588
+ <strong>⚑ Status:</strong> Ready to Style β€’
589
+ <strong>✨ Your Fashion Journey Awaits!</strong>
590
+ </p>
591
+ </div>
592
+ """)
593
+
594
+ return demo
595
+
596
+ # Launch the app
597
+ if __name__ == "__main__":
598
+ print("πŸš€ Starting Advanced Fashion AI Stylist...")
599
+ demo = create_fashion_interface()
600
+ demo.launch(
601
+ share=True,
602
+ server_name="0.0.0.0",
603
+ server_port=7860,
604
+ show_error=True
605
+ )
606
+