romi2001 commited on
Commit
419b1be
·
verified ·
1 Parent(s): ab54a1b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +72 -53
app.py CHANGED
@@ -3,24 +3,23 @@ import numpy as np
3
  from PIL import Image
4
 
5
  # ==========================================
6
- # 1. CORE DATA & ANALYSIS PIPELINE
7
  # ==========================================
8
 
9
  COLOR_PALETTES = {
10
  "Fair-Blonde-Blue": {
11
- "name": "Icy Cool Blonde",
12
- "description": "Fair skin · Blonde hair · Blue eyes",
13
  "swatches": [
14
  {"name": "Light Blue", "hex": "#A0C4DF"},
15
  {"name": "Soft Lavender", "hex": "#C39BD3"},
16
  {"name": "Ivory", "hex": "#F9F9F6"},
17
  {"name": "Dusty Rose", "hex": "#E8A7A1"}
18
  ],
19
- "tip": "Avoid harsh black — opt for navy or charcoal instead."
20
  }
21
  }
22
 
23
- # The specific items recommended directly based on user traits
24
  RECOMMENDED_LOOK = [
25
  {"category": "TOP", "name": "Powder Blue Linen Blouse", "brand": "Zara", "hex": "#A0C4DF", "url": "https://shopping.google.com"},
26
  {"category": "TROUSERS", "name": "Soft White Wide-Leg Trousers", "brand": "ASOS", "hex": "#F9F9F6", "url": "https://shopping.google.com"},
@@ -31,24 +30,21 @@ RECOMMENDED_LOOK = [
31
  ]
32
 
33
  def analyze_and_recommend(image, skin, hair, eye, choice_method):
34
- # 1. Detect features based on input method
35
  if choice_method == "Upload a photo" and image is not None:
36
- # Connect your SigLIP / feature classification logic here
37
  skin_tone, hair_color, eye_color = "Fair", "Blonde", "Blue"
38
  else:
39
  skin_tone, hair_color, eye_color = skin, hair, eye
40
 
41
- # 2. Get corresponding color palette archetype
42
  palette_key = f"{skin_tone}-{hair_color}-{eye_color}"
43
  palette = COLOR_PALETTES.get(palette_key, COLOR_PALETTES["Fair-Blonde-Blue"])
44
 
45
- # 3. Build HTML for Color Swatches
46
  swatches_html = "".join([
47
- f'<div class="swatch-card"><div class="color-bubble" style="background-color: {s["hex"]};"></div><p>{s["name"]}</p></div>'
48
  for s in palette["swatches"]
49
  ])
50
 
51
- # 4. Build HTML for Outfit Picks (mapping your FAISS database results here)
52
  outfit_html = "".join([
53
  f'''
54
  <div class="product-card">
@@ -56,8 +52,8 @@ def analyze_and_recommend(image, skin, hair, eye, choice_method):
56
  <div class="prod-meta">
57
  <span class="prod-cat">{item["category"]}</span>
58
  <p class="prod-title">{item["name"]}</p>
59
- <span class="prod-brand">{item["brand"]}</span>
60
- <a href="{item["url"]}" target="_blank" class="shop-btn">Shop ↗</a>
61
  </div>
62
  </div>
63
  ''' for item in RECOMMENDED_LOOK
@@ -66,16 +62,17 @@ def analyze_and_recommend(image, skin, hair, eye, choice_method):
66
  palette_results = f"""
67
  <div class="results-box">
68
  <div class="palette-banner">
 
69
  <h2>{palette["name"]}</h2>
70
- <p>{palette["description"]}</p>
71
  </div>
72
  <div class="section-split">
73
- <div>
74
- <h3>COLORS FOR YOU</h3>
75
  <div class="swatch-grid">{swatches_html}</div>
76
  </div>
77
  <div class="tip-box">
78
- <h3>STYLIST TIP</h3>
79
  <p>{palette["tip"]}</p>
80
  </div>
81
  </div>
@@ -92,45 +89,67 @@ def analyze_and_recommend(image, skin, hair, eye, choice_method):
92
  )
93
 
94
  # ==========================================
95
- # 2. MATCHING MINIMALIST UI CSS (No Orange)
96
  # ==========================================
97
- custom_css = """
98
- body { background-color: #F9F8F6 !important; font-family: -apple-system, BlinkMacSystemFont, sans-serif; }
99
- .gradio-container { max-width: 800px !important; margin: 0 auto !important; padding-top: 40px !important; }
100
  .center-text { text-align: center; }
101
- .title-main { font-size: 40px; font-weight: 800; color: #111111; margin-bottom: 4px; letter-spacing: -1px; }
102
- .subtitle-main { font-size: 16px; color: #777777; margin-bottom: 32px; }
103
- .pill-container { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
104
- .results-box { background: white; border-radius: 16px; padding: 24px; border: 1px solid #EAE9E6; margin-top: 24px; }
105
- .palette-banner { background: #1A1A1A; color: white; padding: 24px; border-radius: 12px; margin-bottom: 24px; }
106
- .palette-banner h2 { font-size: 26px; font-weight: 700; margin: 0 0 4px 0; }
107
- .palette-banner p { color: #A0A0A0; margin: 0; font-size: 14px; }
108
- .section-split { display: grid; grid-template-columns: 1.2fr 0.8fr; gap: 24px; margin-bottom: 24px; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
109
  @media (max-width: 768px) { .section-split { grid-template-columns: 1fr; } }
110
- .swatch-grid { display: flex; gap: 16px; margin-top: 12px; }
111
- .swatch-card { text-align: center; font-size: 12px; font-weight: 500; color: #555; }
112
- .color-bubble { width: 52px; height: 52px; border-radius: 50%; margin: 0 auto 8px auto; border: 1px solid rgba(0,0,0,0.05); }
113
- .tip-box { background: #F4F3F0; border-radius: 12px; padding: 20px; border: 1px solid #EAE9E6; }
114
- .tip-box h3, .section-split h3 { font-size: 11px; font-weight: 700; color: #A24A70; letter-spacing: 1px; margin-top: 0; }
115
- .tip-box p { font-size: 14px; color: #333; line-height: 1.5; margin: 8px 0 0 0; }
116
- .outfit-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-top: 16px; }
 
117
  @media (max-width: 640px) { .outfit-grid { grid-template-columns: repeat(2, 1fr); } }
118
- .product-card { background: white; border: 1px solid #EAE9E6; border-radius: 12px; padding: 16px; display: flex; flex-direction: column; align-items: center; text-align: center; }
119
- .prod-bubble { width: 36px; height: 36px; border-radius: 50%; margin-bottom: 12px; border: 1px solid rgba(0,0,0,0.04); }
120
- .prod-cat { font-size: 10px; font-weight: 700; color: #A24A70; letter-spacing: 0.5px; }
121
- .prod-title { font-size: 14px; font-weight: 600; color: #111; margin: 4px 0; min-height: 40px; display: flex; align-items: center; }
122
- .prod-brand { font-size: 12px; color: #888; margin-bottom: 12px; display: block; }
123
- .shop-btn { display: block; width: 100%; background: #111111; color: white !important; text-align: center; padding: 8px 0; border-radius: 6px; font-size: 13px; font-weight: 500; text-decoration: none !important; }
124
- .primary-action-btn { background: #111111 !important; color: white !important; border: none !important; border-radius: 8px !important; font-weight: 600 !important; font-size: 16px !important; padding: 12px 0 !important; }
 
 
 
 
 
125
  """
126
 
127
  # ==========================================
128
- # 3. GRADIO INTERFACE LAYOUT
129
  # ==========================================
130
- with gr.Blocks(css=custom_css) as demo:
131
 
132
  with gr.Group(elem_classes="center-text"):
133
- gr.Markdown("PERSONAL COLOR STYLING", elem_classes="prod-cat")
134
  gr.Markdown("# LookMatch", elem_classes="title-main")
135
  gr.Markdown("Discover your perfect color palette and outfit", elem_classes="subtitle-main")
136
 
@@ -143,18 +162,18 @@ with gr.Blocks(css=custom_css) as demo:
143
 
144
  with gr.Row():
145
  with gr.Column() as upload_col:
146
- image_input = gr.Image(label="Upload your photo — Gemini AI will detect your features", type="pil")
147
 
148
  with gr.Column(visible=False) as manual_col:
149
- skin_dropdown = gr.Dropdown(["Fair", "Light", "Medium", "Olive", "Tan", "Deep"], value="Fair", label="Skin tone")
150
- hair_dropdown = gr.Dropdown(["Blonde", "Auburn/Red", "Brunette", "Black", "Grey/White"], value="Blonde", label="Hair color")
151
- eye_dropdown = gr.Dropdown(["Blue", "Green", "Hazel", "Brown", "Dark brown/Black"], value="Blue", label="Eye color")
152
 
153
- submit_btn = gr.Button("Get my look ✨", elem_classes="primary-action-btn")
154
 
155
  # Lower Dashboard Area (Revealed on click)
156
  with gr.Column(visible=False) as output_dashboard:
157
- gr.Markdown("### YOUR FEATURES")
158
  with gr.Row(elem_classes="pill-container"):
159
  skin_tag = gr.Button(value="Fair", size="sm")
160
  hair_tag = gr.Button(value="Blonde", size="sm")
@@ -162,7 +181,7 @@ with gr.Blocks(css=custom_css) as demo:
162
 
163
  palette_output = gr.HTML()
164
 
165
- gr.Markdown("### OUTFIT PICKS")
166
  outfit_output = gr.HTML(elem_classes="outfit-grid")
167
 
168
  # Navigation controller
 
3
  from PIL import Image
4
 
5
  # ==========================================
6
+ # 1. LUXURY DATA & SIMILARITY ANALYSIS LOGIC
7
  # ==========================================
8
 
9
  COLOR_PALETTES = {
10
  "Fair-Blonde-Blue": {
11
+ "name": "ICY COOL BLONDE",
12
+ "description": "Fair Skin · Blonde Hair · Blue Eyes",
13
  "swatches": [
14
  {"name": "Light Blue", "hex": "#A0C4DF"},
15
  {"name": "Soft Lavender", "hex": "#C39BD3"},
16
  {"name": "Ivory", "hex": "#F9F9F6"},
17
  {"name": "Dusty Rose", "hex": "#E8A7A1"}
18
  ],
19
+ "tip": "Avoid harsh black — opt for deep navy or charcoal instead to preserve your delicate contrast."
20
  }
21
  }
22
 
 
23
  RECOMMENDED_LOOK = [
24
  {"category": "TOP", "name": "Powder Blue Linen Blouse", "brand": "Zara", "hex": "#A0C4DF", "url": "https://shopping.google.com"},
25
  {"category": "TROUSERS", "name": "Soft White Wide-Leg Trousers", "brand": "ASOS", "hex": "#F9F9F6", "url": "https://shopping.google.com"},
 
30
  ]
31
 
32
  def analyze_and_recommend(image, skin, hair, eye, choice_method):
 
33
  if choice_method == "Upload a photo" and image is not None:
 
34
  skin_tone, hair_color, eye_color = "Fair", "Blonde", "Blue"
35
  else:
36
  skin_tone, hair_color, eye_color = skin, hair, eye
37
 
 
38
  palette_key = f"{skin_tone}-{hair_color}-{eye_color}"
39
  palette = COLOR_PALETTES.get(palette_key, COLOR_PALETTES["Fair-Blonde-Blue"])
40
 
41
+ # Premium circular swatches with elegant borders
42
  swatches_html = "".join([
43
+ f'<div class="swatch-card"><div class="color-bubble" style="background-color: {s["hex"]};"></div><p>{s["name"].upper()}</p></div>'
44
  for s in palette["swatches"]
45
  ])
46
 
47
+ # Luxury Editorial-style Product Grid
48
  outfit_html = "".join([
49
  f'''
50
  <div class="product-card">
 
52
  <div class="prod-meta">
53
  <span class="prod-cat">{item["category"]}</span>
54
  <p class="prod-title">{item["name"]}</p>
55
+ <span class="prod-brand">{item["brand"].upper()}</span>
56
+ <a href="{item["url"]}" target="_blank" class="shop-btn">VIEW PIECE ↗</a>
57
  </div>
58
  </div>
59
  ''' for item in RECOMMENDED_LOOK
 
62
  palette_results = f"""
63
  <div class="results-box">
64
  <div class="palette-banner">
65
+ <span class="editorial-tag">YOUR ARCHETYPE</span>
66
  <h2>{palette["name"]}</h2>
67
+ <p class="banner-desc">{palette["description"].upper()}</p>
68
  </div>
69
  <div class="section-split">
70
+ <div class="swatch-container">
71
+ <h3>CURATED SWATCHES</h3>
72
  <div class="swatch-grid">{swatches_html}</div>
73
  </div>
74
  <div class="tip-box">
75
+ <h3>EDITORIAL NOTE</h3>
76
  <p>{palette["tip"]}</p>
77
  </div>
78
  </div>
 
89
  )
90
 
91
  # ==========================================
92
+ # 2. CLASSY, HIGH-END EDITORIAL DESIGN THEME
93
  # ==========================================
94
+ luxury_css = """
95
+ body { background-color: #F6F5F2 !important; font-family: "Didot", "Playfair Display", "Times New Roman", serif; }
96
+ .gradio-container { max-width: 800px !important; margin: 0 auto !important; padding-top: 50px !important; }
97
  .center-text { text-align: center; }
98
+
99
+ /* Typography */
100
+ .prod-cat { font-size: 11px; font-weight: 600; color: #8C7A6B; letter-spacing: 2px; text-transform: uppercase; margin-bottom: 8px; }
101
+ .title-main { font-size: 48px; font-weight: 700; color: #111111; font-family: "Didot", serif; margin-bottom: 2px; letter-spacing: -1px; }
102
+ .subtitle-main { font-size: 14px; font-style: italic; color: #666666; margin-bottom: 40px; letter-spacing: 0.5px; }
103
+ h3 { font-family: -apple-system, BlinkMacSystemFont, sans-serif; font-size: 10px; font-weight: 700; color: #8C7A6B; letter-spacing: 2px; margin-bottom: 14px; }
104
+
105
+ /* Radio Navigation Tabs */
106
+ .gr-radio { display: flex; justify-content: center; gap: 24px; border: none !important; background: transparent !important; }
107
+ .gr-radio label { font-family: -apple-system, sans-serif; font-size: 13px !important; text-transform: uppercase; letter-spacing: 1px; color: #777 !important; border-bottom: 2px solid transparent; padding-bottom: 4px; transition: all 0.3s; }
108
+ .gr-radio label.selected { color: #111 !important; border-bottom: 2px solid #111 !important; font-weight: 600; }
109
+
110
+ /* Input Elements */
111
+ .gr-box { border-radius: 0px !important; border: 1px solid #DCD9G6 !important; background-color: #FFFFFF !important; }
112
+
113
+ /* Main Output Board */
114
+ .results-box { background: #FFFFFF; border-radius: 0px; padding: 32px; border: 1px solid #E4E2DF; margin-top: 32px; box-shadow: 0 10px 40px rgba(0,0,0,0.03); }
115
+ .palette-banner { background: #111111; color: #FFFFFF; padding: 32px; border-radius: 0px; margin-bottom: 32px; text-align: center; border-bottom: 3px solid #D4AF37; }
116
+ .editorial-tag { font-size: 9px; font-weight: 700; color: #D4AF37; letter-spacing: 3px; display: block; margin-bottom: 8px; font-family: -apple-system, sans-serif; }
117
+ .palette-banner h2 { font-family: "Didot", serif; font-size: 36px; font-weight: 400; margin: 0 0 6px 0; letter-spacing: 1px; }
118
+ .banner-desc { font-family: -apple-system, sans-serif; color: #C0C0A0; margin: 0; font-size: 11px; letter-spacing: 1.5px; }
119
+
120
+ /* Section Grid Splits */
121
+ .section-split { display: grid; grid-template-columns: 1.1fr 0.9fr; gap: 32px; margin-bottom: 16px; }
122
  @media (max-width: 768px) { .section-split { grid-template-columns: 1fr; } }
123
+ .swatch-grid { display: flex; gap: 20px; }
124
+ .swatch-card { text-align: center; font-family: -apple-system, sans-serif; font-size: 10px; font-weight: 600; color: #444; letter-spacing: 0.5px; }
125
+ .color-bubble { width: 48px; height: 48px; border-radius: 50%; margin: 0 auto 10px auto; border: 1px solid rgba(0,0,0,0.08); box-shadow: inset 0 0 0 2px #FFFFFF; }
126
+ .tip-box { background: #FAF9F6; padding: 24px; border-left: 2px solid #D4AF37; }
127
+ .tip-box p { font-size: 14px; font-style: italic; color: #444; line-height: 1.6; margin: 0; }
128
+
129
+ /* Luxury E-Commerce Product Grid */
130
+ .outfit-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; margin-top: 24px; }
131
  @media (max-width: 640px) { .outfit-grid { grid-template-columns: repeat(2, 1fr); } }
132
+ .product-card { background: #FFFFFF; border: 1px solid #EAE8E4; border-radius: 0px; padding: 20px; display: flex; flex-direction: column; align-items: center; text-align: center; transition: transform 0.3s; }
133
+ .product-card:hover { transform: translateY(-4px); border-color: #D4AF37; }
134
+ .prod-bubble { width: 32px; height: 36px; border-radius: 4px; margin-bottom: 14px; border: 1px solid rgba(0,0,0,0.05); }
135
+ .prod-title { font-family: "Didot", serif; font-size: 15px; font-weight: 500; color: #111; margin: 6px 0; min-height: 44px; display: flex; align-items: center; line-height: 1.3; }
136
+ .prod-brand { font-family: -apple-system, sans-serif; font-size: 10px; font-weight: 700; color: #888; letter-spacing: 1px; margin-bottom: 16px; }
137
+
138
+ /* Premium CTA Styling */
139
+ .shop-btn { display: block; width: 100%; background: transparent; color: #111111 !important; text-align: center; padding: 10px 0; border: 1px solid #111111; font-family: -apple-system, sans-serif; font-size: 11px; font-weight: 600; letter-spacing: 1px; text-decoration: none !important; transition: all 0.2s; }
140
+ .shop-btn:hover { background: #111111; color: #FFFFFF !important; }
141
+ .primary-action-btn { background: #111111 !important; color: #FFFFFF !important; border: none !important; border-radius: 0px !important; font-family: -apple-system, sans-serif; font-weight: 600 !important; font-size: 14px !important; letter-spacing: 2px !important; padding: 14px 0 !important; text-transform: uppercase; }
142
+ .primary-action-btn:hover { background: #2A2A2A !important; }
143
+ .pill-container button { background: #FAF9F6 !important; border: 1px solid #E4E2DF !important; border-radius: 0px !important; font-family: -apple-system, sans-serif; font-size: 11px !important; font-weight: 600 !important; color: #555 !important; letter-spacing: 1px; text-transform: uppercase; }
144
  """
145
 
146
  # ==========================================
147
+ # 3. INTERFACE BUILD
148
  # ==========================================
149
+ with gr.Blocks(css=luxury_css) as demo:
150
 
151
  with gr.Group(elem_classes="center-text"):
152
+ gr.Markdown("PERSONAL STYLE ARCHITECT", elem_classes="prod-cat")
153
  gr.Markdown("# LookMatch", elem_classes="title-main")
154
  gr.Markdown("Discover your perfect color palette and outfit", elem_classes="subtitle-main")
155
 
 
162
 
163
  with gr.Row():
164
  with gr.Column() as upload_col:
165
+ image_input = gr.Image(label="UPLOAD PORTRAIT — PERSONAL ATTRIBUTES DETECTION", type="pil")
166
 
167
  with gr.Column(visible=False) as manual_col:
168
+ skin_dropdown = gr.Dropdown(["Fair", "Light", "Medium", "Olive", "Tan", "Deep"], value="Fair", label="SKIN ARCHETYPE")
169
+ hair_dropdown = gr.Dropdown(["Blonde", "Auburn/Red", "Brunette", "Black", "Grey/White"], value="Blonde", label="HAIR ARCHETYPE")
170
+ eye_dropdown = gr.Dropdown(["Blue", "Green", "Hazel", "Brown", "Dark brown/Black"], value="Blue", label="EYE ARCHETYPE")
171
 
172
+ submit_btn = gr.Button("ANALYZE PROFILE", elem_classes="primary-action-btn")
173
 
174
  # Lower Dashboard Area (Revealed on click)
175
  with gr.Column(visible=False) as output_dashboard:
176
+ gr.Markdown("### DETECTED SPECIFICATIONS")
177
  with gr.Row(elem_classes="pill-container"):
178
  skin_tag = gr.Button(value="Fair", size="sm")
179
  hair_tag = gr.Button(value="Blonde", size="sm")
 
181
 
182
  palette_output = gr.HTML()
183
 
184
+ gr.Markdown("### CURATED EDITORIAL OUTFIT PICKS")
185
  outfit_output = gr.HTML(elem_classes="outfit-grid")
186
 
187
  # Navigation controller