Spaces:
Sleeping
Sleeping
import gradio as gr | |
from googletrans import Translator | |
def translate_text(text, direction): | |
translator = Translator() | |
if direction == "Hindi to English": | |
translated = translator.translate(text, src='hi', dest='en') | |
else: # English to Hindi | |
translated = translator.translate(text, src='en', dest='hi') | |
return translated.text | |
# Define the Gradio interface | |
iface = gr.Interface( | |
fn=translate_text, | |
inputs=[ | |
gr.Textbox(label="Enter text to translate"), | |
gr.Radio(["Hindi to English", "English to Hindi"], label="Translation Direction") | |
], | |
outputs=gr.Textbox(label="Translated Text"), | |
title="Hindi-English Translator", | |
description="Translate text between Hindi and English" | |
) | |
# Launch the interface | |
iface.launch(debug=True) |