Spaces:
Runtime error
Runtime error
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() | |