Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,39 +1,48 @@
|
|
| 1 |
-
|
| 2 |
import gradio as gr
|
| 3 |
import spaces
|
| 4 |
-
from
|
| 5 |
|
|
|
|
| 6 |
user_preferences = {
|
| 7 |
-
"diet":
|
| 8 |
-
"goal":
|
| 9 |
-
"
|
| 10 |
}
|
| 11 |
|
|
|
|
| 12 |
@spaces.GPU
|
| 13 |
-
def
|
| 14 |
-
return
|
| 15 |
|
| 16 |
-
def
|
| 17 |
user_preferences["diet"] = diet
|
| 18 |
user_preferences["goal"] = goal
|
| 19 |
-
user_preferences["
|
| 20 |
-
return
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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()
|