Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,52 +1,17 @@
|
|
1 |
-
|
2 |
-
from gradio import Audio, Interface, Textbox
|
3 |
|
4 |
-
from
|
5 |
-
html_audio_autoplay, stt, to_en_translation, tts,
|
6 |
-
tts_to_bytesio)
|
7 |
|
8 |
-
|
9 |
-
desired_language = "de"
|
10 |
-
response_generator_pipe = TextGenerationPipeline(max_length=max_answer_length)
|
11 |
|
|
|
|
|
12 |
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
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()
|
|
|
1 |
+
import gradio as gr
|
|
|
2 |
|
3 |
+
from transformers import pipeline
|
|
|
|
|
4 |
|
5 |
+
pipe = pipeline("translation", model="Helsinki-NLP/opus-mt-en-es")
|
|
|
|
|
6 |
|
7 |
+
def predict(text):
|
8 |
+
return pipe(text)[0]["translation_text"]
|
9 |
|
10 |
+
iface = gr.Interface(
|
11 |
+
fn=predict,
|
12 |
+
inputs='text',
|
13 |
+
outputs='text',
|
14 |
+
examples=[["Hello! My name is Omar"]]
|
15 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
+
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|