File size: 2,368 Bytes
35817a7
0b683a5
 
 
 
35817a7
0b683a5
 
 
 
 
 
 
 
 
 
 
 
35817a7
0b683a5
 
 
 
 
 
 
 
 
35817a7
 
 
0b683a5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ffb0d70
0b683a5
 
 
35817a7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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()