Tel_Translator / app.py
ZubairAhmed777's picture
Upload 2 files
5e22169 verified
raw
history blame
967 Bytes
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()