Spaces:
Sleeping
Sleeping
Changed whole code to
Browse files
app.py
CHANGED
|
@@ -1,17 +1,54 @@
|
|
| 1 |
-
import pandas as pd
|
| 2 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
-
def suggest_outfit(
|
| 8 |
-
matches =
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
with gr.Blocks() as demo:
|
| 12 |
gr.Markdown("# Wardrobe Chatbot ππ")
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
demo.launch()
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import pandas as pd
|
| 3 |
+
|
| 4 |
+
# Initialize a dataframe in memory to store clothes
|
| 5 |
+
columns = ["name", "image_path", "category", "weather", "setting", "color"]
|
| 6 |
+
clothes_df = pd.DataFrame(columns=columns)
|
| 7 |
|
| 8 |
+
def add_clothing(name, image, category, weather, setting, color):
|
| 9 |
+
global clothes_df
|
| 10 |
+
new_row = {
|
| 11 |
+
"name": name,
|
| 12 |
+
"image_path": image, # gradio stores path to temp file
|
| 13 |
+
"category": category,
|
| 14 |
+
"weather": weather,
|
| 15 |
+
"setting": setting,
|
| 16 |
+
"color": color
|
| 17 |
+
}
|
| 18 |
+
clothes_df = pd.concat([clothes_df, pd.DataFrame([new_row])], ignore_index=True)
|
| 19 |
+
return f"Added {name}!"
|
| 20 |
|
| 21 |
+
def suggest_outfit(query_weather, query_setting, query_color):
|
| 22 |
+
matches = clothes_df.copy()
|
| 23 |
+
if query_weather:
|
| 24 |
+
matches = matches[matches["weather"].str.contains(query_weather, case=False, na=False)]
|
| 25 |
+
if query_setting:
|
| 26 |
+
matches = matches[matches["setting"].str.contains(query_setting, case=False, na=False)]
|
| 27 |
+
if query_color:
|
| 28 |
+
matches = matches[matches["color"].str.contains(query_color, case=False, na=False)]
|
| 29 |
+
return [[row["image_path"], row["name"]] for _, row in matches.iterrows()]
|
| 30 |
|
| 31 |
with gr.Blocks() as demo:
|
| 32 |
gr.Markdown("# Wardrobe Chatbot ππ")
|
| 33 |
+
|
| 34 |
+
with gr.Tab("Upload Clothes"):
|
| 35 |
+
with gr.Row():
|
| 36 |
+
name = gr.Textbox(label="Name of item")
|
| 37 |
+
image = gr.Image(label="Upload Image", type="filepath")
|
| 38 |
+
category = gr.Dropdown(["Top", "Bottom", "Footwear", "Outerwear", "Accessory"], label="Category")
|
| 39 |
+
weather = gr.Textbox(label="Suitable weather (e.g. hot, rainy)")
|
| 40 |
+
setting = gr.Textbox(label="Suitable setting (e.g. office, beach)")
|
| 41 |
+
color = gr.Textbox(label="Main color (e.g. red, blue)")
|
| 42 |
+
add_btn = gr.Button("Add to Wardrobe")
|
| 43 |
+
status = gr.Textbox(label="Status")
|
| 44 |
+
add_btn.click(add_clothing, inputs=[name, image, category, weather, setting, color], outputs=status)
|
| 45 |
+
|
| 46 |
+
with gr.Tab("Find Outfit"):
|
| 47 |
+
query_weather = gr.Textbox(label="Weather")
|
| 48 |
+
query_setting = gr.Textbox(label="Setting")
|
| 49 |
+
query_color = gr.Textbox(label="Color")
|
| 50 |
+
gallery = gr.Gallery(label="Recommended Clothes").style(grid=[2], height="auto")
|
| 51 |
+
search_btn = gr.Button("Suggest Outfit")
|
| 52 |
+
search_btn.click(suggest_outfit, inputs=[query_weather, query_setting, query_color], outputs=gallery)
|
| 53 |
+
|
| 54 |
demo.launch()
|