prasanth345 commited on
Commit
423ebdd
·
verified ·
1 Parent(s): 7e97c4c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -29
app.py CHANGED
@@ -1,35 +1,27 @@
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(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()
 
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()