Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -64,31 +64,26 @@ 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 {"role": "bot", "content": "Great! Please select your preferred category: Vegetarian or Non-Vegetarian."}, [
|
| 68 |
|
| 69 |
-
return {"role": "bot", "content": "I'm here to help you customize your food. Would you like to proceed? (Yes/No)"}, []
|
| 70 |
|
| 71 |
elif chat_state.step == "category":
|
| 72 |
chat_state.category = message.lower()
|
| 73 |
chat_state.step = "ingredient"
|
| 74 |
|
| 75 |
if "vegetarian" in message.lower():
|
| 76 |
-
return {"role": "bot", "content": f"Great! What main ingredient would you like? Available options: {', '.join(VEG_INGREDIENTS)}"}, []
|
| 77 |
elif "non-vegetarian" in message.lower():
|
| 78 |
-
return {"role": "bot", "content": f"Great! What type of meat would you prefer? Available options: {', '.join(NONVEG_TYPES)}"}, []
|
| 79 |
|
| 80 |
-
return {"role": "bot", "content": "Please select either Vegetarian or Non-Vegetarian."}, []
|
| 81 |
|
| 82 |
elif chat_state.step == "ingredient":
|
| 83 |
chat_state.ingredient = message.lower()
|
| 84 |
chat_state.step = "nutrition"
|
| 85 |
|
| 86 |
-
|
| 87 |
-
return {"role": "bot", "content": f"Perfect! Now, select your nutrition preference: {', '.join(NUTRITION_OPTIONS)}"}, []
|
| 88 |
-
elif "nonveg" in chat_state.category:
|
| 89 |
-
return {"role": "bot", "content": f"Perfect! Now, select your nutrition preference: {', '.join(NUTRITION_OPTIONS)}"}, []
|
| 90 |
-
|
| 91 |
-
return {"role": "bot", "content": "I'm not sure how to help with that. Would you like to start over?"}, []
|
| 92 |
|
| 93 |
elif chat_state.step == "nutrition":
|
| 94 |
nutrition = message.lower().replace(" ", "")
|
|
@@ -101,12 +96,12 @@ def process_message(message, history):
|
|
| 101 |
for item in food_items:
|
| 102 |
response += f"\n• {item['name']} ({item['calories']} cal, {item['protein']}g protein)\n {item['description']}"
|
| 103 |
chat_state.step = "initial" # Reset for new conversation
|
| 104 |
-
return {"role": "bot", "content": response}, []
|
| 105 |
except KeyError:
|
| 106 |
chat_state.step = "initial" # Reset for new conversation
|
| 107 |
-
return {"role": "bot", "content": f"Sorry, I don't have any dishes for this combination."}, []
|
| 108 |
|
| 109 |
-
return {"role": "bot", "content": "I'm not sure how to help with that. Would you like to start over?"}, []
|
| 110 |
|
| 111 |
def create_gradio_interface():
|
| 112 |
with gr.Blocks() as demo:
|
|
@@ -120,12 +115,7 @@ def create_gradio_interface():
|
|
| 120 |
def bot(history):
|
| 121 |
user_message = history[-1]["content"]
|
| 122 |
bot_message, buttons = process_message(user_message, history)
|
| 123 |
-
history[-1]["content"] = bot_message["content"]
|
| 124 |
-
|
| 125 |
-
# Display buttons for category selection after the initial message
|
| 126 |
-
if buttons:
|
| 127 |
-
button_elements = [gr.Button(button) for button in buttons]
|
| 128 |
-
return history + [{"role": "bot", "content": bot_message["content"]}, button_elements]
|
| 129 |
|
| 130 |
return history
|
| 131 |
|
|
|
|
| 64 |
if chat_state.step == "initial":
|
| 65 |
if "yes" in message.lower() or "yeah" in message.lower():
|
| 66 |
chat_state.step = "category"
|
| 67 |
+
return [{"role": "bot", "content": "Great! Please select your preferred category: Vegetarian or Non-Vegetarian."}], []
|
| 68 |
|
| 69 |
+
return [{"role": "bot", "content": "I'm here to help you customize your food. Would you like to proceed? (Yes/No)"}], []
|
| 70 |
|
| 71 |
elif chat_state.step == "category":
|
| 72 |
chat_state.category = message.lower()
|
| 73 |
chat_state.step = "ingredient"
|
| 74 |
|
| 75 |
if "vegetarian" in message.lower():
|
| 76 |
+
return [{"role": "bot", "content": f"Great! What main ingredient would you like? Available options: {', '.join(VEG_INGREDIENTS)}"}], []
|
| 77 |
elif "non-vegetarian" in message.lower():
|
| 78 |
+
return [{"role": "bot", "content": f"Great! What type of meat would you prefer? Available options: {', '.join(NONVEG_TYPES)}"}], []
|
| 79 |
|
| 80 |
+
return [{"role": "bot", "content": "Please select either Vegetarian or Non-Vegetarian."}], []
|
| 81 |
|
| 82 |
elif chat_state.step == "ingredient":
|
| 83 |
chat_state.ingredient = message.lower()
|
| 84 |
chat_state.step = "nutrition"
|
| 85 |
|
| 86 |
+
return [{"role": "bot", "content": f"Perfect! Now, select your nutrition preference: {', '.join(NUTRITION_OPTIONS)}"}], []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
|
| 88 |
elif chat_state.step == "nutrition":
|
| 89 |
nutrition = message.lower().replace(" ", "")
|
|
|
|
| 96 |
for item in food_items:
|
| 97 |
response += f"\n• {item['name']} ({item['calories']} cal, {item['protein']}g protein)\n {item['description']}"
|
| 98 |
chat_state.step = "initial" # Reset for new conversation
|
| 99 |
+
return [{"role": "bot", "content": response}], []
|
| 100 |
except KeyError:
|
| 101 |
chat_state.step = "initial" # Reset for new conversation
|
| 102 |
+
return [{"role": "bot", "content": f"Sorry, I don't have any dishes for this combination."}], []
|
| 103 |
|
| 104 |
+
return [{"role": "bot", "content": "I'm not sure how to help with that. Would you like to start over?"}], []
|
| 105 |
|
| 106 |
def create_gradio_interface():
|
| 107 |
with gr.Blocks() as demo:
|
|
|
|
| 115 |
def bot(history):
|
| 116 |
user_message = history[-1]["content"]
|
| 117 |
bot_message, buttons = process_message(user_message, history)
|
| 118 |
+
history[-1]["content"] = bot_message[0]["content"] # Update the message content
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
|
| 120 |
return history
|
| 121 |
|