nagasurendra commited on
Commit
be9516d
·
verified ·
1 Parent(s): 44e324b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -29
app.py CHANGED
@@ -115,17 +115,16 @@ def preprocess_command(command):
115
  return command
116
 
117
  def process_command(command):
118
- """
119
- Process the user command based on the current menu and cart.
120
- """
121
  global cart, menu_preferences, section_preferences
122
 
 
 
 
123
  # Handle menu preferences
124
  if menu_preferences is None:
125
- # Use fuzzy matching for preference selection
126
  preferences = ["non-vegetarian", "vegetarian", "all"]
127
  closest_match = process.extractOne(command, preferences, scorer=fuzz.partial_ratio)
128
- if closest_match and closest_match[1] > 70: # Match threshold
129
  menu_preferences = closest_match[0]
130
  if menu_preferences == "non-vegetarian":
131
  return "You have chosen the Non-Vegetarian menu. Which section would you like? (biryanis, starters, curries, desserts, soft drinks)"
@@ -144,34 +143,29 @@ def process_command(command):
144
  return f"Here are the items in {section}: {', '.join(available_items)}. Say the item name to add to the cart."
145
  return "Please specify a section: biryanis, starters, curries, desserts, or soft drinks."
146
 
147
- # Other logic continues...
148
-
149
-
150
  # Handle item addition
151
  available_items = [item for item in default_sections[section_preferences] if item in menus[menu_preferences]]
152
- closest_match = process.extractOne(command, available_items, scorer=fuzz.partial_ratio)
153
- if closest_match and closest_match[1] > 60: # Match threshold
154
- item = closest_match[0]
155
- quantity = extract_quantity(command)
156
- if quantity is not None:
157
- for cart_item in cart:
158
- if cart_item[0] == item:
159
- cart_item[2] += quantity
160
- break
161
- else:
162
- cart.append([item, prices[item], quantity])
163
- cart_summary = ", ".join([f"{i[0]} x{i[2]} (₹{i[1] * i[2]})" for i in cart])
164
- return f"Added {quantity} x {item} to your cart. Current cart: {cart_summary}. Would you like to choose another section or finalize your order?"
165
- return "Please specify a quantity between 1 and 10. Say 'Add 2' or 'Add three' followed by the item name."
166
 
167
  # Handle remove command
168
  if "remove" in command:
169
- closest_match = process.extractOne(command, [item[0] for item in cart], scorer=fuzz.partial_ratio)
170
- if closest_match and closest_match[1] > 60: # Match threshold
171
- item = closest_match[0]
172
- cart = [i for i in cart if i[0] != item]
173
- cart_summary = ", ".join([f"{i[0]} x{i[2]} (₹{i[1] * i[2]})" for i in cart])
174
- return f"Removed {item} from your cart. Current cart: {cart_summary}."
175
  return "The item you are trying to remove is not in your cart."
176
 
177
  # Handle final order
@@ -179,9 +173,13 @@ def process_command(command):
179
  if cart:
180
  total = sum(i[1] * i[2] for i in cart)
181
  order_summary = ", ".join([f"{i[0]} x{i[2]} (₹{i[1] * i[2]})" for i in cart])
182
- return f"Your final order is: {order_summary}. Total bill: ₹{total}. Thank you for ordering!"
 
 
 
183
  return "Your cart is empty. Please add items to your cart first."
184
 
 
185
  return "Sorry, I couldn't understand that. Please try again."
186
  def extract_quantity(command):
187
  """
 
115
  return command
116
 
117
  def process_command(command):
 
 
 
118
  global cart, menu_preferences, section_preferences
119
 
120
+ # Log command and current preferences for debugging
121
+ logging.info(f"Command: {command}, Menu Preferences: {menu_preferences}, Section Preferences: {section_preferences}")
122
+
123
  # Handle menu preferences
124
  if menu_preferences is None:
 
125
  preferences = ["non-vegetarian", "vegetarian", "all"]
126
  closest_match = process.extractOne(command, preferences, scorer=fuzz.partial_ratio)
127
+ if closest_match and closest_match[1] > 70:
128
  menu_preferences = closest_match[0]
129
  if menu_preferences == "non-vegetarian":
130
  return "You have chosen the Non-Vegetarian menu. Which section would you like? (biryanis, starters, curries, desserts, soft drinks)"
 
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
+ quantity = extract_quantity(command)
151
+ if quantity is not None:
152
+ for cart_item in cart:
153
+ if cart_item[0] == item:
154
+ cart_item[2] += quantity
155
+ break
156
+ else:
157
+ cart.append([item, prices[item], quantity])
158
+ cart_summary = ", ".join([f"{i[0]} x{i[2]} (₹{i[1] * i[2]})" for i in cart])
159
+ return f"Added {quantity} x {item} to your cart. Current cart: {cart_summary}. Would you like to choose another section or finalize your order?"
160
+ return "Please specify a quantity between 1 and 10. Say 'Add 2' or 'Add three' followed by the item name."
 
161
 
162
  # Handle remove command
163
  if "remove" in command:
164
+ for item in cart:
165
+ if item[0] in command:
166
+ cart.remove(item)
167
+ cart_summary = ", ".join([f"{i[0]} x{i[2]} (₹{i[1] * i[2]})" for i in cart])
168
+ return f"Removed {item[0]} from your cart. Current cart: {cart_summary}."
 
169
  return "The item you are trying to remove is not in your cart."
170
 
171
  # Handle final order
 
173
  if cart:
174
  total = sum(i[1] * i[2] for i in cart)
175
  order_summary = ", ".join([f"{i[0]} x{i[2]} (₹{i[1] * i[2]})" for i in cart])
176
+ cart.clear()
177
+ menu_preferences = None
178
+ section_preferences = None
179
+ return f"Your final order is: {order_summary}. Total bill: ₹{total}. Thank you for ordering! You can start a new order by specifying your preference."
180
  return "Your cart is empty. Please add items to your cart first."
181
 
182
+
183
  return "Sorry, I couldn't understand that. Please try again."
184
  def extract_quantity(command):
185
  """