romi2001 commited on
Commit
2ed4b82
·
verified ·
1 Parent(s): 2fdadb5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +132 -19
app.py CHANGED
@@ -3,7 +3,7 @@ import numpy as np
3
  from PIL import Image
4
 
5
  # ==========================================
6
- # 1. LUXURY DATA & SIMILARITY ANALYSIS LOGIC
7
  # ==========================================
8
 
9
  COLOR_PALETTES = {
@@ -31,6 +31,21 @@ RECOMMENDED_LOOKS = {
31
  ]
32
  }
33
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  def analyze_and_recommend(image, skin, hair, eye, choice_method):
35
  if choice_method == "Upload a photo" and image is not None:
36
  skin_tone, hair_color, eye_color = "Light", "Black", "Brown"
@@ -47,22 +62,7 @@ def analyze_and_recommend(image, skin, hair, eye, choice_method):
47
  for s in palette["swatches"]
48
  ])
49
 
50
- # תיקון: שימוש ב-target="_blank" לפתיחה חלקה של הקישורים בכרטיסייה חדשה
51
- outfit_html = "".join([
52
- f'''
53
- <div class="product-card">
54
- <div class="card-color-header" style="background-color: {item['bg']};">
55
- <div class="prod-bubble" style="background-color: {item['hex']};"></div>
56
- </div>
57
- <div class="prod-meta">
58
- <span class="prod-cat">{item['category']}</span>
59
- <p class="prod-title">{item['name']}</p>
60
- <span class="prod-brand">{item['brand']}</span>
61
- <a href="{item['url']}" target="_blank" rel="noopener noreferrer" class="shop-btn">Shop ↗</a>
62
- </div>
63
- </div>
64
- ''' for item in look_items
65
- ])
66
 
67
  palette_results = f"""
68
  <div class="section-split">
@@ -87,9 +87,122 @@ def analyze_and_recommend(image, skin, hair, eye, choice_method):
87
  )
88
 
89
  # ==========================================
90
- # 2. EXACT ORIGINAL LOOKMATCH PILL & GRID STYLES
91
  # ==========================================
92
  lookmatch_css = """
93
  body, .gradio-container { background-color: #F8F5F5 !important; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
94
  .gradio-container { max-width: 850px !important; margin: 0 auto !important; padding-top: 20px !important; }
95
- .center-text { text-align: center
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  from PIL import Image
4
 
5
  # ==========================================
6
+ # 1. DYNAMIC COLOR PROFILE & STORE INTEGRATION
7
  # ==========================================
8
 
9
  COLOR_PALETTES = {
 
31
  ]
32
  }
33
 
34
+ def build_product_card(item):
35
+ """בניית כרטיס מוצר עם מחרוזת פשוטה כדי למנוע בעיות של SyntaxError"""
36
+ card_html = '<div class="product-card">'
37
+ card_html += f'<div class="card-color-header" style="background-color: {item["bg"]};">'
38
+ card_html += f'<div class="prod-bubble" style="background-color: {item["hex"]};"></div>'
39
+ card_html += '</div>'
40
+ card_html += '<div class="prod-meta">'
41
+ card_html += f'<span class="prod-cat">{item["category"]}</span>'
42
+ card_html += f'<p class="prod-title">{item["name"]}</p>'
43
+ card_html += f'<span class="prod-brand">{item["brand"]}</span>'
44
+ card_html += f'<a href="{item["url"]}" target="_blank" rel="noopener noreferrer" class="shop-btn">Shop ↗</a>'
45
+ card_html += '</div>'
46
+ card_html += '</div>'
47
+ return card_html
48
+
49
  def analyze_and_recommend(image, skin, hair, eye, choice_method):
50
  if choice_method == "Upload a photo" and image is not None:
51
  skin_tone, hair_color, eye_color = "Light", "Black", "Brown"
 
62
  for s in palette["swatches"]
63
  ])
64
 
65
+ outfit_html = "".join([build_product_card(item) for item in look_items])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
 
67
  palette_results = f"""
68
  <div class="section-split">
 
87
  )
88
 
89
  # ==========================================
90
+ # 2. FIXED LOOKMATCH PILL & GRID STYLES
91
  # ==========================================
92
  lookmatch_css = """
