romi2001 commited on
Commit
e5d76df
·
verified ·
1 Parent(s): d45a40d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -11
app.py CHANGED
@@ -56,10 +56,11 @@ COMPONENT_RETAILERS = {
56
  "ACCESSORY": "mango",
57
  }
58
 
 
59
  RETAILER_SEARCH_URLS = {
60
  "zara": "https://www.zara.com/us/en/search?searchTerm={query}&section={section}",
61
  "hm": "https://www2.hm.com/en_us/search-results.html?q={query}",
62
- "asos": "https://www.asos.com/us/{dept}/search/?q={query}",
63
  "mango": "https://shop.mango.com/us/en/search?kw={query}",
64
  "shein": "https://us.shein.com/pdsearch/{query}/",
65
  }
@@ -172,7 +173,7 @@ SEASON_INFO = {
172
  },
173
  "Summer": {
174
  "blurb": "Cool and soft — muted, misty colors flatter your cool undertone beautifully.",
175
- "palette": [("Powder Blue", "#B0E0E6"), ("Lavender", "#B497D6"), ("Rose Pink", "#D17B96"),
176
  ("Soft Teal", "#5F9EA0"), ("Dusty Mauve", "#A97C8A"), ("Slate Gray", "#6E7B8B")],
177
  },
178
  "Winter": {
@@ -232,7 +233,7 @@ def derive_color_profile(skin_tone, undertone, eye_color=None):
232
  return season, info["blurb"], info["palette"]
233
 
234
  # =============================================================================
235
- # Core Engine: Skin Heuristics & Search Pipeling
236
  # =============================================================================
237
 
238
  def estimate_skin_tone_undertone(pil_image, available_skin_tones):
@@ -349,18 +350,28 @@ def normalize_gender(gender):
349
  return "women"
350
 
351
  def component_shop_link(retailer, item_text, gender=None):
 
352
  dept = normalize_gender(gender)
353
- text = str(item_text)
 
 
 
 
354
  if retailer == "zara":
355
  section = "MAN" if dept == "men" else "WOMAN"
356
- query = urllib.parse.quote(text)
357
- return RETAILER_SEARCH_URLS["zara"].format(query=query, section=section)
358
  if retailer == "asos":
359
- query = urllib.parse.quote(text)
360
- return RETAILER_SEARCH_URLS["asos"].format(query=query, dept=dept)
361
- gender_word = "men's" if dept == "men" else "women's"
362
- query = urllib.parse.quote(f"{gender_word} {text}")
363
- return RETAILER_SEARCH_URLS[retailer].format(query=query)
 
 
 
 
 
364
 
365
  # =============================================================================
366
  # HTML Luxury Rendering Engine
 
56
  "ACCESSORY": "mango",
57
  }
58
 
59
+ # Optimized and validated production URLs for fashion e-commerce search engines
60
  RETAILER_SEARCH_URLS = {
61
  "zara": "https://www.zara.com/us/en/search?searchTerm={query}&section={section}",
62
  "hm": "https://www2.hm.com/en_us/search-results.html?q={query}",
63
+ "asos": "https://www.asos.com/us/search/?q={query}",
64
  "mango": "https://shop.mango.com/us/en/search?kw={query}",
65
  "shein": "https://us.shein.com/pdsearch/{query}/",
66
  }
 
173
  },
174
  "Summer": {
175
  "blurb": "Cool and soft — muted, misty colors flatter your cool undertone beautifully.",
176
+ "palette": [("Power Blue", "#B0E0E6"), ("Lavender", "#B497D6"), ("Rose Pink", "#D17B96"),
177
  ("Soft Teal", "#5F9EA0"), ("Dusty Mauve", "#A97C8A"), ("Slate Gray", "#6E7B8B")],
178
  },
179
  "Winter": {
 
233
  return season, info["blurb"], info["palette"]
234
 
235
  # =============================================================================
236
+ # Core Engine: Skin Heuristics & Search Pipeline
237
  # =============================================================================
238
 
239
  def estimate_skin_tone_undertone(pil_image, available_skin_tones):
 
350
  return "women"
351
 
352
  def component_shop_link(retailer, item_text, gender=None):
353
+ """Build a robust, live retailer search URL for one outfit component."""
354
  dept = normalize_gender(gender)
355
+ text = str(item_text).strip()
356
+
357
+ # URL encoding to safely preserve spacing and text literals across browsers
358
+ query_encoded = urllib.parse.quote(text)
359
+
360
  if retailer == "zara":
361
  section = "MAN" if dept == "men" else "WOMAN"
362
+ return RETAILER_SEARCH_URLS["zara"].format(query=query_encoded, section=section)
363
+
364
  if retailer == "asos":
365
+ return RETAILER_SEARCH_URLS["asos"].format(query=query_encoded)
366
+
367
+ # Standardizing search queries for H&M, Mango, and Shein by prepending department contexts
368
+ gender_prefix = "mens" if dept == "men" else "womens"
369
+ combined_query = urllib.parse.quote(f"{gender_prefix} {text}")
370
+
371
+ if retailer in RETAILER_SEARCH_URLS:
372
+ return RETAILER_SEARCH_URLS[retailer].format(query=combined_query)
373
+
374
+ return f"https://www.google.com/search?q={query_encoded}"
375
 
376
  # =============================================================================
377
  # HTML Luxury Rendering Engine