veetla commited on
Commit
a13da65
1 Parent(s): ef74f5d

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -0
app.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Deploying AI Voice Chatbot Gradio App."""
2
+ from gradio import Audio, Interface, Textbox
3
+
4
+ from utils import (TextGenerationPipeline, from_en_translation,
5
+ html_audio_autoplay, stt, to_en_translation, tts,
6
+ tts_to_bytesio)
7
+
8
+ max_answer_length = 100
9
+ desired_language = "de"
10
+ response_generator_pipe = TextGenerationPipeline(max_length=max_answer_length)
11
+
12
+
13
+ def main(audio: object):
14
+ """Calls functions for deploying gradio app.
15
+ It responds both verbally and in text
16
+ by taking voice input from user.
17
+ Args:
18
+ audio (object): recorded speech of user
19
+ Returns:
20
+ tuple containing
21
+ - user_speech_text (str) : recognized speech
22
+ - bot_response_de (str) : translated answer of bot
23
+ - bot_response_en (str) : bot's original answer
24
+ - html (object) : autoplayer for bot's speech
25
+ """
26
+ user_speech_text = stt(audio, desired_language)
27
+ tranlated_text = to_en_translation(user_speech_text, desired_language)
28
+ bot_response_en = response_generator_pipe(tranlated_text)
29
+ bot_response_de = from_en_translation(bot_response_en, desired_language)
30
+ bot_voice = tts(bot_response_de, desired_language)
31
+ bot_voice_bytes = tts_to_bytesio(bot_voice)
32
+ html = html_audio_autoplay(bot_voice_bytes)
33
+ return user_speech_text, bot_response_de, bot_response_en, html
34
+
35
+
36
+ Interface(
37
+ fn=main,
38
+ inputs=[
39
+ Audio(
40
+ source="microphone",
41
+ type="filepath",
42
+ ),
43
+ ],
44
+ outputs=[
45
+ Textbox(label="You said: "),
46
+ Textbox(label="AI said: "),
47
+ Textbox(label="AI said (English): "),
48
+ "html",
49
+ ],
50
+ live=True,
51
+ allow_flagging="never",
52
+ ).launch()