Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,10 +1,16 @@
|
|
1 |
"""Deploying AI Voice Chatbot Gradio App."""
|
2 |
-
|
3 |
from typing import Tuple
|
4 |
|
5 |
-
from utils import (
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
max_answer_length = 100
|
10 |
desired_language = "de"
|
@@ -12,25 +18,24 @@ response_generator_pipe = TextGenerationPipeline(max_length=max_answer_length)
|
|
12 |
|
13 |
|
14 |
def main(audio: object) -> Tuple[str, str, str, object]:
|
15 |
-
"""Calls functions for deploying
|
16 |
|
17 |
It responds both verbally and in text
|
18 |
-
by taking voice input from user.
|
19 |
|
20 |
Args:
|
21 |
-
audio (object):
|
22 |
|
23 |
Returns:
|
24 |
-
tuple containing
|
25 |
-
|
26 |
-
-
|
27 |
-
-
|
28 |
-
-
|
29 |
-
- html (object) : autoplayer for bot's speech
|
30 |
"""
|
31 |
user_speech_text = stt(audio, desired_language)
|
32 |
-
|
33 |
-
bot_response_en = response_generator_pipe(
|
34 |
bot_response_de = from_en_translation(bot_response_en, desired_language)
|
35 |
bot_voice = tts(bot_response_de, desired_language)
|
36 |
bot_voice_bytes = tts_to_bytesio(bot_voice)
|
@@ -38,20 +43,24 @@ def main(audio: object) -> Tuple[str, str, str, object]:
|
|
38 |
return user_speech_text, bot_response_de, bot_response_en, html
|
39 |
|
40 |
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
Textbox(label="
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
|
|
|
|
|
|
|
|
|
1 |
"""Deploying AI Voice Chatbot Gradio App."""
|
2 |
+
import gradio as gr
|
3 |
from typing import Tuple
|
4 |
|
5 |
+
from utils import (
|
6 |
+
TextGenerationPipeline,
|
7 |
+
from_en_translation,
|
8 |
+
html_audio_autoplay,
|
9 |
+
stt,
|
10 |
+
to_en_translation,
|
11 |
+
tts,
|
12 |
+
tts_to_bytesio,
|
13 |
+
)
|
14 |
|
15 |
max_answer_length = 100
|
16 |
desired_language = "de"
|
|
|
18 |
|
19 |
|
20 |
def main(audio: object) -> Tuple[str, str, str, object]:
|
21 |
+
"""Calls functions for deploying Gradio app.
|
22 |
|
23 |
It responds both verbally and in text
|
24 |
+
by taking voice input from the user.
|
25 |
|
26 |
Args:
|
27 |
+
audio (object): Recorded speech of the user.
|
28 |
|
29 |
Returns:
|
30 |
+
tuple containing:
|
31 |
+
- user_speech_text (str): Recognized speech.
|
32 |
+
- bot_response_de (str): Translated answer of the bot.
|
33 |
+
- bot_response_en (str): Bot's original answer.
|
34 |
+
- html (object): Autoplayer for bot's speech.
|
|
|
35 |
"""
|
36 |
user_speech_text = stt(audio, desired_language)
|
37 |
+
translated_text = to_en_translation(user_speech_text, desired_language)
|
38 |
+
bot_response_en = response_generator_pipe(translated_text)
|
39 |
bot_response_de = from_en_translation(bot_response_en, desired_language)
|
40 |
bot_voice = tts(bot_response_de, desired_language)
|
41 |
bot_voice_bytes = tts_to_bytesio(bot_voice)
|
|
|
43 |
return user_speech_text, bot_response_de, bot_response_en, html
|
44 |
|
45 |
|
46 |
+
# Define the Gradio interface
|
47 |
+
with gr.Blocks() as demo:
|
48 |
+
gr.Markdown("## AI Voice Chatbot")
|
49 |
+
with gr.Row():
|
50 |
+
audio_input = gr.Audio(type="filepath", label="Speak or Upload Audio")
|
51 |
+
submit_btn = gr.Button("Submit")
|
52 |
+
with gr.Row():
|
53 |
+
user_speech_text = gr.Textbox(label="You said:", interactive=False)
|
54 |
+
bot_response_de = gr.Textbox(label="AI said (in German):", interactive=False)
|
55 |
+
bot_response_en = gr.Textbox(label="AI said (in English):", interactive=False)
|
56 |
+
html_output = gr.HTML()
|
57 |
+
|
58 |
+
# Connect the function to the components
|
59 |
+
submit_btn.click(
|
60 |
+
fn=main,
|
61 |
+
inputs=[audio_input],
|
62 |
+
outputs=[user_speech_text, bot_response_de, bot_response_en, html_output],
|
63 |
+
)
|
64 |
+
|
65 |
+
# Launch the Gradio app
|
66 |
+
demo.launch(debug=True)
|