Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -16,7 +16,7 @@ menu_preferences = None # Tracks the current menu preference
|
|
| 16 |
section_preferences = None # Tracks the current section preference
|
| 17 |
default_menu_preferences = "all" # To reset menu preferences
|
| 18 |
default_sections = {
|
| 19 |
-
"
|
| 20 |
"starters": ["samosa", "onion pakoda", "chilli gobi", "chicken manchurian", "veg manchurian"],
|
| 21 |
"curries": ["paneer butter", "chicken curry", "fish curry", "chilli chicken"],
|
| 22 |
"desserts": ["gulab jamun", "ice cream"],
|
|
@@ -113,6 +113,7 @@ def preprocess_command(command):
|
|
| 113 |
- Normalize user input.
|
| 114 |
"""
|
| 115 |
return command.strip().lower()
|
|
|
|
| 116 |
def process_command(command):
|
| 117 |
"""
|
| 118 |
Process the user command based on the current menu and cart.
|
|
@@ -123,30 +124,33 @@ def process_command(command):
|
|
| 123 |
if menu_preferences is None:
|
| 124 |
if "vegetarian" in command:
|
| 125 |
menu_preferences = "vegetarian"
|
| 126 |
-
return "You have chosen the Vegetarian menu. Which section would you like? (
|
| 127 |
elif "non-vegetarian" in command:
|
| 128 |
menu_preferences = "non-vegetarian"
|
| 129 |
-
return "You have chosen the Non-Vegetarian menu. Which section would you like? (
|
| 130 |
elif "all" in command:
|
| 131 |
menu_preferences = "all"
|
| 132 |
-
return "You have chosen the complete menu. Which section would you like? (
|
| 133 |
else:
|
| 134 |
return "Please specify your preference: Vegetarian, Non-Vegetarian, or All."
|
| 135 |
|
| 136 |
-
# Handle section preferences
|
| 137 |
-
for section in default_sections.keys():
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
|
|
|
|
|
|
| 142 |
|
| 143 |
-
# Handle item addition
|
| 144 |
-
if
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
|
|
|
| 148 |
quantity = extract_quantity(command)
|
| 149 |
-
if quantity:
|
| 150 |
for cart_item in cart:
|
| 151 |
if cart_item[0] == item:
|
| 152 |
cart_item[2] += quantity
|
|
@@ -156,8 +160,8 @@ def process_command(command):
|
|
| 156 |
cart_summary = ", ".join([f"{i[0]} x{i[2]} (₹{i[1] * i[2]})" for i in cart])
|
| 157 |
return f"Added {quantity} x {item} to your cart. Current cart: {cart_summary}. Would you like to choose another section or finalize your order?"
|
| 158 |
else:
|
| 159 |
-
return "Please specify a quantity between 1 and 10."
|
| 160 |
-
|
| 161 |
# Handle remove command
|
| 162 |
if "remove" in command:
|
| 163 |
for item in cart:
|
|
@@ -198,9 +202,6 @@ def extract_quantity(command):
|
|
| 198 |
|
| 199 |
return None
|
| 200 |
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
html_code = """
|
| 205 |
<!DOCTYPE html>
|
| 206 |
<html lang="en">
|
|
|
|
| 16 |
section_preferences = None # Tracks the current section preference
|
| 17 |
default_menu_preferences = "all" # To reset menu preferences
|
| 18 |
default_sections = {
|
| 19 |
+
"biryanis": ["veg biryani", "paneer biryani", "chicken biryani", "mutton biryani"],
|
| 20 |
"starters": ["samosa", "onion pakoda", "chilli gobi", "chicken manchurian", "veg manchurian"],
|
| 21 |
"curries": ["paneer butter", "chicken curry", "fish curry", "chilli chicken"],
|
| 22 |
"desserts": ["gulab jamun", "ice cream"],
|
|
|
|
| 113 |
- Normalize user input.
|
| 114 |
"""
|
| 115 |
return command.strip().lower()
|
| 116 |
+
|
| 117 |
def process_command(command):
|
| 118 |
"""
|
| 119 |
Process the user command based on the current menu and cart.
|
|
|
|
| 124 |
if menu_preferences is None:
|
| 125 |
if "vegetarian" in command:
|
| 126 |
menu_preferences = "vegetarian"
|
| 127 |
+
return "You have chosen the Vegetarian menu. Which section would you like? (biryanis, starters, curries, desserts, soft drinks)"
|
| 128 |
elif "non-vegetarian" in command:
|
| 129 |
menu_preferences = "non-vegetarian"
|
| 130 |
+
return "You have chosen the Non-Vegetarian menu. Which section would you like? (biryanis, starters, curries, desserts, soft drinks)"
|
| 131 |
elif "all" in command:
|
| 132 |
menu_preferences = "all"
|
| 133 |
+
return "You have chosen the complete menu. Which section would you like? (biryanis, starters, curries, desserts, soft drinks)"
|
| 134 |
else:
|
| 135 |
return "Please specify your preference: Vegetarian, Non-Vegetarian, or All."
|
| 136 |
|
| 137 |
+
# Handle section preferences
|
| 138 |
+
if section_preferences is None or any(section in command for section in default_sections.keys()):
|
| 139 |
+
for section in default_sections.keys():
|
| 140 |
+
if section in command:
|
| 141 |
+
section_preferences = section
|
| 142 |
+
available_items = [item for item in default_sections[section] if item in menus[menu_preferences]]
|
| 143 |
+
return f"Here are the items in {section}: {', '.join(available_items)}. Say the item name to add to the cart."
|
| 144 |
+
return "Please specify a section: biryanis, starters, curries, desserts, or soft drinks."
|
| 145 |
|
| 146 |
+
# Handle item addition
|
| 147 |
+
available_items = [item for item in default_sections[section_preferences] if item in menus[menu_preferences]]
|
| 148 |
+
for item in available_items:
|
| 149 |
+
if item in command:
|
| 150 |
+
# Handle plural forms and alternate endings (e.g., "biryanis" or "paneer biryani")
|
| 151 |
+
if "biryanis" in command or item.endswith("i") or item.endswith("e"):
|
| 152 |
quantity = extract_quantity(command)
|
| 153 |
+
if quantity is not None:
|
| 154 |
for cart_item in cart:
|
| 155 |
if cart_item[0] == item:
|
| 156 |
cart_item[2] += quantity
|
|
|
|
| 160 |
cart_summary = ", ".join([f"{i[0]} x{i[2]} (₹{i[1] * i[2]})" for i in cart])
|
| 161 |
return f"Added {quantity} x {item} to your cart. Current cart: {cart_summary}. Would you like to choose another section or finalize your order?"
|
| 162 |
else:
|
| 163 |
+
return "Please specify a quantity between 1 and 10. Say 'Add 2' or 'Add three' followed by the item name."
|
| 164 |
+
|
| 165 |
# Handle remove command
|
| 166 |
if "remove" in command:
|
| 167 |
for item in cart:
|
|
|
|
| 202 |
|
| 203 |
return None
|
| 204 |
|
|
|
|
|
|
|
|
|
|
| 205 |
html_code = """
|
| 206 |
<!DOCTYPE html>
|
| 207 |
<html lang="en">
|