Spaces:
Running
Running
File size: 1,910 Bytes
4c0757f 5785668 4c0757f 5785668 4c0757f 5785668 4c0757f 5785668 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
import gradio as gr
from utils.detector import detect_clothing
from utils.advisor import get_advice
def run_style_savvy(image, bg_remove, body_type, face_shape, occasion):
# 1) Detect garments
items = detect_clothing(image, do_bg_remove=bg_remove)
# 2) Get raw advice string
advice_text = get_advice(items, body_type, face_shape, occasion)
# 3) Parse out up to 5 tips
tips = []
for line in advice_text.splitlines():
ln = line.strip()
# catch bullets ("- β¦", "* β¦") or numbered ("1. β¦") or plain
if ln.startswith(("-", "*")) or (len(ln) > 1 and ln[0].isdigit() and ln[1] in ". "):
tips.append(ln.lstrip("-*0123456789. ").strip())
if not tips:
# fallback: split on sentences
parts = [p.strip() for p in advice_text.split(".") if p.strip()]
tips = parts[:5]
tips = tips[:5] # ensure max 5
# 4) Build dark-themed HTML
html = """
<div style="
background-color: #1e1e1e;
color: #eeeeee;
padding: 24px;
border-radius: 12px;
max-width: 600px;
">
<h2>Your Style Tips</h2>
<ul style="
list-style: disc inside;
font-size: 1.2em;
line-height: 1.6;
">
"""
for tip in tips:
html += f"<li>{tip}</li>"
html += "</ul></div>"
return html
iface = gr.Interface(
fn=run_style_savvy,
inputs=[
gr.Image(type="pil", label="Your Photo"),
gr.Checkbox(label="Remove Background"),
gr.Radio(["Slim","Athletic","Curvy","Plus-size"], label="Body Type"),
gr.Radio(["Oval","Round","Square","Heart"], label="Face Shape"),
gr.Textbox(label="Occasion"),
],
outputs=gr.HTML(),
title="StyleSavvy",
description="AI-powered fashion consultant. Upload your photo and get personalized style tips!",
)
if __name__ == "__main__":
iface.launch()
|