Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,8 @@ from gtts import gTTS
|
|
3 |
import tempfile
|
4 |
import os
|
5 |
import speech_recognition as sr
|
|
|
|
|
6 |
|
7 |
# Store cart in a temporary storage
|
8 |
cart = []
|
@@ -57,11 +59,15 @@ def process_audio(audio_path):
|
|
57 |
response = "Your final order includes:\n"
|
58 |
for item in cart:
|
59 |
response += f"- {item}: ${menu_items[item]:.2f}\n"
|
60 |
-
response += f"\nTotal: ${total:.2f}
|
|
|
61 |
cart = [] # Clear cart after finalizing order
|
62 |
else:
|
63 |
response = "Your cart is empty. Would you like to order something?"
|
64 |
|
|
|
|
|
|
|
65 |
else:
|
66 |
response = "I didn’t quite catch that. Please tell me what you’d like to order."
|
67 |
|
@@ -73,19 +79,19 @@ def process_audio(audio_path):
|
|
73 |
audio_response_path = generate_voice_response(response)
|
74 |
return response, audio_response_path
|
75 |
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
def run_assistant(audio):
|
77 |
transcription, audio_response_path = process_audio(audio)
|
78 |
-
|
|
|
79 |
|
80 |
-
# Gradio Interface
|
81 |
with gr.Blocks() as demo:
|
82 |
gr.Markdown("# Voice-Activated Restaurant Assistant")
|
83 |
-
|
84 |
-
audio_input = gr.Audio(type="filepath", label="Speak Now")
|
85 |
-
text_output = gr.Textbox(label="Transcription")
|
86 |
-
audio_output = gr.Audio(label="Assistant Response")
|
87 |
-
|
88 |
-
submit_button = gr.Button("Submit")
|
89 |
-
submit_button.click(run_assistant, inputs=[audio_input], outputs=[text_output, audio_output])
|
90 |
|
91 |
-
demo.launch()
|
|
|
3 |
import tempfile
|
4 |
import os
|
5 |
import speech_recognition as sr
|
6 |
+
import threading
|
7 |
+
import time
|
8 |
|
9 |
# Store cart in a temporary storage
|
10 |
cart = []
|
|
|
59 |
response = "Your final order includes:\n"
|
60 |
for item in cart:
|
61 |
response += f"- {item}: ${menu_items[item]:.2f}\n"
|
62 |
+
response += f"\nTotal: ${total:.2f}.
|
63 |
+
Thank you for ordering!"
|
64 |
cart = [] # Clear cart after finalizing order
|
65 |
else:
|
66 |
response = "Your cart is empty. Would you like to order something?"
|
67 |
|
68 |
+
elif "stop" in input_text.lower():
|
69 |
+
response = "Stopping voice assistant."
|
70 |
+
|
71 |
else:
|
72 |
response = "I didn’t quite catch that. Please tell me what you’d like to order."
|
73 |
|
|
|
79 |
audio_response_path = generate_voice_response(response)
|
80 |
return response, audio_response_path
|
81 |
|
82 |
+
def background_listen():
|
83 |
+
while True:
|
84 |
+
print("Listening...")
|
85 |
+
time.sleep(2)
|
86 |
+
|
87 |
+
# Gradio Interface
|
88 |
def run_assistant(audio):
|
89 |
transcription, audio_response_path = process_audio(audio)
|
90 |
+
os.system(f"start {audio_response_path}") # Automatically play the response audio
|
91 |
+
return transcription
|
92 |
|
|
|
93 |
with gr.Blocks() as demo:
|
94 |
gr.Markdown("# Voice-Activated Restaurant Assistant")
|
95 |
+
audio_input = gr.Audio(type="filepath", label="Speak Now", source="microphone")
|
|
|
|
|
|
|
|
|
|
|
|
|
96 |
|
97 |
+
demo.launch()
|