Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,35 +1,27 @@
|
|
1 |
import gradio as gr
|
2 |
-
|
3 |
-
from utils.nlp import process_query
|
4 |
-
from utils.tts import text_to_speech
|
5 |
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
intents = json.load(f)
|
10 |
|
11 |
-
def
|
12 |
-
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
# Gradio interface
|
24 |
-
interface = gr.Interface(
|
25 |
-
fn=voice_agent,
|
26 |
-
inputs=gr.Audio(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 |
-
|
35 |
-
interface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
import speech_recognition as sr
|
|
|
|
|
3 |
|
4 |
+
def booking_agent(input_text):
|
5 |
+
# Example placeholder for hotel booking logic
|
6 |
+
return f"Hotel booked successfully for: {input_text}"
|
|
|
7 |
|
8 |
+
def voice_booking(audio):
|
9 |
+
recognizer = sr.Recognizer()
|
10 |
+
with sr.AudioFile(audio.name) as source:
|
11 |
+
audio_data = recognizer.record(source)
|
12 |
+
try:
|
13 |
+
text = recognizer.recognize_google(audio_data)
|
14 |
+
return booking_agent(text)
|
15 |
+
except sr.UnknownValueError:
|
16 |
+
return "Sorry, could not understand the audio."
|
17 |
|
18 |
+
# Gradio Interface
|
19 |
+
iface = gr.Interface(
|
20 |
+
fn=voice_booking,
|
21 |
+
inputs=gr.inputs.Audio(),
|
22 |
+
outputs="text",
|
23 |
+
title="Hotel Booking Chatbot",
|
24 |
+
description="Use voice or text to book a hotel",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
)
|
26 |
|
27 |
+
iface.launch()
|
|