Spaces:
Runtime error
Runtime error
File size: 904 Bytes
7dec5c7 912ba15 7dec5c7 912ba15 6b843bc 912ba15 6b843bc 912ba15 6b843bc 912ba15 6b843bc |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
import gradio as gr
import IPython.display as ipd
from gtts import gTTS
import io
from transformers import pipeline
def translate_and_play_sound(text, lang='hi'):
translator = pipeline("translation", model="Amitesh007/finetuned-eng-hi-translation")
translation = translator(text)
tts = gTTS(text=translation[0]['translation_text'], lang=lang)
fp = io.BytesIO()
tts.write_to_fp(fp)
fp.seek(0)
audio = ipd.Audio(fp.read(), autoplay=True)
return translation[0]['translation_text'], audio
iface = gr.Interface(
fn=translate_and_play_sound,
inputs=gr.inputs.Textbox(lines=2, placeholder="Enter text in English"),
outputs=[gr.outputs.Textbox(label="Translated Text"), gr.outputs.Audio(label="Translation Audio")],
title="English to Hindi Translator",
description="Enter some text in English to translate and play the translation audio."
)
iface.launch()
|