Spaces:
Runtime error
Runtime error
import gradio as gr | |
from transformers import MBartForConditionalGeneration, MBart50TokenizerFast,MBartTokenizerFast,MBart50Tokenizer | |
from transformers import MBartTokenizer,MBartForConditionalGeneration, MBartConfig | |
model = MBartForConditionalGeneration.from_pretrained("facebook/mbart-large-50-one-to-many-mmt") | |
tokenizer = MBart50TokenizerFast.from_pretrained("facebook/mbart-large-50-one-to-many-mmt",src_lang="en_XX") | |
def get_input(text): | |
models_input = tokenizer(text,return_tensors="pt") | |
generated_tokens = model.generate(**models_input,forced_bos_token_id=tokenizer.lang_code_to_id["hi_IN"]) | |
translation = tokenizer.batch_decode(generated_tokens, skip_special_tokens=True) | |
return translation | |
iface = gr.Interface(fn=get_input,inputs="Text In English",outputs="Translated Text", title = "English to Hindi Translator",description="Translate the text given in English to Hindi") | |
iface.launch() |