Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -64,76 +64,41 @@ def process_message(message, history):
|
|
64 |
if chat_state.step == "initial":
|
65 |
if "yes" in message.lower() or "yeah" in message.lower():
|
66 |
chat_state.step = "category"
|
67 |
-
return
|
68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
|
70 |
elif chat_state.step == "category":
|
71 |
chat_state.category = message.lower()
|
72 |
chat_state.step = "ingredient"
|
73 |
|
74 |
if "vegetarian" in message.lower():
|
75 |
-
return
|
|
|
|
|
|
|
76 |
elif "non-vegetarian" in message.lower():
|
77 |
-
return
|
78 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
79 |
|
80 |
elif chat_state.step == "ingredient":
|
81 |
chat_state.ingredient = message.lower()
|
82 |
chat_state.step = "nutrition"
|
83 |
|
84 |
-
# Check if category is vegetarian or non-vegetarian
|
85 |
if "veg" in chat_state.category:
|
86 |
-
return
|
87 |
-
|
88 |
-
|
89 |
-
return "I'm not sure how to help with that. Would you like to start over?"
|
90 |
-
|
91 |
-
elif chat_state.step == "nutrition":
|
92 |
-
nutrition = message.lower().replace(" ", "")
|
93 |
-
category = "nonveg" if "non" in chat_state.category else "veg"
|
94 |
-
ingredient = chat_state.ingredient
|
95 |
-
|
96 |
-
try:
|
97 |
-
food_items = FOOD_DATABASE[category][ingredient][nutrition]
|
98 |
-
response = f"Here are some {message} {ingredient} dishes for you:\n"
|
99 |
-
for item in food_items:
|
100 |
-
response += f"\n• {item['name']} ({item['calories']} cal, {item['protein']}g protein)\n {item['description']}"
|
101 |
-
chat_state.step = "initial" # Reset for new conversation
|
102 |
-
return response, []
|
103 |
-
except KeyError:
|
104 |
-
chat_state.step = "initial" # Reset for new conversation
|
105 |
-
return f"Sorry, I don't have any dishes for this combination.", []
|
106 |
-
|
107 |
-
return "I'm not sure how to help with that. Would you like to start over?"
|
108 |
-
|
109 |
-
def create_gradio_interface():
|
110 |
-
with gr.Blocks() as demo:
|
111 |
-
chatbot = gr.Chatbot([], type='messages') # Set the type to 'messages' to avoid warning
|
112 |
-
msg = gr.Textbox(show_label=False, placeholder="Enter text and press enter")
|
113 |
-
clear = gr.Button("Clear")
|
114 |
-
|
115 |
-
# Buttons for category selection will appear in the chat stream
|
116 |
-
def user(user_message, history):
|
117 |
-
return "", history + [[user_message, None]]
|
118 |
-
|
119 |
-
def bot(history):
|
120 |
-
user_message = history[-1][0]
|
121 |
-
bot_message, buttons = process_message(user_message, history)
|
122 |
-
history[-1][1] = bot_message
|
123 |
-
|
124 |
-
# Display buttons for category selection after the initial message
|
125 |
-
if buttons:
|
126 |
-
button_elements = [gr.Button(button) for button in buttons]
|
127 |
-
return history + [[bot_message, button_elements]]
|
128 |
-
|
129 |
-
return history
|
130 |
-
|
131 |
-
msg.submit(user, [msg, chatbot], [msg, chatbot]).then(bot, chatbot, chatbot)
|
132 |
-
clear.click(lambda: None, None, chatbot)
|
133 |
-
|
134 |
-
return demo
|
135 |
-
|
136 |
-
# Launch the Gradio app
|
137 |
-
if __name__ == "__main__":
|
138 |
-
demo = create_gradio_interface()
|
139 |
-
demo.launch(share=True)
|
|
|
64 |
if chat_state.step == "initial":
|
65 |
if "yes" in message.lower() or "yeah" in message.lower():
|
66 |
chat_state.step = "category"
|
67 |
+
return {
|
68 |
+
'role': 'bot',
|
69 |
+
'content': "Great! Please select your preferred category: Vegetarian or Non-Vegetarian."
|
70 |
+
}, ["Vegetarian", "Non-Vegetarian"]
|
71 |
+
|
72 |
+
return {
|
73 |
+
'role': 'bot',
|
74 |
+
'content': "I'm here to help you customize your food. Would you like to proceed? (Yes/No)"
|
75 |
+
}, []
|
76 |
|
77 |
elif chat_state.step == "category":
|
78 |
chat_state.category = message.lower()
|
79 |
chat_state.step = "ingredient"
|
80 |
|
81 |
if "vegetarian" in message.lower():
|
82 |
+
return {
|
83 |
+
'role': 'bot',
|
84 |
+
'content': f"Great! What main ingredient would you like? Available options: {', '.join(VEG_INGREDIENTS)}"
|
85 |
+
}, []
|
86 |
elif "non-vegetarian" in message.lower():
|
87 |
+
return {
|
88 |
+
'role': 'bot',
|
89 |
+
'content': f"Great! What type of meat would you prefer? Available options: {', '.join(NONVEG_TYPES)}"
|
90 |
+
}, []
|
91 |
+
|
92 |
+
return {
|
93 |
+
'role': 'bot',
|
94 |
+
'content': "Please select either Vegetarian or Non-Vegetarian."
|
95 |
+
}, []
|
96 |
|
97 |
elif chat_state.step == "ingredient":
|
98 |
chat_state.ingredient = message.lower()
|
99 |
chat_state.step = "nutrition"
|
100 |
|
|
|
101 |
if "veg" in chat_state.category:
|
102 |
+
return {
|
103 |
+
'role': 'bot',
|
104 |
+
'content': f"Perfect! Now, select your nutrition preference: {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|