romi2001 commited on
Commit
7440678
·
verified ·
1 Parent(s): 6be0d88

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +78 -57
app.py CHANGED
@@ -364,13 +364,19 @@ def _lighten_hex(hex_color, factor=0.82):
364
  return f"#{r:02x}{g:02x}{b:02x}"
365
 
366
 
 
 
 
 
 
 
367
  _PALETTE_NAMES = {
368
- "fair": {"cool": "Frost Bloom", "warm": "Sunlit Honey", "neutral": "Soft Linen"},
369
- "light": {"cool": "Moonlit Rose", "warm": "Amber Glow", "neutral": "Quiet Dawn"},
370
- "medium": {"cool": "Dusty Orchid", "warm": "Spiced Caramel", "neutral": "Warm Clay"},
371
- "olive": {"cool": "Sage Twilight", "warm": "Bronzed Olive", "neutral": "Earth Tone"},
372
- "tan": {"cool": "Copper Mist", "warm": "Golden Sand", "neutral": "Desert Bloom"},
373
- "deep": {"cool": "Midnight Jewel", "warm": "Mahogany Sun", "neutral": "Onyx Velvet"},
374
  }
375
 
376
 
@@ -380,6 +386,7 @@ def get_palette_name(skin_tone, undertone):
380
  )
381
 
382
 
 
383
  def pil_to_base64(img, max_size=420):
384
  img = img.convert("RGB").copy()
385
  img.thumbnail((max_size, max_size))
@@ -425,19 +432,19 @@ def build_features_recap_html(skin_tone, undertone, style):
425
  )
426
  colors = [c.strip() for c in str(row["recommended_colors"]).split(",") if c.strip()][:4]
427
  swatches = "".join(
428
- f'<div class="swatch-card"><div class="color-bubble" style="background-color:{_swatch_color(c)};">'
429
  f'</div><p>{c.title()}</p></div>'
430
  for c in colors
431
  )
432
  palette_name = get_palette_name(row["skin_tone"], row["undertone"])
433
  return f"""
434
- <div style="position:relative;overflow:hidden;background:#161617;color:white;
435
- border-radius:18px;padding:24px 28px;margin-bottom:16px;">
436
- <div style="position:absolute;top:-40px;right:-40px;width:150px;height:150px;border-radius:50%;
437
- background:rgba(210,82,127,.25);"></div>
438
- <div style="font-size:11px;letter-spacing:1.5px;color:#D2527F;font-weight:700;">YOUR COLOR PALETTE</div>
439
- <div style="font-size:30px;font-weight:800;margin:6px 0 4px;">{palette_name}</div>
440
- <div style="font-size:13px;color:#bdb8c9;">
441
  {row['skin_tone'].title()} skin · {row['undertone'].title()} undertone · {row['style_preference'].title()} style
442
  </div>
443
  </div>
@@ -454,6 +461,7 @@ def build_features_recap_html(skin_tone, undertone, style):
454
  """
455
 
456
 
 
457
  def build_outfit_component_cards_html(row):
458
  """One card per garment piece of the TOP match (top/bottom/shoes/accessory) -
459
  mirrors a 'your outfit, broken into shoppable pieces' layout."""
@@ -466,8 +474,9 @@ def build_outfit_component_cards_html(row):
466
  ]
467
  cards = []
468
  for i, (label, item_name, retailer, col) in enumerate(components):
469
- dot_color = _swatch_color(colors[i % len(colors)])
470
- banner_color = _lighten_hex(dot_color)
 
471
  link = to_shop_link(retailer, row[col], row["gender"])
