-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
95 lines (82 loc) · 3.16 KB
/
app.py
File metadata and controls
95 lines (82 loc) · 3.16 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
"""
Main application file for FashNova AI Fashion Advisor.
"""
import gradio as gr
from src.agents.fashion_advisor import AIris
def initialize_agent(offline_mode: bool = False):
"""Initialize the AIris agent."""
return AIris(offline_mode=offline_mode)
# Initialize agent
agent = initialize_agent(offline_mode=True) # Start in offline mode by default
def switch_mode(mode: bool) -> str:
"""Switch between online and offline modes."""
global agent
agent = initialize_agent(offline_mode=mode)
return f"Switched to {'offline' if mode else 'online'} mode successfully!"
def chat_with_mode(message: str, image, weather: str, occasion: str, style: str, offline_mode: bool) -> str:
"""Handle chat with current mode."""
global agent
if agent.offline_mode != offline_mode:
agent = initialize_agent(offline_mode=offline_mode)
return agent.chat(message, image, weather, occasion, style)
# Create the interface
with gr.Blocks(title="👗 AIris - Your AI Fashion Advisor") as demo:
gr.Markdown("# 👗 AIris - Your AI Fashion Advisor")
gr.Markdown("Get personalized fashion advice and style recommendations!")
with gr.Row():
mode_switch = gr.Checkbox(
label="Offline Mode",
value=True,
info="Toggle between online (using Groq API) and offline mode"
)
mode_indicator = gr.Textbox(
label="Mode Status",
value="Currently in offline mode",
interactive=False
)
with gr.Row():
with gr.Column():
message = gr.Textbox(label="Ask AIris about fashion...")
image = gr.Image(label="Upload an image (optional)", type="pil")
weather = gr.Dropdown(
choices=["hot", "cold", "rainy", "windy"],
label="Weather",
value="hot"
)
occasion = gr.Dropdown(
choices=["casual", "formal", "business", "party"],
label="Occasion",
value="casual"
)
style = gr.Dropdown(
choices=["classic", "modern", "bohemian", "minimalist"],
label="Style",
value="classic"
)
submit = gr.Button("Get Advice")
with gr.Column():
output = gr.Textbox(label="AIris's Response")
# Handle mode switching
mode_switch.change(
fn=lambda x: f"Currently in {'offline' if x else 'online'} mode",
inputs=[mode_switch],
outputs=[mode_indicator]
)
# Handle chat submission
submit.click(
fn=chat_with_mode,
inputs=[message, image, weather, occasion, style, mode_switch],
outputs=[output]
)
# Add examples
gr.Examples(
examples=[
["What should I wear to a summer wedding?", None, "hot", "formal", "classic"],
["How do I style a white shirt?", None, "cold", "business", "minimalist"],
["Suggest an outfit for rainy weather", None, "rainy", "casual", "modern"]
],
inputs=[message, image, weather, occasion, style]
)
# Launch the app
if __name__ == "__main__":
demo.launch()