File size: 967 Bytes
5e22169
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
28
from transformers import MBartForConditionalGeneration, MBart50TokenizerFast
import gradio as gr

# Load the tokenizer and model
model_checkpoint = "aryaumesh/english-to-telugu"
tokenizer = MBart50TokenizerFast.from_pretrained(model_checkpoint)
model = MBartForConditionalGeneration.from_pretrained(model_checkpoint)

# Function to translate text
def translate_to_telugu(text):
    inputs = tokenizer(text, return_tensors="pt")
    outputs = model.generate(**inputs)
    translation = tokenizer.decode(outputs[0], skip_special_tokens=True)
    return translation

# Create a Gradio interface
iface = gr.Interface(
    fn=translate_to_telugu,
    inputs=gr.Textbox(lines=2, placeholder="Enter text in English..."),  # Text input
    outputs=gr.Textbox(label="Translation to Telugu"),  # Text output
    title="English to Telugu Translator",
    description="Translate text from English to Telugu using an MBart model."
)

# Launch the Gradio interface
iface.launch()