File size: 663 Bytes
5dc48e3
e623ffc
5dc48e3
 
e623ffc
5dc48e3
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import streamlit as st
from transformers import MBartForConditionalGeneration, MBart50TokenizerFast

text = st.text_area('Enter the text:')
model = MBartForConditionalGenerationneration.from_pretrained("facebook/mbart-large-50-one-to-many-mmt")
tokenizer = MBart50TokenizerFast.from_pretrained("facebook/mbart-large-50-one-to-many-mmt", src_large="en_XX")

if text:
    model_inputs = tokenizer(text, return_tensors="pt")
    generated_tokens = model.generate(
        **model_inputs,
        forced_bos_token_id=tokenizer.lang_code_to_id["hi_IN"]
    )
    translation = tokenizer.batch_decode(generated_tokens, skip_special_tokens=True)
    st.json(translation)