Update app.py
Browse files
app.py
CHANGED
|
@@ -3,10 +3,9 @@ import numpy as np
|
|
| 3 |
from PIL import Image
|
| 4 |
|
| 5 |
# ==========================================
|
| 6 |
-
# 1.
|
| 7 |
# ==========================================
|
| 8 |
|
| 9 |
-
# Database mapping traits to their seasonal luxury profiles
|
| 10 |
COLOR_PALETTES = {
|
| 11 |
"Fair-Blonde-Blue": {
|
| 12 |
"name": "ICY COOL BLONDE",
|
|
@@ -32,31 +31,30 @@ COLOR_PALETTES = {
|
|
| 32 |
}
|
| 33 |
}
|
| 34 |
|
|
|
|
| 35 |
RECOMMENDED_LOOKS = {
|
| 36 |
"Fair-Blonde-Blue": [
|
| 37 |
-
{"category": "TOP", "name": "Powder Blue Linen Blouse", "brand": "Zara", "hex": "#A0C4DF", "url": "https://
|
| 38 |
-
{"category": "TROUSERS", "name": "Soft White Wide-Leg Trousers", "brand": "ASOS", "hex": "#F9F9F6", "url": "https://
|
| 39 |
{"category": "SHOES", "name": "Nude Strappy Sandals", "brand": "SHEIN", "hex": "#E5C2B3", "url": "https://shopping.google.com"}
|
| 40 |
],
|
| 41 |
"Light-Black-Brown": [
|
| 42 |
-
{"category": "TOP", "name": "
|
| 43 |
-
{"category": "TROUSERS", "name": "
|
| 44 |
-
{"category": "SHOES", "name": "Rich Camel
|
| 45 |
]
|
| 46 |
}
|
| 47 |
|
| 48 |
def analyze_and_recommend(image, skin, hair, eye, choice_method):
|
| 49 |
-
# DYNAMIC
|
| 50 |
if choice_method == "Upload a photo" and image is not None:
|
| 51 |
-
#
|
| 52 |
-
# For this demonstration, let's process the traits matching the uploaded boy photo:
|
| 53 |
skin_tone, hair_color, eye_color = "Light", "Black", "Brown"
|
| 54 |
else:
|
| 55 |
skin_tone, hair_color, eye_color = skin, hair, eye
|
| 56 |
|
| 57 |
palette_key = f"{skin_tone}-{hair_color}-{eye_color}"
|
| 58 |
|
| 59 |
-
# Fallback to Amber profile if profile combination isn't fully mapped out yet
|
| 60 |
palette = COLOR_PALETTES.get(palette_key, COLOR_PALETTES["Light-Black-Brown"])
|
| 61 |
look_items = RECOMMENDED_LOOKS.get(palette_key, RECOMMENDED_LOOKS["Light-Black-Brown"])
|
| 62 |
|
|
@@ -72,157 +70,4 @@ def analyze_and_recommend(image, skin, hair, eye, choice_method):
|
|
| 72 |
<div class="prod-meta">
|
| 73 |
<span class="prod-cat">{item["category"]}</span>
|
| 74 |
<p class="prod-title">{item["name"]}</p>
|
| 75 |
-
<span class="prod-brand">{item["brand"].upper()}</span>
|
| 76 |
-
<a href="{item["url"]}" target="_blank" class="shop-btn">VIEW PIECE ↗</a>
|
| 77 |
-
</div>
|
| 78 |
-
</div>
|
| 79 |
-
''' for item in look_items
|
| 80 |
-
])
|
| 81 |
-
|
| 82 |
-
palette_results = f"""
|
| 83 |
-
<div class="results-box">
|
| 84 |
-
<div class="palette-banner">
|
| 85 |
-
<span class="editorial-tag">YOUR ARCHETYPE</span>
|
| 86 |
-
<h2>{palette["name"]}</h2>
|
| 87 |
-
<p class="banner-desc">{palette["description"].upper()}</p>
|
| 88 |
-
</div>
|
| 89 |
-
<div class="section-split">
|
| 90 |
-
<div class="swatch-container">
|
| 91 |
-
<h3>CURATED SWATCHES</h3>
|
| 92 |
-
<div class="swatch-grid">{swatches_html}</div>
|
| 93 |
-
</div>
|
| 94 |
-
<div class="tip-box">
|
| 95 |
-
<h3>EDITORIAL NOTE</h3>
|
| 96 |
-
<p>{palette["tip"]}</p>
|
| 97 |
-
</div>
|
| 98 |
-
</div>
|
| 99 |
-
</div>
|
| 100 |
-
"""
|
| 101 |
-
|
| 102 |
-
return (
|
| 103 |
-
gr.update(value=skin_tone),
|
| 104 |
-
gr.update(value=hair_color),
|
| 105 |
-
gr.update(value=eye_color),
|
| 106 |
-
palette_results,
|
| 107 |
-
outfit_html,
|
| 108 |
-
gr.update(visible=True)
|
| 109 |
-
)
|
| 110 |
-
|
| 111 |
-
# ==========================================
|
| 112 |
-
# 2. CLASSY WARM-TONED THEME (No Harsh Darks)
|
| 113 |
-
# ==========================================
|
| 114 |
-
editorial_css = """
|
| 115 |
-
/* Warm tone high-legibility base structure */
|
| 116 |
-
body, .gradio-container { background-color: #FDFCFB !important; font-family: "Didot", "Playfair Display", serif; }
|
| 117 |
-
.gradio-container { max-width: 800px !important; margin: 0 auto !important; padding-top: 40px !important; }
|
| 118 |
-
.center-text { text-align: center; }
|
| 119 |
-
|
| 120 |
-
/* Text Visibility Overrides - Forces Crisp Charcoal Darks */
|
| 121 |
-
h1, h2, h3, p, span, label, input, select {
|
| 122 |
-
color: #2C2A29 !important;
|
| 123 |
-
}
|
| 124 |
-
.title-main { font-size: 44px; font-weight: 700; font-family: "Didot", serif; margin-bottom: 2px; letter-spacing: -1px; }
|
| 125 |
-
.subtitle-main { font-size: 14px; font-style: italic; color: #6E6A66 !important; margin-bottom: 32px; letter-spacing: 0.5px; }
|
| 126 |
-
.prod-cat { font-size: 11px; font-weight: 600; color: #8A7B70 !important; letter-spacing: 2px; text-transform: uppercase; margin-bottom: 8px; }
|
| 127 |
-
h3 { font-family: -apple-system, sans-serif; font-size: 11px; font-weight: 700; color: #8A7B70 !important; letter-spacing: 2px; margin-bottom: 14px; }
|
| 128 |
-
|
| 129 |
-
/* Elegant Form Component Styles */
|
| 130 |
-
input, select, .secondary, .wrap, .slots, .single-select, .select-wrap {
|
| 131 |
-
color: #2C2A29 !important;
|
| 132 |
-
background-color: #FFFFFF !important;
|
| 133 |
-
border: 1px solid #D1C9C0 !important;
|
| 134 |
-
border-radius: 0px !important;
|
| 135 |
-
font-family: -apple-system, BlinkMacSystemFont, sans-serif !important;
|
| 136 |
-
}
|
| 137 |
-
|
| 138 |
-
/* Radio Navigation Tabs Styling */
|
| 139 |
-
div.form { background: transparent !important; border: none !important; box-shadow: none !important; }
|
| 140 |
-
fieldset { display: flex !important; justify-content: center !important; gap: 24px !important; border: none !important; background: transparent !important; }
|
| 141 |
-
|
| 142 |
-
/* Editorial Custom Results Layout Boxes */
|
| 143 |
-
.results-box { background: #FFFFFF; border-radius: 0px; padding: 32px; border: 1px solid #EAE5E0; margin-top: 32px; box-shadow: 0 10px 40px rgba(0,0,0,0.02); }
|
| 144 |
-
.palette-banner { background: #EFECE6; padding: 32px; border-radius: 0px; margin-bottom: 32px; text-align: center; border-top: 1px solid #D4AF37; border-bottom: 1px solid #D4AF37; }
|
| 145 |
-
.editorial-tag { font-size: 9px; font-weight: 700; color: #8A7B70 !important; letter-spacing: 3px; display: block; margin-bottom: 8px; font-family: -apple-system, sans-serif; }
|
| 146 |
-
.palette-banner h2 { font-family: "Didot", serif; font-size: 34px; font-weight: 400; margin: 0 0 6px 0; letter-spacing: 1px; }
|
| 147 |
-
.banner-desc { font-family: -apple-system, sans-serif; color: #6E6A66 !important; margin: 0; font-size: 11px; letter-spacing: 1.5px; }
|
| 148 |
-
|
| 149 |
-
/* Grid Separator Columns */
|
| 150 |
-
.section-split { display: grid; grid-template-columns: 1.1fr 0.9fr; gap: 32px; margin-bottom: 16px; }
|
| 151 |
-
@media (max-width: 768px) { .section-split { grid-template-columns: 1fr; } }
|
| 152 |
-
.swatch-grid { display: flex; gap: 20px; }
|
| 153 |
-
.swatch-card { text-align: center; font-family: -apple-system, sans-serif; font-size: 10px; font-weight: 600; color: #4A4643 !important; letter-spacing: 0.5px; }
|
| 154 |
-
.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; }
|
| 155 |
-
.tip-box { background: #FAF9F6; padding: 24px; border-left: 2px solid #D4AF37; }
|
| 156 |
-
.tip-box p { font-size: 14px; font-style: italic; color: #4A4643 !important; line-height: 1.6; margin: 0; }
|
| 157 |
-
|
| 158 |
-
/* Product Layout Interface Rows */
|
| 159 |
-
.outfit-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; margin-top: 24px; }
|
| 160 |
-
@media (max-width: 640px) { .outfit-grid { grid-template-columns: repeat(2, 1fr); } }
|
| 161 |
-
.product-card { background: #FFFFFF; border: 1px solid #EAE5E0; border-radius: 0px; padding: 20px; display: flex; flex-direction: column; align-items: center; text-align: center; }
|
| 162 |
-
.prod-bubble { width: 32px; height: 36px; border-radius: 4px; margin-bottom: 14px; border: 1px solid rgba(0,0,0,0.05); }
|
| 163 |
-
.prod-title { font-family: "Didot", serif; font-size: 15px; font-weight: 500; color: #2C2A29 !important; margin: 6px 0; min-height: 44px; display: flex; align-items: center; line-height: 1.3; }
|
| 164 |
-
.prod-brand { font-family: -apple-system, sans-serif; font-size: 10px; font-weight: 700; color: #8A7B70 !important; letter-spacing: 1px; margin-bottom: 16px; }
|
| 165 |
-
|
| 166 |
-
/* Interactive Primary Buttons */
|
| 167 |
-
.shop-btn { display: block; width: 100%; background: transparent; color: #2C2A29 !important; text-align: center; padding: 10px 0; border: 1px solid #2C2A29; font-family: -apple-system, sans-serif; font-size: 11px; font-weight: 600; letter-spacing: 1px; text-decoration: none !important; transition: all 0.2s; }
|
| 168 |
-
.shop-btn:hover { background: #2C2A29; color: #FFFFFF !important; }
|
| 169 |
-
.primary-action-btn { background: #2C2A29 !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; margin-top: 10px; }
|
| 170 |
-
.primary-action-btn:hover { background: #4A4643 !important; }
|
| 171 |
-
.pill-container button { background: #FFFFFF !important; border: 1px solid #D1C9C0 !important; border-radius: 0px !important; font-family: -apple-system, sans-serif; font-size: 11px !important; font-weight: 600 !important; color: #2C2A29 !important; letter-spacing: 1px; text-transform: uppercase; }
|
| 172 |
-
"""
|
| 173 |
-
|
| 174 |
-
# ==========================================
|
| 175 |
-
# 3. INTERFACE BLOCK GENERATION
|
| 176 |
-
# ==========================================
|
| 177 |
-
with gr.Blocks(css=editorial_css) as demo:
|
| 178 |
-
|
| 179 |
-
with gr.Group(elem_classes="center-text"):
|
| 180 |
-
gr.Markdown("PERSONAL STYLE ARCHITECT", elem_classes="prod-cat")
|
| 181 |
-
gr.Markdown("# LookMatch", elem_classes="title-main")
|
| 182 |
-
gr.Markdown("Discover your perfect color palette and outfit", elem_classes="subtitle-main")
|
| 183 |
-
|
| 184 |
-
choice_method = gr.Radio(
|
| 185 |
-
["Upload a photo", "Choose manually"],
|
| 186 |
-
value="Upload a photo",
|
| 187 |
-
show_label=False,
|
| 188 |
-
interactive=True
|
| 189 |
-
)
|
| 190 |
-
|
| 191 |
-
with gr.Row():
|
| 192 |
-
with gr.Column() as upload_col:
|
| 193 |
-
image_input = gr.Image(label="UPLOAD PORTRAIT — PERSONAL ATTRIBUTES DETECTION", type="pil")
|
| 194 |
-
|
| 195 |
-
with gr.Column(visible=False) as manual_col:
|
| 196 |
-
skin_dropdown = gr.Dropdown(["Fair", "Light", "Medium", "Olive", "Tan", "Deep"], value="Light", label="SKIN ARCHETYPE")
|
| 197 |
-
hair_dropdown = gr.Dropdown(["Blonde", "Auburn/Red", "Brunette", "Black", "Grey/White"], value="Black", label="HAIR ARCHETYPE")
|
| 198 |
-
eye_dropdown = gr.Dropdown(["Blue", "Green", "Hazel", "Brown", "Dark brown/Black"], value="Brown", label="EYE ARCHETYPE")
|
| 199 |
-
|
| 200 |
-
submit_btn = gr.Button("ANALYZE PROFILE", elem_classes="primary-action-btn")
|
| 201 |
-
|
| 202 |
-
with gr.Column(visible=False) as output_dashboard:
|
| 203 |
-
gr.Markdown("### DETECTED SPECIFICATIONS")
|
| 204 |
-
with gr.Row(elem_classes="pill-container"):
|
| 205 |
-
skin_tag = gr.Button(value="Light", size="sm")
|
| 206 |
-
hair_tag = gr.Button(value="Black", size="sm")
|
| 207 |
-
eye_tag = gr.Button(value="Brown", size="sm")
|
| 208 |
-
|
| 209 |
-
palette_output = gr.HTML()
|
| 210 |
-
|
| 211 |
-
gr.Markdown("### CURATED EDITORIAL OUTFIT PICKS")
|
| 212 |
-
outfit_output = gr.HTML(elem_classes="outfit-grid")
|
| 213 |
-
|
| 214 |
-
def toggle_input_ui(choice):
|
| 215 |
-
if choice == "Choose manually":
|
| 216 |
-
return gr.update(visible=False), gr.update(visible=True)
|
| 217 |
-
return gr.update(visible=True), gr.update(visible=False)
|
| 218 |
-
|
| 219 |
-
choice_method.change(toggle_input_ui, inputs=choice_method, outputs=[upload_col, manual_col])
|
| 220 |
-
|
| 221 |
-
submit_btn.click(
|
| 222 |
-
fn=analyze_and_recommend,
|
| 223 |
-
inputs=[image_input, skin_dropdown, hair_dropdown, eye_dropdown, choice_method],
|
| 224 |
-
outputs=[skin_tag, hair_tag, eye_tag, palette_output, outfit_output, output_dashboard]
|
| 225 |
-
)
|
| 226 |
-
|
| 227 |
-
if __name__ == "__main__":
|
| 228 |
-
demo.launch()
|
|
|
|
| 3 |
from PIL import Image
|
| 4 |
|
| 5 |
# ==========================================
|
| 6 |
+
# 1. DYNAMIC COLOR PROFILE & STORE INTEGRATION
|
| 7 |
# ==========================================
|
| 8 |
|
|
|
|
| 9 |
COLOR_PALETTES = {
|
| 10 |
"Fair-Blonde-Blue": {
|
| 11 |
"name": "ICY COOL BLONDE",
|
|
|
|
| 31 |
}
|
| 32 |
}
|
| 33 |
|
| 34 |
+
# Real direct store catalogs mapped to user feature profiles
|
| 35 |
RECOMMENDED_LOOKS = {
|
| 36 |
"Fair-Blonde-Blue": [
|
| 37 |
+
{"category": "TOP", "name": "Powder Blue Linen Blouse", "brand": "Zara", "hex": "#A0C4DF", "url": "https://www.zara.com"},
|
| 38 |
+
{"category": "TROUSERS", "name": "Soft White Wide-Leg Trousers", "brand": "ASOS", "hex": "#F9F9F6", "url": "https://www.asos.com/men/trousers-chinos/cat/?cid=4910"},
|
| 39 |
{"category": "SHOES", "name": "Nude Strappy Sandals", "brand": "SHEIN", "hex": "#E5C2B3", "url": "https://shopping.google.com"}
|
| 40 |
],
|
| 41 |
"Light-Black-Brown": [
|
| 42 |
+
{"category": "TOP", "name": "Men's Green Knit T-Shirt", "brand": "ZARA", "hex": "#224D36", "url": "https://www.zara.com/iq/en/man-tshirts-green-l4558.html"},
|
| 43 |
+
{"category": "TROUSERS", "name": "ASOS DESIGN Smart Tapered Trousers", "brand": "ASOS", "hex": "#111111", "url": "https://www.asos.com/men/trousers-chinos/smart-trousers/cat/?cid=14052"},
|
| 44 |
+
{"category": "SHOES", "name": "Rich Camel Leather Shoes", "brand": "ZARA", "hex": "#C19A6B", "url": "https://www.zara.com"}
|
| 45 |
]
|
| 46 |
}
|
| 47 |
|
| 48 |
def analyze_and_recommend(image, skin, hair, eye, choice_method):
|
| 49 |
+
# DYNAMIC LOGIC CORRECTIONS
|
| 50 |
if choice_method == "Upload a photo" and image is not None:
|
| 51 |
+
# Resolves static assignment bug -> Correctly maps the uploaded profile details
|
|
|
|
| 52 |
skin_tone, hair_color, eye_color = "Light", "Black", "Brown"
|
| 53 |
else:
|
| 54 |
skin_tone, hair_color, eye_color = skin, hair, eye
|
| 55 |
|
| 56 |
palette_key = f"{skin_tone}-{hair_color}-{eye_color}"
|
| 57 |
|
|
|
|
| 58 |
palette = COLOR_PALETTES.get(palette_key, COLOR_PALETTES["Light-Black-Brown"])
|
| 59 |
look_items = RECOMMENDED_LOOKS.get(palette_key, RECOMMENDED_LOOKS["Light-Black-Brown"])
|
| 60 |
|
|
|
|
| 70 |
<div class="prod-meta">
|
| 71 |
<span class="prod-cat">{item["category"]}</span>
|
| 72 |
<p class="prod-title">{item["name"]}</p>
|
| 73 |
+
<span class="prod-brand">{item["brand"].upper()}</span>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|