Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,9 +1,9 @@
|
|
1 |
-
import
|
2 |
-
import IPython.display as ipd
|
3 |
-
from gtts import gTTS
|
4 |
import io
|
|
|
5 |
from transformers import pipeline
|
6 |
|
|
|
7 |
def play_sound(text, lang):
|
8 |
translator = pipeline("translation", model="Amitesh007/finetuned-eng-hi-translation")
|
9 |
translation = translator(text)
|
@@ -11,12 +11,23 @@ def play_sound(text, lang):
|
|
11 |
fp = io.BytesIO()
|
12 |
tts.write_to_fp(fp)
|
13 |
fp.seek(0)
|
14 |
-
return
|
15 |
-
|
16 |
-
st.title("English To Hindi Translator")
|
17 |
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
-
|
21 |
-
|
22 |
-
st.write(audio)
|
|
|
1 |
+
import gradio as gr
|
|
|
|
|
2 |
import io
|
3 |
+
from gtts import gTTS
|
4 |
from transformers import pipeline
|
5 |
|
6 |
+
# Define the translation and text-to-speech function
|
7 |
def play_sound(text, lang):
|
8 |
translator = pipeline("translation", model="Amitesh007/finetuned-eng-hi-translation")
|
9 |
translation = translator(text)
|
|
|
11 |
fp = io.BytesIO()
|
12 |
tts.write_to_fp(fp)
|
13 |
fp.seek(0)
|
14 |
+
return fp.read(), translation[0]['translation_text']
|
|
|
|
|
15 |
|
16 |
+
# Create the Gradio Blocks interface
|
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()
|
|