geethareddy commited on
Commit
c1d4c82
·
verified ·
1 Parent(s): 8490c51

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -21
app.py CHANGED
@@ -20,6 +20,9 @@ MENU = {
20
  "Curries": {"Butter Chicken": 200, "Dal Fry": 150},
21
  }
22
 
 
 
 
23
  # HTML Template for Frontend
24
  html_code = """
25
  <!DOCTYPE html>
@@ -128,6 +131,7 @@ def index():
128
 
129
  @app.route("/process-audio", methods=["POST"])
130
  def process_audio():
 
131
  try:
132
  audio_file = request.files.get("audio")
133
  if not audio_file:
@@ -149,7 +153,7 @@ def process_audio():
149
  audio_data = recognizer.record(source)
150
  try:
151
  command = recognizer.recognize_google(audio_data)
152
- response = process_command(command)
153
  except sr.UnknownValueError:
154
  response = "Sorry, I could not understand. Please try again."
155
 
@@ -163,28 +167,26 @@ def process_audio():
163
  os.unlink(temp_file.name)
164
  os.unlink(converted_file.name)
165
 
166
- def process_command(command):
167
- global cart
168
  command = command.lower()
169
  all_items = {item.lower(): (category, price) for category, items in MENU.items() for item, price in items.items()}
170
- categories = {category.lower(): items for category, items in MENU.items()}
171
-
172
- # Handle category-specific queries
173
- if any(category in command for category in categories.keys()):
174
- category = next((cat for cat in categories.keys() if cat in command), None)
175
- if category:
176
- items = ", ".join(categories[category].keys())
177
- return f"{category.capitalize()} has {items}. What would you like to order?"
178
-
179
- # Handle specific item addition
180
- elif any(item in command for item in all_items.keys()):
181
- item = next((item for item in all_items.keys() if item in command), None)
182
- if item:
183
- category, price = all_items[item]
184
- cart.append((item.title(), price))
185
- total = sum(item[1] for item in cart)
186
- cart_summary = ", ".join([f"{i[0]} (₹{i[1]})" for i in cart])
187
- return f"{item.title()} added to your cart for ₹{price}. Your cart: {cart_summary}. Total: ₹{total}. Do you want to order anything else?"
188
 
189
  # Handle final order
190
  elif "final order" in command or "submit" in command:
 
20
  "Curries": {"Butter Chicken": 200, "Dal Fry": 150},
21
  }
22
 
23
+ # Track ongoing suggestions for categories
24
+ suggested_category = None
25
+
26
  # HTML Template for Frontend
27
  html_code = """
28
  <!DOCTYPE html>
 
131
 
132
  @app.route("/process-audio", methods=["POST"])
133
  def process_audio():
134
+ global suggested_category
135
  try:
136
  audio_file = request.files.get("audio")
137
  if not audio_file:
 
153
  audio_data = recognizer.record(source)
154
  try:
155
  command = recognizer.recognize_google(audio_data)
156
+ response = process_command(command, suggested_category)
157
  except sr.UnknownValueError:
158
  response = "Sorry, I could not understand. Please try again."
159
 
 
167
  os.unlink(temp_file.name)
168
  os.unlink(converted_file.name)
169
 
170
+ def process_command(command, suggested_category=None):
171
+ global cart, MENU
172
  command = command.lower()
173
  all_items = {item.lower(): (category, price) for category, items in MENU.items() for item, price in items.items()}
174
+
175
+ # Handle ongoing suggestion
176
+ if suggested_category and command in [item.lower() for item in MENU[suggested_category].keys()]:
177
+ item = command.title()
178
+ price = MENU[suggested_category][item]
179
+ cart.append((item, price))
180
+ total = sum(item[1] for item in cart)
181
+ cart_summary = ", ".join([f"{i[0]} (₹{i[1]})" for i in cart])
182
+ return f"{item} added to your cart for ₹{price}. Your cart: {cart_summary}. Total: ₹{total}. Do you want to order anything else?"
183
+
184
+ # Handle category suggestion
185
+ categories = {category.lower(): category for category in MENU.keys()}
186
+ if any(cat in command for cat in categories.keys()):
187
+ suggested_category = categories[next(cat for cat in categories.keys() if cat in command)]
188
+ items = ", ".join(MENU[suggested_category].keys())
189
+ return f"{suggested_category.capitalize()} options are: {items}. Which one would you like?"
 
 
190
 
191
  # Handle final order
192
  elif "final order" in command or "submit" in command: