Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,11 +1,6 @@
|
|
1 |
import gradio as gr
|
2 |
-
import json
|
3 |
-
from flask import Flask, render_template
|
4 |
|
5 |
-
#
|
6 |
-
app = Flask(__name__)
|
7 |
-
|
8 |
-
# Food database (same as you provided)
|
9 |
FOOD_DATABASE = {
|
10 |
"veg": {
|
11 |
"paneer": {
|
@@ -69,7 +64,7 @@ def process_message(message, history):
|
|
69 |
if chat_state.step == "initial":
|
70 |
if "yes" in message.lower() or "yeah" in message.lower():
|
71 |
chat_state.step = "category"
|
72 |
-
return "Great! Please select your preferred category: Vegetarian, Non-Vegetarian
|
73 |
return "I'm here to help you customize your food. Would you like to proceed? (Yes/No)"
|
74 |
|
75 |
elif chat_state.step == "category":
|
@@ -77,10 +72,10 @@ def process_message(message, history):
|
|
77 |
chat_state.step = "ingredient"
|
78 |
|
79 |
if "vegetarian" in message.lower():
|
80 |
-
return f"
|
81 |
elif "non-vegetarian" in message.lower():
|
82 |
-
return f"Great
|
83 |
-
return "Please select either Vegetarian, Non-Vegetarian
|
84 |
|
85 |
elif chat_state.step == "ingredient":
|
86 |
chat_state.ingredient = message.lower()
|
@@ -99,14 +94,13 @@ def process_message(message, history):
|
|
99 |
response += f"\n• {item['name']} ({item['calories']} cal, {item['protein']}g protein)\n {item['description']}"
|
100 |
chat_state.step = "initial" # Reset for new conversation
|
101 |
return response
|
102 |
-
except:
|
103 |
chat_state.step = "initial" # Reset for new conversation
|
104 |
-
return f"I'
|
105 |
-
|
106 |
-
return "I'm not sure how to help with that. Would you like to start over? (Yes/No)"
|
107 |
|
108 |
-
|
109 |
-
|
|
|
110 |
with gr.Blocks() as demo:
|
111 |
chatbot = gr.Chatbot([])
|
112 |
msg = gr.Textbox(show_label=False, placeholder="Enter text and press enter")
|
@@ -120,24 +114,13 @@ def gradio_interface():
|
|
120 |
bot_message = process_message(user_message, history)
|
121 |
history[-1][1] = bot_message
|
122 |
return history
|
123 |
-
|
124 |
-
msg.submit(user, [msg, chatbot], [msg, chatbot]).then(
|
125 |
-
bot, chatbot, chatbot
|
126 |
-
)
|
127 |
-
|
128 |
clear.click(lambda: None, None, chatbot)
|
129 |
|
130 |
return demo
|
131 |
|
132 |
-
|
133 |
-
def index():
|
134 |
-
return render_template("index.html")
|
135 |
-
|
136 |
-
@app.route("/chat")
|
137 |
-
def chat():
|
138 |
-
demo = gradio_interface()
|
139 |
-
demo.launch(inline=True)
|
140 |
-
return "Chatbot launched!"
|
141 |
-
|
142 |
if __name__ == "__main__":
|
143 |
-
|
|
|
|
1 |
import gradio as gr
|
|
|
|
|
2 |
|
3 |
+
# Food database (same as your provided code)
|
|
|
|
|
|
|
4 |
FOOD_DATABASE = {
|
5 |
"veg": {
|
6 |
"paneer": {
|
|
|
64 |
if chat_state.step == "initial":
|
65 |
if "yes" in message.lower() or "yeah" in message.lower():
|
66 |
chat_state.step = "category"
|
67 |
+
return "Great! Please select your preferred category: Vegetarian, Non-Vegetarian."
|
68 |
return "I'm here to help you customize your food. Would you like to proceed? (Yes/No)"
|
69 |
|
70 |
elif chat_state.step == "category":
|
|
|
72 |
chat_state.step = "ingredient"
|
73 |
|
74 |
if "vegetarian" in message.lower():
|
75 |
+
return f"Great! What main ingredient would you like? Available options: {', '.join(VEG_INGREDIENTS)}"
|
76 |
elif "non-vegetarian" in message.lower():
|
77 |
+
return f"Great! What type of meat would you prefer? Available options: {', '.join(NONVEG_TYPES)}"
|
78 |
+
return "Please select either Vegetarian, Non-Vegetarian"
|
79 |
|
80 |
elif chat_state.step == "ingredient":
|
81 |
chat_state.ingredient = message.lower()
|
|
|
94 |
response += f"\n• {item['name']} ({item['calories']} cal, {item['protein']}g protein)\n {item['description']}"
|
95 |
chat_state.step = "initial" # Reset for new conversation
|
96 |
return response
|
97 |
+
except KeyError:
|
98 |
chat_state.step = "initial" # Reset for new conversation
|
99 |
+
return f"Sorry, I don't have any dishes for this combination."
|
|
|
|
|
100 |
|
101 |
+
return "I'm not sure how to help with that. Would you like to start over?"
|
102 |
+
|
103 |
+
def create_gradio_interface():
|
104 |
with gr.Blocks() as demo:
|
105 |
chatbot = gr.Chatbot([])
|
106 |
msg = gr.Textbox(show_label=False, placeholder="Enter text and press enter")
|
|
|
114 |
bot_message = process_message(user_message, history)
|
115 |
history[-1][1] = bot_message
|
116 |
return history
|
117 |
+
|
118 |
+
msg.submit(user, [msg, chatbot], [msg, chatbot]).then(bot, chatbot, chatbot)
|
|
|
|
|
|
|
119 |
clear.click(lambda: None, None, chatbot)
|
120 |
|
121 |
return demo
|
122 |
|
123 |
+
# Launch the Gradio app
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
124 |
if __name__ == "__main__":
|
125 |
+
demo = create_gradio_interface()
|
126 |
+
demo.launch(share=True)
|