hank1229 commited on
Commit
4c0757f
·
verified ·
1 Parent(s): 923b2e4

Upload app.py

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