nagasurendra commited on
Commit
41ce285
·
verified ·
1 Parent(s): ac47bc5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -5
app.py CHANGED
@@ -25,7 +25,7 @@ def generate_voice_response(text):
25
  return temp_file.name
26
 
27
  def calculate_total(cart):
28
- return len(cart) # Only count items, not prices
29
 
30
  def restaurant_voice_assistant(audio, state_json):
31
  global cart
@@ -83,10 +83,11 @@ def restaurant_voice_assistant(audio, state_json):
83
  response += "\nWhat would you like to add to your cart or ask about?"
84
  elif "final order" in input_text or "submit order" in input_text:
85
  if cart:
 
86
  response = "Your final order includes:\n"
87
  for item in cart:
88
  response += f"- {item}\n"
89
- response += f"\nThank you for ordering!"
90
  cart = [] # Clear cart after finalizing order
91
  state["current_items"] = [] # Clear current cycle tracking
92
  else:
@@ -101,13 +102,13 @@ with gr.Blocks() as demo:
101
  state = gr.State(value=json.dumps({}))
102
 
103
  with gr.Row():
104
- user_audio = gr.Audio(type="filepath", label="Your Voice Input")
105
- output_text = gr.Textbox(label="Response Text")
106
 
107
  with gr.Row():
108
  voice_output = gr.Audio(label="Response Audio", autoplay=True)
109
 
110
  # Automatically process audio when recording stops
111
- user_audio.change(restaurant_voice_assistant, inputs=[user_audio, state], outputs=[output_text, voice_output, state])
112
 
113
  demo.launch()
 
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
 
83
  response += "\nWhat would you like to add to your cart or ask about?"
84
  elif "final order" in input_text or "submit order" in input_text:
85
  if cart:
86
+ total = calculate_total(cart)
87
  response = "Your final order includes:\n"
88
  for item in cart:
89
  response += f"- {item}\n"
90
+ response += f"\nTotal amount: ${total:.2f}.\nThank you for ordering!"
91
  cart = [] # Clear cart after finalizing order
92
  state["current_items"] = [] # Clear current cycle tracking
93
  else:
 
102
  state = gr.State(value=json.dumps({}))
103
 
104
  with gr.Row():
105
+ record_button = gr.Audio(source="microphone", type="filepath", label="Speak Now")
106
+ output_text = gr.Textbox(label="Response Text", interactive=False)
107
 
108
  with gr.Row():
109
  voice_output = gr.Audio(label="Response Audio", autoplay=True)
110
 
111
  # Automatically process audio when recording stops
112
+ record_button.change(restaurant_voice_assistant, inputs=[record_button, state], outputs=[output_text, voice_output, state])
113
 
114
  demo.launch()