Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
import gradio as gr
|
2 |
|
3 |
-
# Food
|
4 |
FOOD_DATABASE = {
|
5 |
"veg": {
|
6 |
"paneer": {
|
@@ -48,8 +48,8 @@ FOOD_DATABASE = {
|
|
48 |
}
|
49 |
}
|
50 |
|
51 |
-
VEG_INGREDIENTS = ["Paneer", "Mushroom", "Aloo"
|
52 |
-
NONVEG_TYPES = ["Chicken", "Fish", "Mutton"
|
53 |
NUTRITION_OPTIONS = ["Low Calorie", "High Protein", "Low Carb", "Balanced", "Gluten Free"]
|
54 |
|
55 |
class ChatState:
|
@@ -66,7 +66,7 @@ def process_message(message, history):
|
|
66 |
if chat_state.step == "initial":
|
67 |
if "yes" in message.lower() or "yeah" in message.lower():
|
68 |
chat_state.step = "category"
|
69 |
-
return "Great! Please select your preferred category:
|
70 |
return "I'm here to help you customize your food. Would you like to proceed? (Yes/No)"
|
71 |
|
72 |
# Step 2: Category selection
|
@@ -74,17 +74,30 @@ def process_message(message, history):
|
|
74 |
chat_state.category = message.lower()
|
75 |
chat_state.step = "ingredient"
|
76 |
|
77 |
-
if "
|
78 |
return f"Great! What main ingredient would you like? Available options: {', '.join(VEG_INGREDIENTS)}"
|
79 |
-
elif "
|
80 |
return f"Great! What type of meat would you prefer? Available options: {', '.join(NONVEG_TYPES)}"
|
81 |
return "Please select either Vegetarian or Non-Vegetarian."
|
82 |
|
83 |
# Step 3: Ingredient selection
|
84 |
elif chat_state.step == "ingredient":
|
85 |
chat_state.ingredient = message.lower().strip() # Ensure no extra spaces or case issues
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
chat_state.step = "nutrition"
|
87 |
-
return f"
|
88 |
|
89 |
# Step 4: Nutrition preference
|
90 |
elif chat_state.step == "nutrition":
|
@@ -94,14 +107,6 @@ def process_message(message, history):
|
|
94 |
category = "nonveg" if "non" in chat_state.category else "veg"
|
95 |
ingredient = chat_state.ingredient
|
96 |
|
97 |
-
# Debugging: Print the state before fetching food items
|
98 |
-
print(f"Category: {category}, Ingredient: {ingredient}, Nutrition: {nutrition}")
|
99 |
-
|
100 |
-
# Check if the ingredient exists in the database for the selected category
|
101 |
-
if ingredient not in FOOD_DATABASE[category]:
|
102 |
-
chat_state.step = "initial" # Reset for new conversation
|
103 |
-
return f"Sorry, I don't have any data for {ingredient}. Please select another ingredient."
|
104 |
-
|
105 |
# Try to fetch the food items from the correct category, ingredient, and nutrition preference
|
106 |
try:
|
107 |
# Access food items based on category, ingredient, and nutrition preference
|
@@ -120,29 +125,3 @@ def process_message(message, history):
|
|
120 |
return f"Sorry, I don't have any dishes for this combination."
|
121 |
|
122 |
return "I'm not sure how to help with that. Would you like to start over?"
|
123 |
-
|
124 |
-
# Gradio interface for the chatbot
|
125 |
-
def create_gradio_interface():
|
126 |
-
with gr.Blocks() as demo:
|
127 |
-
chatbot = gr.Chatbot([])
|
128 |
-
msg = gr.Textbox(show_label=False, placeholder="Enter text and press enter")
|
129 |
-
clear = gr.Button("Clear")
|
130 |
-
|
131 |
-
def user(user_message, history):
|
132 |
-
return "", history + [[user_message, None]]
|
133 |
-
|
134 |
-
def bot(history):
|
135 |
-
user_message = history[-1][0]
|
136 |
-
bot_message = process_message(user_message, history)
|
137 |
-
history[-1][1] = bot_message
|
138 |
-
return history
|
139 |
-
|
140 |
-
msg.submit(user, [msg, chatbot], [msg, chatbot]).then(bot, chatbot, chatbot)
|
141 |
-
clear.click(lambda: None, None, chatbot)
|
142 |
-
|
143 |
-
return demo
|
144 |
-
|
145 |
-
# Launch the Gradio app
|
146 |
-
if __name__ == "__main__":
|
147 |
-
demo = create_gradio_interface()
|
148 |
-
demo.launch(share=True)
|
|
|
1 |
import gradio as gr
|
2 |
|
3 |
+
# Corrected Food Database with consistent food item names
|
4 |
FOOD_DATABASE = {
|
5 |
"veg": {
|
6 |
"paneer": {
|
|
|
48 |
}
|
49 |
}
|
50 |
|
51 |
+
VEG_INGREDIENTS = ["Paneer", "Mushroom", "Aloo"]
|
52 |
+
NONVEG_TYPES = ["Chicken", "Fish", "Mutton"]
|
53 |
NUTRITION_OPTIONS = ["Low Calorie", "High Protein", "Low Carb", "Balanced", "Gluten Free"]
|
54 |
|
55 |
class ChatState:
|
|
|
66 |
if chat_state.step == "initial":
|
67 |
if "yes" in message.lower() or "yeah" in message.lower():
|
68 |
chat_state.step = "category"
|
69 |
+
return "Great! Please select your preferred category: Veg, nonveg."
|
70 |
return "I'm here to help you customize your food. Would you like to proceed? (Yes/No)"
|
71 |
|
72 |
# Step 2: Category selection
|
|
|
74 |
chat_state.category = message.lower()
|
75 |
chat_state.step = "ingredient"
|
76 |
|
77 |
+
if "veg" in message.lower():
|
78 |
return f"Great! What main ingredient would you like? Available options: {', '.join(VEG_INGREDIENTS)}"
|
79 |
+
elif "nonveg" in message.lower():
|
80 |
return f"Great! What type of meat would you prefer? Available options: {', '.join(NONVEG_TYPES)}"
|
81 |
return "Please select either Vegetarian or Non-Vegetarian."
|
82 |
|
83 |
# Step 3: Ingredient selection
|
84 |
elif chat_state.step == "ingredient":
|
85 |
chat_state.ingredient = message.lower().strip() # Ensure no extra spaces or case issues
|
86 |
+
# Get the list of available food items for this ingredient
|
87 |
+
category = "nonveg" if "non" in chat_state.category else "veg"
|
88 |
+
|
89 |
+
# Check if the ingredient exists in the food database
|
90 |
+
if chat_state.ingredient not in FOOD_DATABASE[category]:
|
91 |
+
chat_state.step = "initial" # Reset for new conversation
|
92 |
+
return f"Sorry, I don't have any data for {message}. Please select another ingredient."
|
93 |
+
|
94 |
+
# List available food items based on ingredient
|
95 |
+
food_items = FOOD_DATABASE[category][chat_state.ingredient]
|
96 |
+
food_item_names = [item['name'] for nutrition in food_items for item in food_items[nutrition]]
|
97 |
+
|
98 |
+
# Show available food items
|
99 |
chat_state.step = "nutrition"
|
100 |
+
return f"Great! Here are the available food items for {message}:\n{', '.join(food_item_names)}\nNow, select your nutrition preference: {', '.join(NUTRITION_OPTIONS)}"
|
101 |
|
102 |
# Step 4: Nutrition preference
|
103 |
elif chat_state.step == "nutrition":
|
|
|
107 |
category = "nonveg" if "non" in chat_state.category else "veg"
|
108 |
ingredient = chat_state.ingredient
|
109 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
110 |
# Try to fetch the food items from the correct category, ingredient, and nutrition preference
|
111 |
try:
|
112 |
# Access food items based on category, ingredient, and nutrition preference
|
|
|
125 |
return f"Sorry, I don't have any dishes for this combination."
|
126 |
|
127 |
return "I'm not sure how to help with that. Would you like to start over?"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|