Dupilaicate / app.py
Ifeeab05's picture
Changed from Colab
ffb0d70 verified
import gradio as gr
import pandas as pd
# Initialize a dataframe in memory to store clothes
columns = ["name", "image_path", "category", "weather", "setting", "color"]
clothes_df = pd.DataFrame(columns=columns)
def add_clothing(name, image, category, weather, setting, color):
global clothes_df
new_row = {
"name": name,
"image_path": image, # gradio stores path to temp file
"category": category,
"weather": weather,
"setting": setting,
"color": color
}
clothes_df = pd.concat([clothes_df, pd.DataFrame([new_row])], ignore_index=True)
return f"Added {name}!"
def suggest_outfit(query_weather, query_setting, query_color):
matches = clothes_df.copy()
if query_weather:
matches = matches[matches["weather"].str.contains(query_weather, case=False, na=False)]
if query_setting:
matches = matches[matches["setting"].str.contains(query_setting, case=False, na=False)]
if query_color:
matches = matches[matches["color"].str.contains(query_color, case=False, na=False)]
return [[row["image_path"], row["name"]] for _, row in matches.iterrows()]
with gr.Blocks() as demo:
gr.Markdown("# Wardrobe Chatbot πŸ‘•πŸ‘—")
with gr.Tab("Upload Clothes"):
with gr.Row():
name = gr.Textbox(label="Name of item")
image = gr.Image(label="Upload Image", type="filepath")
category = gr.Dropdown(["Top", "Bottom", "Footwear", "Outerwear", "Accessory"], label="Category")
weather = gr.Textbox(label="Suitable weather (e.g. hot, rainy)")
setting = gr.Textbox(label="Suitable setting (e.g. office, beach)")
color = gr.Textbox(label="Main color (e.g. red, blue)")
add_btn = gr.Button("Add to Wardrobe")
status = gr.Textbox(label="Status")
add_btn.click(add_clothing, inputs=[name, image, category, weather, setting, color], outputs=status)
with gr.Tab("Find Outfit"):
query_weather = gr.Textbox(label="Weather")
query_setting = gr.Textbox(label="Setting")
query_color = gr.Textbox(label="Color")
gallery = gr.Gallery(label="Recommended Clothes", columns=2, height="auto")
search_btn = gr.Button("Suggest Outfit")
search_btn.click(suggest_outfit, inputs=[query_weather, query_setting, query_color], outputs=gallery)
demo.launch()