demo-app1 / app.py
tareesh's picture
Update app.py
b12d2a9
raw
history blame
901 Bytes
import streamlit as st
from transformers import MBartForConditionalGeneration, MBart50TokenizerFast
from transformers import AutoModelForMaskedLM, AutoTokenizer
model = MBartForConditionalGeneration.from_pretrained("facebook/mbart-large-50-one-to-many-mmt")
model = AutoModelForMaskedLM.from_pretrained("alabnii/jmedroberta-base-sentencepiece")
modek.eval()
tokenizer = MBart50TokenizerFast.from_pretrained("facebook/mbart-large-50-one-to-many-mmt", src_large="en_XX")
tokenizer = AutoTokenizer.from_pretrained("alabnii/jmedroberta-base-sentencepiece")
text = st.text_area('Enter the text:')
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)