Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,62 +1,48 @@
|
|
1 |
# app.py
|
2 |
import gradio as gr
|
3 |
import spaces
|
4 |
-
from
|
5 |
-
import os
|
6 |
-
#from PyPDF2 import PdfReader
|
7 |
-
from dotenv import load_dotenv
|
8 |
-
|
9 |
-
load_dotenv()
|
10 |
|
11 |
@spaces.GPU
|
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 |
-
def user_input(message, chat_history):
|
56 |
-
response = chat(message, chat_history, diet.value, goal.value, allergens.value)
|
57 |
-
chat_history.append((message, response))
|
58 |
-
return chat_history, ""
|
59 |
-
|
60 |
-
send.click(user_input, [msg, chatbot], [chatbot, msg])
|
61 |
-
|
62 |
-
demo.launch()
|
|
|
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()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|