93
  body, .gradio-container { background-color: #F8F5F5 !important; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
94
  .gradio-container { max-width: 850px !important; margin: 0 auto !important; padding-top: 20px !important; }
95
+ .center-text { text-align: center; }
96
+
97
+ /* כותרות */
98
+ .prod-cat { font-size: 11px; font-weight: 700; color: #D2527F !important; letter-spacing: 1.5px; text-transform: uppercase; }
99
+ .title-main { font-size: 42px; font-weight: 800; color: #111111 !important; margin-bottom: 2px; letter-spacing: -1px; }
100
+ .subtitle-main { font-size: 15px; color: #888888 !important; margin-bottom: 30px; }
101
+ h3 { font-size: 12px; font-weight: 700; color: #A4A1A1 !important; letter-spacing: 1px; margin-top: 0; margin-bottom: 16px; }
102
+
103
+ /* תיקון צבעי טקסט וכפתורים - הכל מוכרח להיות כהה וקריא */
104
+ input, select, textarea, .secondary, .wrap, .slots, .single-select, .select-wrap, span, label {
105
+ color: #111111 !important;
106
+ font-family: -apple-system, BlinkMacSystemFont, sans-serif !important;
107
+ }
108
+ .gr-box, input, select {
109
+ background-color: #FFFFFF !important;
110
+ border: 1px solid #E2DFDA !important;
111
+ }
112
+ div.form { background: transparent !important; border: none !important; box-shadow: none !important; }
113
+
114
+ /* עיצוב הטאבים העליונים */
115
+ fieldset { display: flex !important; justify-content: center !important; gap: 24px !important; border: none !important; background: transparent !important; }
116
+
117
+ /* קופסאות תוצאה */
118
+ .section-split { display: grid; grid-template-columns: repeat(2, 1fr); gap: 20px; margin-top: 24px; }
119
+ @media (max-width: 768px) { .section-split { grid-template-columns: 1fr; } }
120
+ .results-box { background: #FFFFFF; border-radius: 16px; padding: 24px; border: 1px solid #EFECE8; }
121
+ .swatch-grid { display: flex; gap: 20px; justify-content: flex-start; }
122
+ .swatch-card { text-align: center; font-size: 12px; color: #666666 !important; width: 64px; }
123
+ .swatch-card p { color: #666666 !important; }
124
+ .color-bubble { width: 48px; height: 48px; border-radius: 50%; margin: 0 auto 8px auto; border: 1px solid rgba(0,0,0,0.05); }
125
+ .tip-text { font-size: 16px; color: #222222 !important; line-height: 1.5; margin: 0; }
126
+
127
+ /* גריד כרטיסיות ��לבוש */
128
+ .outfit-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; margin-top: 20px; }
129
+ @media (max-width: 768px) { .outfit-grid { grid-template-columns: repeat(2, 1fr); } }
130
+ @media (max-width: 480px) { .outfit-grid { grid-template-columns: 1fr; } }
131
+
132
+ /* עיצוב כרטיסיות הלבוש */
133
+ .product-card { background: #FFFFFF; border: 1px solid #EFECE8; border-radius: 16px; overflow: hidden; display: flex; flex-direction: column; box-shadow: 0 4px 12px rgba(0,0,0,0.01); }
134
+ .card-color-header { width: 100%; height: 95px; display: flex; align-items: center; justify-content: center; }
135
+ .prod-bubble { width: 46px; height: 46px; border-radius: 50%; box-shadow: 0 2px 8px rgba(0,0,0,0.05); }
136
+ .prod-meta { padding: 20px; display: flex; flex-direction: column; align-items: flex-start; text-align: left; }
137
+ .prod-meta .prod-cat { font-size: 11px; font-weight: 700; color: #D2527F !important; letter-spacing: 0.5px; text-transform: uppercase; margin-bottom: 4px; }
138
+ .prod-title { font-size: 16px; font-weight: 700; color: #111111 !important; margin: 0 0 4px 0; line-height: 1.3; min-height: 42px; display: flex; align-items: center; }
139
+ .prod-brand { font-size: 14px; color: #999999 !important; margin-bottom: 16px; display: block; }
140
+
141
+ /* כפתורי הרכישה המקוריים בשחור ברור */
142
+ .shop-btn { display: block; width: 100%; background: #161617; color: #FFFFFF !important; text-align: center; padding: 12px 0; border-radius: 8px; font-size: 14px; font-weight: 700; text-decoration: none !important; letter-spacing: 0.5px; }
143
+ .shop-btn:hover { background: #2D2D2F; }
144
+
145
+ /* כפתור הפעולה הראשי */
146
+ .primary-action-btn { background: #161617 !important; color: #FFFFFF !important; border: none !important; border-radius: 8px !important; font-weight: 700 !important; font-size: 15px !important; padding: 12px 0 !important; text-transform: uppercase; margin-top: 10px; }
147
+
148
+ /* תגיות כפתורי הפילטרים המוצגים למטה */
149
+ .pill-container button { background: #FFFFFF !important; border: 1px solid #E3DFDA !important; border-radius: 4px !important; font-size: 11px !important; font-weight: 700 !important; color: #555555 !important; text-transform: uppercase; letter-spacing: 0.5px; }
150
+ .footer-note { font-size: 13px; color: #A0A0A0 !important; text-align: center; margin-top: 20px; margin-bottom: 30px; }
151
+ """
152
+
153
+ # ==========================================
154
+ # 3. INTERFACE BUILD
155
+ # ==========================================
156
+ with gr.Blocks(css=lookmatch_css) as demo:
157
+
158
+ with gr.Group(elem_classes="center-text"):
159
+ gr.Markdown("PERSONAL COLOR STYLING", show_label=False)
160
+ gr.Markdown("# LookMatch", elem_classes="title-main")
161
+ gr.Markdown("Discover your perfect color palette and outfit", elem_classes="subtitle-main")
162
+
163
+ choice_method = gr.Radio(
164
+ ["Upload a photo", "Choose manually"],
165
+ value="Upload a photo",
166
+ show_label=False,
167
+ interactive=True
168
+ )
169
+
170
+ with gr.Row():
171
+ with gr.Column() as upload_col:
172
+ image_input = gr.Image(label="Upload your photo — Gemini AI will detect your features", type="pil")
173
+
174
+ with gr.Column(visible=False) as manual_col:
175
+ skin_dropdown = gr.Dropdown(["Fair", "Light", "Medium", "Olive", "Tan", "Deep"], value="Light", label="Skin tone")
176
+ hair_dropdown = gr.Dropdown(["Blonde", "Auburn/Red", "Brunette", "Black", "Grey/White"], value="Black", label="Hair color")
177
+ eye_dropdown = gr.Dropdown(["Blue", "Green", "Hazel", "Brown", "Dark brown/Black"], value="Brown", label="Eye color")
178
+
179
+ submit_btn = gr.Button("Get my look ✨", elem_classes="primary-action-btn")
180
+
181
+ with gr.Column(visible=False) as output_dashboard:
182
+ gr.Markdown("### YOUR FEATURES")
183
+ with gr.Row(elem_classes="pill-container"):
184
+ skin_tag = gr.Button(value="Light", size="sm")
185
+ hair_tag = gr.Button(value="Black", size="sm")
186
+ eye_tag = gr.Button(value="Brown", size="sm")
187
+
188
+ palette_output = gr.HTML()
189
+
190
+ gr.Markdown("### OUTFIT PICKS")
191
+ outfit_output = gr.HTML(elem_classes="outfit-grid")
192
+ gr.Markdown("Links open in a new tab", elem_classes="footer-note")
193
+
194
+ def toggle_input_ui(choice):
195
+ if choice == "Choose manually":
196
+ return gr.update(visible=False), gr.update(visible=True)
197
+ return gr.update(visible=True), gr.update(visible=False)
198
+
199
+ choice_method.change(toggle_input_ui, inputs=choice_method, outputs=[upload_col, manual_col])
200
+
201
+ submit_btn.click(
202
+ fn=analyze_and_recommend,
203
+ inputs=[image_input, skin_dropdown, hair_dropdown, eye_dropdown, choice_method],
204
+ outputs=[skin_tag, hair_tag, eye_tag, palette_output, outfit_output, output_dashboard]
205
+ )
206
+
207
+ if __name__ == "__main__":
208
+ demo.launch()