Spaces:
Running
Running
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() | |