Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,48 +1,39 @@
|
|
1 |
-
|
2 |
import gradio as gr
|
3 |
import spaces
|
4 |
from agent import generate_response
|
5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
@spaces.GPU
|
7 |
-
def
|
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 |
-
"diet": diet_type.value,
|
35 |
-
"goal": goal.value,
|
36 |
-
"duration": duration.value
|
37 |
-
}
|
38 |
-
response = generate_response(message, prefs)
|
39 |
-
chat_history.append((message, response))
|
40 |
-
return "", chat_history
|
41 |
-
|
42 |
-
msg.submit(user_respond, [msg, chatbot], [msg, chatbot])
|
43 |
-
clear.click(lambda: None, None, chatbot, queue=False)
|
44 |
-
|
45 |
-
demo.launch()
|
46 |
-
|
47 |
-
if __name__ == "__main__":
|
48 |
-
main()
|
|
|
1 |
+
import os
|
2 |
import gradio as gr
|
3 |
import spaces
|
4 |
from agent import generate_response
|
5 |
|
6 |
+
user_preferences = {
|
7 |
+
"diet": [],
|
8 |
+
"goal": "",
|
9 |
+
"weeks": 1
|
10 |
+
}
|
11 |
+
|
12 |
@spaces.GPU
|
13 |
+
def process_input(message, history):
|
14 |
+
return generate_response(message, history, user_preferences)
|
15 |
+
|
16 |
+
def update_preferences(diet, goal, weeks):
|
17 |
+
user_preferences["diet"] = diet
|
18 |
+
user_preferences["goal"] = goal
|
19 |
+
user_preferences["weeks"] = weeks
|
20 |
+
return gr.update(visible=True)
|
21 |
+
|
22 |
+
with gr.Blocks() as demo:
|
23 |
+
gr.Markdown("## 🥗 Smart Meal Plan Assistant")
|
24 |
+
|
25 |
+
with gr.Row():
|
26 |
+
diet = gr.CheckboxGroup(["Low-carb", "High-protein", "Vegetarian", "Vegan", "Keto"], label="Diet Preferences")
|
27 |
+
goal = gr.Radio(["Weight Loss", "Muscle Gain", "Maintenance"], label="Health Goal")
|
28 |
+
weeks = gr.Slider(1, 12, value=1, step=1, label="Plan Duration (weeks)")
|
29 |
+
|
30 |
+
confirm_btn = gr.Button("Start Chat")
|
31 |
+
chatbot = gr.Chatbot(visible=False)
|
32 |
+
msg = gr.Textbox(visible=False)
|
33 |
+
clear = gr.Button("Clear", visible=False)
|
34 |
+
|
35 |
+
confirm_btn.click(update_preferences, inputs=[diet, goal, weeks], outputs=[chatbot])
|
36 |
+
msg.submit(process_input, [msg, chatbot], chatbot)
|
37 |
+
clear.click(lambda: None, None, chatbot)
|
38 |
+
|
39 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|