472
  cards.append(f"""
473
  <div class="product-card">
@@ -564,56 +573,68 @@ def recommend_from_features(skin_tone, undertone, style, gender, age_group, ques
564
  # GRADIO UI
565
  # ---------------------------------------------------------------------------
566
  CUSTOM_CSS = """
567
- @import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');
568
- body, .gradio-container {background-color: #F8F5F5 !important;
569
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif !important;}
570
- .gradio-container {max-width: 850px !important; margin: 0 auto !important;}
571
  footer {display: none !important;}
572
 
573
- .tab-nav button {font-size: 15px !important; font-weight: 600 !important; padding: 12px 24px !important;}
574
- .tab-nav button.selected {color: #D2527F !important; border-bottom: 2px solid #D2527F !important;}
 
575
 
576
- #find-btn, .big-btn {background: #161617 !important; color: #fff !important; border: none !important;
577
- border-radius: 8px !important; font-weight: 700 !important; font-size: 15px !important;
578
- padding: 13px !important; text-transform: uppercase; transition: background .2s !important;}
579
- #find-btn:hover, .big-btn:hover {background: #2D2D2F !important;}
 
580
 
581
- .dark-panel {background: #161617 !important; border-radius: 16px !important; padding: 18px !important;}
582
- .dark-panel label, .dark-panel span {color: #f0e6ea !important;}
583
 
584
  /* Results layout */
585
- .section-split {display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; margin-bottom: 14px;}
586
- .results-box {background: #FFFFFF; border-radius: 16px; padding: 22px; border: 1px solid #EFECE8;}
587
- .results-box h3 {font-size: 11px; font-weight: 700; color: #A4A1A1; letter-spacing: 1.2px;
588
- text-transform: uppercase; margin: 0 0 14px;}
589
- .swatch-grid {display: flex; gap: 18px; flex-wrap: wrap;}
590
- .swatch-card {text-align: center; font-size: 11px; color: #666; width: 58px;}
591
- .color-bubble {width: 44px; height: 44px; border-radius: 50%; margin: 0 auto 6px; border: 1px solid rgba(0,0,0,.06);}
592
- .tip-text {font-size: 14px; color: #222; line-height: 1.55; margin: 0;}
 
 
593
 
594
  /* Outfit / product cards */
595
- .outfit-grid {display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px;}
596
  @media (max-width: 700px) {.outfit-grid {grid-template-columns: repeat(2, 1fr);}}
597
- .product-card {background: #fff; border: 1px solid #EFECE8; border-radius: 16px; overflow: hidden;}
598
- .card-color-header {width: 100%; height: 80px; display: flex; align-items: center; justify-content: center;}
599
- .prod-bubble {width: 40px; height: 40px; border-radius: 50%; box-shadow: 0 2px 8px rgba(0,0,0,.05);}
600
- .prod-meta {padding: 16px;}
601
- .prod-cat {font-size: 10px; font-weight: 700; color: #D2527F; letter-spacing: 1px; text-transform: uppercase;}
602
- .prod-title {font-size: 14px; font-weight: 700; color: #111; margin: 4px 0 2px; line-height: 1.3;}
603
- .prod-brand {font-size: 11px; color: #999; display: block; margin-bottom: 10px;}
604
- .shop-btn {display: block; text-align: center; padding: 9px 0; background: #161617; color: #fff !important;
605
- text-decoration: none !important; border-radius: 8px; font-size: 12px; font-weight: 700;}
606
- .shop-btn:hover {background: #2D2D2F;}
607
- .more-matches-label {font-size: 11px; font-weight: 700; color: #A4A1A1; letter-spacing: 1.2px;
608
- text-transform: uppercase; margin: 18px 0 8px;}
 
 
 
609
  """
610
 
611
- with gr.Blocks(title="AI Fashion Stylist", css=CUSTOM_CSS, theme=gr.themes.Soft(primary_hue="purple")) as demo:
612
- gr.Markdown(
613
- "# 👗 AI Fashion Stylist\n"
614
- "Upload a photo **or** describe your style — get real catalog matches, shop links, "
615
- "a brand-new AI-generated full-look photo, and a personal stylist note."
616
- )
 
 
 
 
 
617
 
618
  with gr.Tab("📸 Upload a Photo"):
619
  with gr.Row():
@@ -623,7 +644,7 @@ with gr.Blocks(title="AI Fashion Stylist", css=CUSTOM_CSS, theme=gr.themes.Soft(
623
  age_a = gr.Dropdown(AGE_GROUPS, label="Age group (optional)")
624
  question_a = gr.Textbox(label="Ask the stylist a question about your photo (optional)",
625
  placeholder="e.g. What style would suit me best?")
626
- btn_a = gr.Button("Get My Look ✨", elem_id="find-btn", variant="primary")
627
  style_card_a = gr.HTML(label="Style Profile")
628
  new_img_a = gr.Image(label="✨ Your New AI-Generated Look")
629
  answer_a = gr.Textbox(label="Answer to your question")
@@ -655,7 +676,7 @@ with gr.Blocks(title="AI Fashion Stylist", css=CUSTOM_CSS, theme=gr.themes.Soft(
655
  age_b = gr.Dropdown(AGE_GROUPS, label="Age group", value=AGE_GROUPS[0])
656
  question_b = gr.Textbox(label="Ask the stylist a question about the top match (optional)",
657
  placeholder="e.g. Is this outfit formal or casual?")
658
- btn_b = gr.Button("Get My Look ✨", elem_id="find-btn", elem_classes="big-btn", variant="primary")
659
  features_recap_b = gr.HTML(build_features_recap_html(SKIN_TONES[0], UNDERTONES[0], STYLES[0]))
660
  for _dropdown in (skin_b, undertone_b, style_b):
661
  _dropdown.change(
@@ -685,4 +706,4 @@ with gr.Blocks(title="AI Fashion Stylist", css=CUSTOM_CSS, theme=gr.themes.Soft(
685
  )
686
 
687
  if __name__ == "__main__":
688
- demo.launch()
 
364
  return f"#{r:02x}{g:02x}{b:02x}"
365
 
366
 
367
+ def _soften_color(hex_color, factor=0.38):
368
+ """Moderately lightens a color toward a pastel-leaning, elegant tone - keeps the hue
369
+ recognizable (so the color *name* shown stays accurate) without it looking garish."""
370
+ return _lighten_hex(hex_color, factor)
371
+
372
+
373
  _PALETTE_NAMES = {
374
+ "fair": {"cool": "Porcelain Frost", "warm": "Champagne Silk", "neutral": "Pale Linen"},
375
+ "light": {"cool": "Moonlit Pearl", "warm": "Gilded Honey", "neutral": "Quiet Ivory"},
376
+ "medium": {"cool": "Dusk Orchid", "warm": "Spiced Amber", "neutral": "Warm Alabaster"},
377
+ "olive": {"cool": "Sage Noir", "warm": "Burnished Olive", "neutral": "Terracotta Earth"},
378
+ "tan": {"cool": "Copper Veil", "warm": "Gilded Sand", "neutral": "Desert Rosé"},
379
+ "deep": {"cool": "Midnight Sapphire", "warm": "Mahogany Gold", "neutral": "Onyx Velvet"},
380
  }
381
 
382
 
 
386
  )
387
 
388
 
389
+
390
  def pil_to_base64(img, max_size=420):
391
  img = img.convert("RGB").copy()
392
  img.thumbnail((max_size, max_size))
 
432
  )
433
  colors = [c.strip() for c in str(row["recommended_colors"]).split(",") if c.strip()][:4]
434
  swatches = "".join(
435
+ f'<div class="swatch-card"><div class="color-bubble" style="background-color:{_soften_color(_swatch_color(c))};">'
436
  f'</div><p>{c.title()}</p></div>'
437
  for c in colors
438
  )
439
  palette_name = get_palette_name(row["skin_tone"], row["undertone"])
440
  return f"""
441
+ <div style="position:relative;overflow:hidden;background:#1B1814;color:#F5EFE6;
442
+ border-radius:10px;padding:28px 32px;margin-bottom:18px;">
443
+ <div style="position:absolute;top:-50px;right:-50px;width:170px;height:170px;border-radius:50%;
444
+ background:rgba(201,168,118,.18);"></div>
445
+ <div style="font-size:10.5px;letter-spacing:2px;color:#C9A876;font-weight:600;">YOUR COLOR PALETTE</div>
446
+ <div class="palette-name" style="font-size:34px;font-weight:700;margin:8px 0 6px;">{palette_name}</div>
447
+ <div style="font-size:13px;color:#B3A38A;letter-spacing:.02em;">
448
  {row['skin_tone'].title()} skin · {row['undertone'].title()} undertone · {row['style_preference'].title()} style
449
  </div>
450
  </div>
 
461
  """
462
 
463
 
464
+
465
  def build_outfit_component_cards_html(row):
466
  """One card per garment piece of the TOP match (top/bottom/shoes/accessory) -
467
  mirrors a 'your outfit, broken into shoppable pieces' layout."""
 
474
  ]
475
  cards = []
476
  for i, (label, item_name, retailer, col) in enumerate(components):
477
+ raw_color = _swatch_color(colors[i % len(colors)])
478
+ dot_color = _soften_color(raw_color, 0.30)
479
+ banner_color = _lighten_hex(raw_color, 0.88)
480
  link = to_shop_link(retailer, row[col], row["gender"])
481
  cards.append(f"""
482
  <div class="product-card">
 
573
  # GRADIO UI
574
  # ---------------------------------------------------------------------------
575
  CUSTOM_CSS = """
576
+ @import url('https://fonts.googleapis.com/css2?family=Playfair+Display:wght@600;700&family=Inter:wght@400;500;600;700&display=swap');
577
+ body, .gradio-container {background-color: #FAF7F2 !important;
578
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif !important;}
579
+ .gradio-container {max-width: 860px !important; margin: 0 auto !important;}
580
  footer {display: none !important;}
581
 
582
+ .tab-nav button {font-size: 14px !important; font-weight: 600 !important; padding: 14px 26px !important;
583
+ letter-spacing: .03em !important;}
584
+ .tab-nav button.selected {color: #9C7A4E !important; border-bottom: 2px solid #C9A876 !important;}
585
 
586
+ #find-btn, .big-btn {background: #1B1814 !important; color: #F5EFE6 !important; border: none !important;
587
+ border-radius: 4px !important; font-weight: 600 !important; font-size: 14px !important;
588
+ padding: 15px !important; text-transform: uppercase; letter-spacing: .12em !important;
589
+ transition: background .25s !important;}
590
+ #find-btn:hover, .big-btn:hover {background: #3A332B !important;}
591
 
592
+ .dark-panel {background: #1B1814 !important; border-radius: 10px !important; padding: 22px !important;}
593
+ .dark-panel label, .dark-panel span {color: #E8DFD2 !important;}
594
 
595
  /* Results layout */
596
+ .section-split {display: grid; grid-template-columns: repeat(2, 1fr); gap: 18px; margin-bottom: 16px;}
597
+ .results-box {background: #FFFFFF; border-radius: 6px; padding: 26px;
598
+ border: 1px solid #ECE4D6; box-shadow: 0 8px 28px rgba(60,50,30,.04);}
599
+ .results-box h3 {font-size: 10.5px; font-weight: 600; color: #B3A38A; letter-spacing: 1.6px;
600
+ text-transform: uppercase; margin: 0 0 16px;}
601
+ .swatch-grid {display: flex; gap: 20px; flex-wrap: wrap;}
602
+ .swatch-card {text-align: center; font-size: 11px; color: #8A7F6E; width: 58px;}
603
+ .color-bubble {width: 42px; height: 42px; border-radius: 50%; margin: 0 auto 8px;
604
+ border: 1px solid rgba(0,0,0,.05); box-shadow: 0 2px 6px rgba(0,0,0,.05);}
605
+ .tip-text {font-size: 14px; color: #3A332B; line-height: 1.65; margin: 0; font-style: italic;}
606
 
607
  /* Outfit / product cards */
608
+ .outfit-grid {display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px;}
609
  @media (max-width: 700px) {.outfit-grid {grid-template-columns: repeat(2, 1fr);}}
610
+ .product-card {background: #fff; border: 1px solid #ECE4D6; border-radius: 6px; overflow: hidden;
611
+ box-shadow: 0 8px 28px rgba(60,50,30,.04);}
612
+ .card-color-header {width: 100%; height: 84px; display: flex; align-items: center; justify-content: center;}
613
+ .prod-bubble {width: 38px; height: 38px; border-radius: 50%; box-shadow: 0 2px 8px rgba(0,0,0,.06);}
614
+ .prod-meta {padding: 18px;}
615
+ .prod-cat {font-size: 10px; font-weight: 600; color: #9C7A4E; letter-spacing: 1.4px; text-transform: uppercase;}
616
+ .prod-title {font-size: 14px; font-weight: 600; color: #1B1814; margin: 5px 0 3px; line-height: 1.3;}
617
+ .prod-brand {font-size: 11px; color: #B3A38A; display: block; margin-bottom: 12px; letter-spacing: .04em;}
618
+ .shop-btn {display: block; text-align: center; padding: 10px 0; background: #1B1814; color: #F5EFE6 !important;
619
+ text-decoration: none !important; border-radius: 4px; font-size: 11px; font-weight: 600;
620
+ letter-spacing: .1em; text-transform: uppercase;}
621
+ .shop-btn:hover {background: #C9A876; color: #1B1814 !important;}
622
+ .more-matches-label {font-size: 10.5px; font-weight: 600; color: #B3A38A; letter-spacing: 1.6px;
623
+ text-transform: uppercase; margin: 20px 0 10px;}
624
+ .palette-name {font-family: 'Playfair Display', Georgia, serif !important;}
625
  """
626
 
627
+ with gr.Blocks(title="Personal Color Styling", css=CUSTOM_CSS, theme=gr.themes.Soft(primary_hue="amber")) as demo:
628
+ gr.HTML("""
629
+ <div style="text-align:center;padding:30px 20px 18px;">
630
+ <div style="font-size:11px;font-weight:600;color:#C9A876;letter-spacing:.18em;
631
+ text-transform:uppercase;margin-bottom:10px;">Personal Color Styling</div>
632
+ <div style="font-size:14px;color:#8A7F6E;max-width:480px;margin:0 auto;line-height:1.6;">
633
+ Upload a photo or describe your features — receive a curated palette,
634
+ a personal stylist note, and a brand-new look generated just for you.
635
+ </div>
636
+ </div>
637
+ """)
638
 
639
  with gr.Tab("📸 Upload a Photo"):
640
  with gr.Row():
 
644
  age_a = gr.Dropdown(AGE_GROUPS, label="Age group (optional)")
645
  question_a = gr.Textbox(label="Ask the stylist a question about your photo (optional)",
646
  placeholder="e.g. What style would suit me best?")
647
+ btn_a = gr.Button("Reveal My Palette", elem_id="find-btn", variant="primary")
648
  style_card_a = gr.HTML(label="Style Profile")
649
  new_img_a = gr.Image(label="✨ Your New AI-Generated Look")
650
  answer_a = gr.Textbox(label="Answer to your question")
 
676
  age_b = gr.Dropdown(AGE_GROUPS, label="Age group", value=AGE_GROUPS[0])
677
  question_b = gr.Textbox(label="Ask the stylist a question about the top match (optional)",
678
  placeholder="e.g. Is this outfit formal or casual?")
679
+ btn_b = gr.Button("Reveal My Palette", elem_id="find-btn", elem_classes="big-btn", variant="primary")
680
  features_recap_b = gr.HTML(build_features_recap_html(SKIN_TONES[0], UNDERTONES[0], STYLES[0]))
681
  for _dropdown in (skin_b, undertone_b, style_b):
682
  _dropdown.change(
 
706
  )
707
 
708
  if __name__ == "__main__":
709
+ demo.launch()