nagasurendra commited on
Commit
4c9e0d1
·
verified ·
1 Parent(s): a8fce64

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -4
app.py CHANGED
@@ -24,6 +24,9 @@ def generate_voice_response(text):
24
  tts.save(temp_file.name)
25
  return temp_file.name
26
 
 
 
 
27
  def restaurant_voice_assistant(audio, state_json):
28
  global cart
29
  state = json.loads(state_json) if state_json else {}
@@ -53,19 +56,24 @@ def restaurant_voice_assistant(audio, state_json):
53
  for item in menu_items:
54
  if item.lower() in input_text.lower():
55
  cart.append(item)
56
- response = f"{item} has been added to your cart. Would you like to add anything else?"
 
 
 
 
57
  break
58
  elif "menu" in input_text.lower():
59
  response = "Here is our menu again:\n"
60
  for item, price in menu_items.items():
61
  response += f"{item}: ${price:.2f}\n"
62
  response += "\nWhat would you like to add to your cart?"
63
- elif "final order" in input_text.lower():
64
  if cart:
 
65
  response = "Your final order includes:\n"
66
  for item in cart:
67
- response += f"- {item}\n"
68
- response += "\nThank you for ordering!"
69
  cart = [] # Clear cart after finalizing order
70
  else:
71
  response = "Your cart is empty. Would you like to order something?"
 
24
  tts.save(temp_file.name)
25
  return temp_file.name
26
 
27
+ def calculate_total(cart):
28
+ return sum(menu_items[item] for item in cart)
29
+
30
  def restaurant_voice_assistant(audio, state_json):
31
  global cart
32
  state = json.loads(state_json) if state_json else {}
 
56
  for item in menu_items:
57
  if item.lower() in input_text.lower():
58
  cart.append(item)
59
+ total = calculate_total(cart)
60
+ response = f"{item} has been added to your cart. Your current cart includes:\n"
61
+ for cart_item in cart:
62
+ response += f"- {cart_item}: ${menu_items[cart_item]:.2f}\n"
63
+ response += f"\nTotal: ${total:.2f}. Would you like to add anything else?"
64
  break
65
  elif "menu" in input_text.lower():
66
  response = "Here is our menu again:\n"
67
  for item, price in menu_items.items():
68
  response += f"{item}: ${price:.2f}\n"
69
  response += "\nWhat would you like to add to your cart?"
70
+ elif "final order" in input_text.lower() or "submit order" in input_text.lower():
71
  if cart:
72
+ total = calculate_total(cart)
73
  response = "Your final order includes:\n"
74
  for item in cart:
75
+ response += f"- {item}: ${menu_items[item]:.2f}\n"
76
+ response += f"\nTotal: ${total:.2f}.\nThank you for ordering!"
77
  cart = [] # Clear cart after finalizing order
78
  else:
79
  response = "Your cart is empty. Would you like to order something?"