DurgaDeepak commited on
Commit
2f10c42
·
verified ·
1 Parent(s): 3cf3f2d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -29
app.py CHANGED
@@ -1,39 +1,48 @@
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()
 
 
 
 
 
 
 
 
1
+ # app.py
2
  import gradio as gr
3
  import spaces
4
+ from chatbot_logic import get_bot_response
5
 
6
+ # === User Preference State ===
7
  user_preferences = {
8
+ "diet": None,
9
+ "goal": None,
10
+ "allergies": None,
11
  }
12
 
13
+ # === GPU Eligibility Decorator ===
14
  @spaces.GPU
15
+ def dummy_gpu_task():
16
+ return "Triggered GPU on startup."
17
 
18
+ def set_preferences(diet, goal, allergies):
19
  user_preferences["diet"] = diet
20
  user_preferences["goal"] = goal
21
+ user_preferences["allergies"] = allergies
22
+ return "Preferences updated. You can start chatting now!"
23
+
24
+ def chat_interface(user_input, history):
25
+ # You can optionally use preferences in prompt formatting later
26
+ response = get_bot_response(user_input)
27
+ history.append((user_input, response))
28
+ return "", history
29
+
30
+ with gr.Blocks(title="AI Meal Plan Assistant") as demo:
31
+ gr.Markdown("""
32
+ # 🍽️ Smart Meal Plan Chatbot
33
+ Ask me anything about meal plans, nutrition, or recipes from the PDFs!
34
+ """)
35
+
36
+ with gr.Accordion("Set Your Preferences (Optional)", open=True):
37
+ with gr.Row():
38
+ diet = gr.Radio(label="Diet Type", choices=["None", "Vegan", "Vegetarian", "Keto", "Low-Carb"], value="None")
39
+ goal = gr.Radio(label="Goal", choices=["None", "Weight Loss", "Muscle Gain", "Diabetic Friendly"], value="None")
40
+ allergies = gr.Textbox(label="Allergies (comma-separated)", placeholder="e.g., peanuts, gluten")
41
+ update_btn = gr.Button("Update Preferences")
42
+ output = gr.Textbox(label="Status")
43
+ update_btn.click(fn=set_preferences, inputs=[diet, goal, allergies], outputs=output)
44
+
45
+ chatbot = gr.ChatInterface(chat_interface, title="Meal Planner Chatbot")
46
+
47
+ if __name__ == "__main__":
48
+ demo.launch()