Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,55 +1,35 @@
|
|
1 |
import gradio as gr
|
2 |
-
import
|
3 |
-
|
4 |
-
from
|
5 |
|
6 |
-
#
|
7 |
-
|
8 |
-
|
|
|
9 |
|
10 |
-
|
11 |
-
|
|
|
12 |
|
13 |
-
|
14 |
-
|
15 |
-
try:
|
16 |
-
response = chatbot(user_query)
|
17 |
-
bot_reply = response[0]['generated_text']
|
18 |
-
engine.say(bot_reply)
|
19 |
-
engine.runAndWait()
|
20 |
-
return bot_reply
|
21 |
-
except Exception as e:
|
22 |
-
return f"Error: {str(e)}"
|
23 |
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
with sr.AudioFile(audio) as source:
|
29 |
-
audio_data = recognizer.record(source)
|
30 |
-
user_query = recognizer.recognize_google(audio_data)
|
31 |
-
return tts_response(user_query)
|
32 |
-
except sr.UnknownValueError:
|
33 |
-
return "Sorry, I could not understand the audio."
|
34 |
-
except sr.RequestError as e:
|
35 |
-
return f"Request error from Speech Recognition service; {e}"
|
36 |
|
37 |
# Gradio interface
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
audio_input = gr.Audio(source="microphone", type="filepath", label="Speak Now")
|
48 |
-
audio_response = gr.Textbox(label="AI Response")
|
49 |
-
audio_button = gr.Button("Submit")
|
50 |
-
audio_button.click(stt_to_tts, inputs=audio_input, outputs=audio_response)
|
51 |
-
return app
|
52 |
|
53 |
if __name__ == "__main__":
|
54 |
-
|
55 |
-
app.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
from utils.stt import speech_to_text
|
3 |
+
from utils.nlp import process_query
|
4 |
+
from utils.tts import text_to_speech
|
5 |
|
6 |
+
# Load intents and other configurations
|
7 |
+
import json
|
8 |
+
with open("intents.json", "r") as f:
|
9 |
+
intents = json.load(f)
|
10 |
|
11 |
+
def voice_agent(audio):
|
12 |
+
# Step 1: Convert speech to text
|
13 |
+
query = speech_to_text(audio)
|
14 |
|
15 |
+
# Step 2: Process the query and get a response
|
16 |
+
response = process_query(query, intents)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
+
# Step 3: Convert the response to speech
|
19 |
+
audio_response = text_to_speech(response)
|
20 |
+
|
21 |
+
return response, audio_response
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
# Gradio interface
|
24 |
+
interface = gr.Interface(
|
25 |
+
fn=voice_agent,
|
26 |
+
inputs=gr.Audio(source="microphone", type="filepath"),
|
27 |
+
outputs=[
|
28 |
+
gr.Textbox(label="Agent Response"),
|
29 |
+
gr.Audio(label="Voice Response")
|
30 |
+
],
|
31 |
+
title="Hotel Booking Voice Agent"
|
32 |
+
)
|
|
|
|
|
|
|
|
|
|
|
33 |
|
34 |
if __name__ == "__main__":
|
35 |
+
interface.launch()
|
|