File size: 1,977 Bytes
2f10c42
901777e
05f1709
2f10c42
0ada0e7
 
 
6ce8ea0
 
 
 
0ada0e7
789f39d
2f10c42
6eae2d9
2f10c42
 
 
6eae2d9
 
2f10c42
05f1709
2f10c42
 
6eae2d9
2f10c42
6eae2d9
 
2f10c42
 
 
 
01d2e68
 
 
 
 
 
bc4b8ef
2f10c42
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# app.py
import gradio as gr
import spaces
from chatbot_logic import get_bot_response
from knowledge_base import load_and_chunk_pdfs, create_vectorstore
import os

# if not os.path.exists("chroma/index"):
#     print("Vectorstore missing or empty — running ingestion.")
#     chunks = load_and_chunk_pdfs("meal_plans")
#     create_vectorstore(chunks)


# === 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):
    try:
        response = get_bot_response(user_input)
        return response
    except Exception as e:
        return f"❌ Failed to process: {str(e)}"



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()