File size: 803 Bytes
f8e5d24
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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)