Spaces:
Runtime error
Runtime error
from transformers import MBartForConditionalGeneration, MBart50Tokenizer | |
import gradio as gr | |
# Load mBART model and tokenizer for multilingual translation | |
model_name = 'facebook/mbart-large-50-many-to-one-mmt' # mBART 50 for many-to-one translation (many languages to English) | |
tokenizer = MBart50Tokenizer.from_pretrained(model_name) | |
model = MBartForConditionalGeneration.from_pretrained(model_name) | |
# Set the source language code (Tamil) | |
tokenizer.src_lang = "ta_IN" # Tamil language code | |
# Function for translation | |
def translate(text): | |
inputs = tokenizer(text, return_tensors="pt") | |
generated_tokens = model.generate(**inputs) | |
translated_text = tokenizer.batch_decode(generated_tokens, skip_special_tokens=True)[0] | |
return translated_text | |
# Launch a Gradio interface | |
interface = gr.Interface(fn=translate, inputs="text", outputs="text", title="Tamil to English Translator") | |
interface.launch() | |