Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,55 +1,55 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
from dotenv import load_dotenv
|
3 |
-
from gradio import ChatMessage
|
4 |
-
from setup import Speech_Text
|
5 |
-
from temp import Script
|
6 |
-
load_dotenv()
|
7 |
-
|
8 |
-
transcriptor = Speech_Text()
|
9 |
-
output_id = None
|
10 |
-
database_con = Script()
|
11 |
-
|
12 |
-
# Function to generate chatbot response
|
13 |
-
def generate_response(chat_history: list[ChatMessage]):
|
14 |
-
return database_con.request(chat_history)
|
15 |
-
|
16 |
-
def process(audio, input_text, chat_history: list[ChatMessage]):
|
17 |
-
|
18 |
-
if audio is not None:
|
19 |
-
transcript = transcriptor.get_transcript(audio)
|
20 |
-
chat_history.append({"role": "user", "content": transcript})
|
21 |
-
|
22 |
-
elif input_text:
|
23 |
-
chat_history.append({"role": "user", "content": input_text})
|
24 |
-
|
25 |
-
else:
|
26 |
-
response = 'Provide a query text or an audio to query.'
|
27 |
-
chat_history.append({"role": "assistant", "content": response})
|
28 |
-
audio_data = transcriptor.speech_synthesis(response)
|
29 |
-
return audio_data, chat_history
|
30 |
-
|
31 |
-
response = generate_response(chat_history)
|
32 |
-
chat_history.append({"role": "assistant", "content": response})
|
33 |
-
# audio_data = transcriptor.speech_synthesis(response)
|
34 |
-
return chat_history
|
35 |
-
|
36 |
-
# Create Gradio Blocks interface
|
37 |
-
with gr.Blocks() as demo:
|
38 |
-
|
39 |
-
with gr.Row():
|
40 |
-
chatbot = gr.Chatbot(label="Chatbot Conversation", type="messages", bubble_full_width=True, show_copy_button=True, autoscroll=True)
|
41 |
-
|
42 |
-
with gr.Row():
|
43 |
-
input_textbox = gr.Textbox(label="Input Text", placeholder="Type your message here...")
|
44 |
-
input_audio = gr.Audio(label="Input Audio", sources="microphone", type="numpy")
|
45 |
-
|
46 |
-
process_button = gr.Button("Submit Query")
|
47 |
-
|
48 |
-
process_button.click(
|
49 |
-
fn=process,
|
50 |
-
inputs=[input_audio, input_textbox, chatbot],
|
51 |
-
outputs=[chatbot]
|
52 |
-
)
|
53 |
-
|
54 |
-
if __name__ == "__main__":
|
55 |
-
demo.launch(
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from dotenv import load_dotenv
|
3 |
+
from gradio import ChatMessage
|
4 |
+
from setup import Speech_Text
|
5 |
+
from temp import Script
|
6 |
+
load_dotenv()
|
7 |
+
|
8 |
+
transcriptor = Speech_Text()
|
9 |
+
output_id = None
|
10 |
+
database_con = Script()
|
11 |
+
|
12 |
+
# Function to generate chatbot response
|
13 |
+
def generate_response(chat_history: list[ChatMessage]):
|
14 |
+
return database_con.request(chat_history)
|
15 |
+
|
16 |
+
def process(audio, input_text, chat_history: list[ChatMessage]):
|
17 |
+
|
18 |
+
if audio is not None:
|
19 |
+
transcript = transcriptor.get_transcript(audio)
|
20 |
+
chat_history.append({"role": "user", "content": transcript})
|
21 |
+
|
22 |
+
elif input_text:
|
23 |
+
chat_history.append({"role": "user", "content": input_text})
|
24 |
+
|
25 |
+
else:
|
26 |
+
response = 'Provide a query text or an audio to query.'
|
27 |
+
chat_history.append({"role": "assistant", "content": response})
|
28 |
+
audio_data = transcriptor.speech_synthesis(response)
|
29 |
+
return audio_data, chat_history
|
30 |
+
|
31 |
+
response = generate_response(chat_history)
|
32 |
+
chat_history.append({"role": "assistant", "content": response})
|
33 |
+
# audio_data = transcriptor.speech_synthesis(response)
|
34 |
+
return chat_history
|
35 |
+
|
36 |
+
# Create Gradio Blocks interface
|
37 |
+
with gr.Blocks() as demo:
|
38 |
+
|
39 |
+
with gr.Row():
|
40 |
+
chatbot = gr.Chatbot(label="Chatbot Conversation", type="messages", bubble_full_width=True, show_copy_button=True, autoscroll=True)
|
41 |
+
|
42 |
+
with gr.Row():
|
43 |
+
input_textbox = gr.Textbox(label="Input Text", placeholder="Type your message here...")
|
44 |
+
input_audio = gr.Audio(label="Input Audio", sources="microphone", type="numpy")
|
45 |
+
|
46 |
+
process_button = gr.Button("Submit Query")
|
47 |
+
|
48 |
+
process_button.click(
|
49 |
+
fn=process,
|
50 |
+
inputs=[input_audio, input_textbox, chatbot],
|
51 |
+
outputs=[chatbot]
|
52 |
+
)
|
53 |
+
|
54 |
+
if __name__ == "__main__":
|
55 |
+
demo.launch()
|