Chris4K commited on
Commit
91773b9
·
verified ·
1 Parent(s): 07a921a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -32
app.py CHANGED
@@ -1,10 +1,16 @@
1
  """Deploying AI Voice Chatbot Gradio App."""
2
- from gradio import Audio, Interface, Textbox
3
  from typing import Tuple
4
 
5
- from utils import (TextGenerationPipeline, from_en_translation,
6
- html_audio_autoplay, stt, to_en_translation, tts,
7
- tts_to_bytesio)
 
 
 
 
 
 
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 gradio app.
16
 
17
  It responds both verbally and in text
18
- by taking voice input from user.
19
 
20
  Args:
21
- audio (object): recorded speech of user
22
 
23
  Returns:
24
- tuple containing
25
-
26
- - user_speech_text (str) : recognized speech
27
- - bot_response_de (str) : translated answer of bot
28
- - bot_response_en (str) : bot's original answer
29
- - html (object) : autoplayer for bot's speech
30
  """
31
  user_speech_text = stt(audio, desired_language)
32
- tranlated_text = to_en_translation(user_speech_text, desired_language)
33
- bot_response_en = response_generator_pipe(tranlated_text)
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
- Interface(
42
- fn=main,
43
- inputs=[
44
- Audio(
45
- source="microphone",
46
- type="filepath",
47
- ),
48
- ],
49
- outputs=[
50
- Textbox(label="You said: "),
51
- Textbox(label="AI said: "),
52
- Textbox(label="AI said (English): "),
53
- "html",
54
- ],
55
- live=True,
56
- allow_flagging="never",
57
- ).launch(debug=True)
 
 
 
 
 
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)