geethareddy commited on
Commit
80ca45f
·
verified ·
1 Parent(s): 60734ee

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -63
app.py CHANGED
@@ -149,7 +149,9 @@ def process_command(command):
149
  if section in command:
150
  section_preferences = section
151
  items_text = ', '.join(default_sections[section_preferences])
152
- return f"Here are the items in the {section_preferences} section: {items_text}. Please choose an item."
 
 
153
 
154
  closest_match = process.extractOne(command, sections, scorer=fuzz.partial_ratio)
155
  if closest_match and closest_match[1] > 75:
@@ -256,65 +258,4 @@ html_code = """
256
  let isConversationActive = false;
257
  micButton.addEventListener('click', () => {
258
  if (!isConversationActive) {
259
- isConversationActive = true;
260
- startConversation();
261
- }
262
- });
263
- function startConversation() {
264
- const utterance = new SpeechSynthesisUtterance('Hello, welcome to Biryani Hub! We have the following categories: Biryanis, Starters, Curries, Desserts, Soft Drinks. Please choose a category.');
265
- speechSynthesis.speak(utterance);
266
- utterance.onend = () => {
267
- status.textContent = 'Listening...';
268
- startListening();
269
- };
270
- }
271
- function startListening() {
272
- navigator.mediaDevices.getUserMedia({ audio: true }).then(stream => {
273
- mediaRecorder = new MediaRecorder(stream, { mimeType: 'audio/webm;codecs=opus' });
274
- mediaRecorder.start();
275
- audioChunks = [];
276
- mediaRecorder.ondataavailable = event => audioChunks.push(event.data);
277
- mediaRecorder.onstop = async () => {
278
- const audioBlob = new Blob(audioChunks, { type: 'audio/webm' });
279
- const formData = new FormData();
280
- formData.append('audio', audioBlob);
281
- status.textContent = 'Processing...';
282
- try {
283
- const result = await fetch('/process-audio', { method: 'POST', body: formData });
284
- const data = await result.json();
285
- response.textContent = 'You said: ' + data.response; // Display user text
286
- response.style.display = 'block';
287
- const utterance = new SpeechSynthesisUtterance(data.response);
288
- speechSynthesis.speak(utterance);
289
- utterance.onend = () => {
290
- console.log("Speech synthesis completed.");
291
- status.textContent = 'Listening...';
292
- setTimeout(() => {
293
- startListening();
294
- }, 100);
295
- };
296
- utterance.onerror = (e) => {
297
- console.error("Speech synthesis error:", e.error);
298
- status.textContent = 'Error with speech output.';
299
- isConversationActive = false;
300
- };
301
- } catch (error) {
302
- response.textContent = 'Sorry, I could not understand. Please try again.';
303
- response.style.display = 'block';
304
- status.textContent = 'Press the mic button to restart the conversation.';
305
- isConversationActive = false;
306
- }
307
- };
308
- setTimeout(() => mediaRecorder.stop(), 5000);
309
- }).catch(() => {
310
- status.textContent = 'Microphone access denied.';
311
- isConversationActive = false;
312
- });
313
- }
314
- </script>
315
- </body>
316
- </html>
317
- """
318
-
319
- if __name__ == "__main__":
320
- app.run(host="0.0.0.0", port=7860)
 
149
  if section in command:
150
  section_preferences = section
151
  items_text = ', '.join(default_sections[section_preferences])
152
+ response_text = f"Here are the items in the {section_preferences} section: {items_text}. Please choose an item."
153
+ # Speak the response
154
+ return response_text
155
 
156
  closest_match = process.extractOne(command, sections, scorer=fuzz.partial_ratio)
157
  if closest_match and closest_match[1] > 75:
 
258
  let isConversationActive = false;
259
  micButton.addEventListener('click', () => {
260
  if (!isConversationActive) {
261
+ isConversationA