DurgaDeepak commited on
Commit
6eae2d9
·
verified ·
1 Parent(s): 4d89c61

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -43
app.py CHANGED
@@ -1,48 +1,39 @@
1
- # app.py
2
  import gradio as gr
3
  import spaces
4
  from agent import generate_response
5
 
 
 
 
 
 
 
6
  @spaces.GPU
7
- def main():
8
- with gr.Blocks(title="Meal Plan Chatbot") as demo:
9
- gr.Markdown("# 🍎 MealBot: Your AI Nutritionist")
10
-
11
- with gr.Row():
12
- diet_type = gr.CheckboxGroup(
13
- label="Diet Type",
14
- choices=["Vegan", "Keto", "Vegetarian", "Paleo", "High-Protein"],
15
- value=["Vegetarian"]
16
- )
17
- goal = gr.CheckboxGroup(
18
- label="Your Goal",
19
- choices=["Weight Loss", "Muscle Gain", "Maintenance"],
20
- value=["Weight Loss"]
21
- )
22
- duration = gr.CheckboxGroup(
23
- label="Duration",
24
- choices=["1 week", "4 weeks", "8 weeks"],
25
- value=["4 weeks"]
26
- )
27
-
28
- chatbot = gr.Chatbot()
29
- msg = gr.Textbox(placeholder="Ask me anything about meal plans...")
30
- clear = gr.Button("Clear")
31
-
32
- def user_respond(message, chat_history):
33
- prefs = {
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()