Update app.py
Browse files
app.py
CHANGED
|
@@ -3,24 +3,23 @@ import numpy as np
|
|
| 3 |
from PIL import Image
|
| 4 |
|
| 5 |
# ==========================================
|
| 6 |
-
# 1.
|
| 7 |
# ==========================================
|
| 8 |
|
| 9 |
COLOR_PALETTES = {
|
| 10 |
"Fair-Blonde-Blue": {
|
| 11 |
-
"name": "
|
| 12 |
-
"description": "Fair
|
| 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 |
-
#
|
| 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 |
-
#
|
| 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">
|
| 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>
|
| 75 |
<div class="swatch-grid">{swatches_html}</div>
|
| 76 |
</div>
|
| 77 |
<div class="tip-box">
|
| 78 |
-
<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.
|
| 96 |
# ==========================================
|
| 97 |
-
|
| 98 |
-
body { background-color: #
|
| 99 |
-
.gradio-container { max-width: 800px !important; margin: 0 auto !important; padding-top:
|
| 100 |
.center-text { text-align: center; }
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
.
|
| 104 |
-
.
|
| 105 |
-
.
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
@media (max-width: 768px) { .section-split { grid-template-columns: 1fr; } }
|
| 110 |
-
.swatch-grid { display: flex; gap:
|
| 111 |
-
.swatch-card { text-align: center; font-size:
|
| 112 |
-
.color-bubble { width:
|
| 113 |
-
.tip-box { background: #
|
| 114 |
-
.tip-box
|
| 115 |
-
|
| 116 |
-
|
|
|
|
| 117 |
@media (max-width: 640px) { .outfit-grid { grid-template-columns: repeat(2, 1fr); } }
|
| 118 |
-
.product-card { background:
|
| 119 |
-
.
|
| 120 |
-
.prod-
|
| 121 |
-
.prod-title { font-size:
|
| 122 |
-
.prod-brand { font-size:
|
| 123 |
-
|
| 124 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
"""
|
| 126 |
|
| 127 |
# ==========================================
|
| 128 |
-
# 3.
|
| 129 |
# ==========================================
|
| 130 |
-
with gr.Blocks(css=
|
| 131 |
|
| 132 |
with gr.Group(elem_classes="center-text"):
|
| 133 |
-
gr.Markdown("PERSONAL
|
| 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="
|
| 147 |
|
| 148 |
with gr.Column(visible=False) as manual_col:
|
| 149 |
-
skin_dropdown = gr.Dropdown(["Fair", "Light", "Medium", "Olive", "Tan", "Deep"], value="Fair", label="
|
| 150 |
-
hair_dropdown = gr.Dropdown(["Blonde", "Auburn/Red", "Brunette", "Black", "Grey/White"], value="Blonde", label="
|
| 151 |
-
eye_dropdown = gr.Dropdown(["Blue", "Green", "Hazel", "Brown", "Dark brown/Black"], value="Blue", label="
|
| 152 |
|
| 153 |
-
submit_btn = gr.Button("
|
| 154 |
|
| 155 |
# Lower Dashboard Area (Revealed on click)
|
| 156 |
with gr.Column(visible=False) as output_dashboard:
|
| 157 |
-
gr.Markdown("###
|
| 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
|