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 = """

Your Style Tips

" 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()