eat2fit / app.py
DurgaDeepak's picture
Update app.py
2f10c42 verified
raw
history blame
1.73 kB
# app.py
import gradio as gr
import spaces
from chatbot_logic import get_bot_response
# === User Preference State ===
user_preferences = {
"diet": None,
"goal": None,
"allergies": None,
}
# === GPU Eligibility Decorator ===
@spaces.GPU
def dummy_gpu_task():
return "Triggered GPU on startup."
def set_preferences(diet, goal, allergies):
user_preferences["diet"] = diet
user_preferences["goal"] = goal
user_preferences["allergies"] = allergies
return "Preferences updated. You can start chatting now!"
def chat_interface(user_input, history):
# You can optionally use preferences in prompt formatting later
response = get_bot_response(user_input)
history.append((user_input, response))
return "", history
with gr.Blocks(title="AI Meal Plan Assistant") as demo:
gr.Markdown("""
# 🍽️ Smart Meal Plan Chatbot
Ask me anything about meal plans, nutrition, or recipes from the PDFs!
""")
with gr.Accordion("Set Your Preferences (Optional)", open=True):
with gr.Row():
diet = gr.Radio(label="Diet Type", choices=["None", "Vegan", "Vegetarian", "Keto", "Low-Carb"], value="None")
goal = gr.Radio(label="Goal", choices=["None", "Weight Loss", "Muscle Gain", "Diabetic Friendly"], value="None")
allergies = gr.Textbox(label="Allergies (comma-separated)", placeholder="e.g., peanuts, gluten")
update_btn = gr.Button("Update Preferences")
output = gr.Textbox(label="Status")
update_btn.click(fn=set_preferences, inputs=[diet, goal, allergies], outputs=output)
chatbot = gr.ChatInterface(chat_interface, title="Meal Planner Chatbot")
if __name__ == "__main__":
demo.launch()