dschandra commited on
Commit
16564e6
·
verified ·
1 Parent(s): 466cb38

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -10
app.py CHANGED
@@ -102,7 +102,6 @@ html_code = """
102
  });
103
 
104
  function startConversation() {
105
- // Show "Listening..." before recording
106
  status.textContent = 'Listening...';
107
  startListening();
108
  }
@@ -115,7 +114,6 @@ html_code = """
115
 
116
  mediaRecorder.ondataavailable = event => audioChunks.push(event.data);
117
  mediaRecorder.onstop = async () => {
118
- // Once the recording stops, update status to "Processing..."
119
  status.textContent = 'Processing...';
120
 
121
  const audioBlob = new Blob(audioChunks, { type: 'audio/webm' });
@@ -128,7 +126,6 @@ html_code = """
128
  response.textContent = data.response;
129
  response.style.display = 'block';
130
 
131
- // Handle Speech synthesis
132
  try {
133
  const utterance = new SpeechSynthesisUtterance(data.response);
134
  speechSynthesis.speak(utterance);
@@ -144,13 +141,12 @@ html_code = """
144
  response.textContent = "Speech output unavailable. Please check your browser.";
145
  }
146
 
147
- // Continue the conversation after a short delay
148
  if (data.response.includes("Goodbye")) {
149
  status.textContent = 'Conversation ended. Press the mic button to start again.';
150
  isConversationActive = false;
151
  } else {
152
  status.textContent = 'Listening...';
153
- setTimeout(startListening, 1000); // Continue listening
154
  }
155
  } catch (error) {
156
  response.textContent = 'Error occurred. Please try again.';
@@ -159,7 +155,7 @@ html_code = """
159
  isConversationActive = false;
160
  }
161
  };
162
- setTimeout(() => mediaRecorder.stop(), 10000); // Stop recording after 10 seconds
163
  }).catch(() => {
164
  status.textContent = 'Microphone access denied.';
165
  isConversationActive = false;
@@ -241,11 +237,12 @@ def process_command(command):
241
  global user_order
242
 
243
  command = command.lower()
 
244
  if "hello" in command or "hi" in command or "hey" in command:
245
  return (
246
  "Welcome! How can I assist you with your meal today? You can ask to see the menu or place an order."
247
  )
248
- elif "show me the menu" in command or "what's the menu" in command:
249
  return (
250
  "Here are the options: \n"
251
  "Vegetarian: Vegetable Biryani, Paneer Butter Masala, Aloo Gobi, Veg Sambar, Veg Korma\n"
@@ -255,12 +252,12 @@ def process_command(command):
255
  "Please let me know what you'd like to add to your order."
256
  )
257
  elif "add" in command:
258
- item_to_add = command.split("add")[-1].strip() # Get the item after "add"
259
  if item_to_add:
260
  user_order.append(item_to_add)
261
  return f"{item_to_add} has been added to your order. Would you like to add more items?"
262
  elif "remove" in command:
263
- item_to_remove = command.split("remove")[-1].strip() # Get the item after "remove"
264
  if item_to_remove in user_order:
265
  user_order.remove(item_to_remove)
266
  return f"{item_to_remove} has been removed from your order. Would you like to add or remove anything else?"
@@ -279,7 +276,15 @@ def process_command(command):
279
  return "You haven't added anything to your order yet. Please add some items."
280
  elif "yes" in command or "place order" in command:
281
  return "Your order has been confirmed and sent to the kitchen. Thank you for ordering!"
282
- return "Sorry, I didn't understand your request. You can ask to view your order, reset preferences, or place an order."
 
 
 
 
 
 
 
 
283
 
284
  if __name__ == "__main__":
285
  app.run(host="0.0.0.0", port=7860)
 
102
  });
103
 
104
  function startConversation() {
 
105
  status.textContent = 'Listening...';
106
  startListening();
107
  }
 
114
 
115
  mediaRecorder.ondataavailable = event => audioChunks.push(event.data);
116
  mediaRecorder.onstop = async () => {
 
117
  status.textContent = 'Processing...';
118
 
119
  const audioBlob = new Blob(audioChunks, { type: 'audio/webm' });
 
126
  response.textContent = data.response;
127
  response.style.display = 'block';
128
 
 
129
  try {
130
  const utterance = new SpeechSynthesisUtterance(data.response);
131
  speechSynthesis.speak(utterance);
 
141
  response.textContent = "Speech output unavailable. Please check your browser.";
142
  }
143
 
 
144
  if (data.response.includes("Goodbye")) {
145
  status.textContent = 'Conversation ended. Press the mic button to start again.';
146
  isConversationActive = false;
147
  } else {
148
  status.textContent = 'Listening...';
149
+ setTimeout(startListening, 1000);
150
  }
151
  } catch (error) {
152
  response.textContent = 'Error occurred. Please try again.';
 
155
  isConversationActive = false;
156
  }
157
  };
158
+ setTimeout(() => mediaRecorder.stop(), 10000);
159
  }).catch(() => {
160
  status.textContent = 'Microphone access denied.';
161
  isConversationActive = false;
 
237
  global user_order
238
 
239
  command = command.lower()
240
+
241
  if "hello" in command or "hi" in command or "hey" in command:
242
  return (
243
  "Welcome! How can I assist you with your meal today? You can ask to see the menu or place an order."
244
  )
245
+ elif "show me the menu" in command or "whats the menu" in command:
246
  return (
247
  "Here are the options: \n"
248
  "Vegetarian: Vegetable Biryani, Paneer Butter Masala, Aloo Gobi, Veg Sambar, Veg Korma\n"
 
252
  "Please let me know what you'd like to add to your order."
253
  )
254
  elif "add" in command:
255
+ item_to_add = command.split("add")[-1].strip()
256
  if item_to_add:
257
  user_order.append(item_to_add)
258
  return f"{item_to_add} has been added to your order. Would you like to add more items?"
259
  elif "remove" in command:
260
+ item_to_remove = command.split("remove")[-1].strip()
261
  if item_to_remove in user_order:
262
  user_order.remove(item_to_remove)
263
  return f"{item_to_remove} has been removed from your order. Would you like to add or remove anything else?"
 
276
  return "You haven't added anything to your order yet. Please add some items."
277
  elif "yes" in command or "place order" in command:
278
  return "Your order has been confirmed and sent to the kitchen. Thank you for ordering!"
279
+
280
+ return (
281
+ "Sorry, I didn’t understand your request. You can say things like:\n"
282
+ "- Show me the menu\n"
283
+ "- Add [item] to my order\n"
284
+ "- Remove [item] from my order\n"
285
+ "- Show my order\n"
286
+ "- Place the order"
287
+ )
288
 
289
  if __name__ == "__main__":
290
  app.run(host="0.0.0.0", port=7860)