Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,33 +1,26 @@
|
|
1 |
import gradio as gr
|
2 |
-
import
|
3 |
from gtts import gTTS
|
|
|
4 |
from transformers import pipeline
|
5 |
|
6 |
-
|
7 |
-
def play_sound(text, lang):
|
8 |
translator = pipeline("translation", model="Amitesh007/finetuned-eng-hi-translation")
|
9 |
translation = translator(text)
|
10 |
tts = gTTS(text=translation[0]['translation_text'], lang=lang)
|
11 |
fp = io.BytesIO()
|
12 |
tts.write_to_fp(fp)
|
13 |
fp.seek(0)
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
-
|
17 |
-
with gr.Blocks() as demo:
|
18 |
-
gr.Markdown("# English To Hindi Translator")
|
19 |
-
gr.Markdown("Enter some text in English to translate and play the audio. Play the audio a second time to listen clearly.")
|
20 |
-
|
21 |
-
with gr.Row():
|
22 |
-
with gr.Column():
|
23 |
-
input_text = gr.Textbox(lines=5, label="Input Text here....", placeholder="Type a sentence to translate and play")
|
24 |
-
translate_button = gr.Button("Translate and play sound")
|
25 |
-
|
26 |
-
with gr.Column():
|
27 |
-
output_audio = gr.Audio(label="Translated Speech")
|
28 |
-
output_text = gr.Textbox(label="Translated Text")
|
29 |
-
|
30 |
-
translate_button.click(fn=play_sound, inputs=input_text, outputs=[output_audio, output_text])
|
31 |
|
32 |
-
# Launch the interface
|
33 |
-
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
import IPython.display as ipd
|
3 |
from gtts import gTTS
|
4 |
+
import io
|
5 |
from transformers import pipeline
|
6 |
|
7 |
+
def translate_and_play_sound(text, lang='hi'):
|
|
|
8 |
translator = pipeline("translation", model="Amitesh007/finetuned-eng-hi-translation")
|
9 |
translation = translator(text)
|
10 |
tts = gTTS(text=translation[0]['translation_text'], lang=lang)
|
11 |
fp = io.BytesIO()
|
12 |
tts.write_to_fp(fp)
|
13 |
fp.seek(0)
|
14 |
+
audio = ipd.Audio(fp.read(), autoplay=True)
|
15 |
+
return translation[0]['translation_text'], audio
|
16 |
+
|
17 |
+
iface = gr.Interface(
|
18 |
+
fn=translate_and_play_sound,
|
19 |
+
inputs=gr.inputs.Textbox(lines=2, placeholder="Enter text in English"),
|
20 |
+
outputs=[gr.outputs.Textbox(label="Translated Text"), gr.outputs.Audio(label="Translation Audio")],
|
21 |
+
title="English to Hindi Translator",
|
22 |
+
description="Enter some text in English to translate and play the translation audio."
|
23 |
+
)
|
24 |
|
25 |
+
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
|
|
|
|