Spaces:
Runtime error
Runtime error
File size: 1,243 Bytes
f546c1a 4dd2b31 f546c1a 4dd2b31 48a85a0 4dd2b31 f546c1a eb1b0b5 356ebfc f546c1a e8da2f4 f546c1a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
import transformers
import streamlit as st
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
st.title("English-Vietnamese Text Translator")
st.write("A simple interface to translate from English to Vietnamese, and vice versa.")
tokenizer = AutoTokenizer.from_pretrained("facebook/nllb-200-distilled-600M")
@st.cache
def load_model(model_name):
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
return model
model = load_model("facebook/nllb-200-distilled-600M")
src_lang_selection = st.radio(
"Select Your Source Language:",
('English', 'Vietnamese'))
if src_lang_selection == "English":
src_lang = "eng_Latn"
tgt_lang = "vie_Latn"
else:
src_lang = "vie_Latn"
tgt_lang = "eng_Latn"
# default_value = "UN Chief says there is no military solution in Syria"
sent = st.text_area("Input Your Text Here", height = 275)
if st.button("Run"):
with st.spinner("Working Hard..."):
translator = pipeline('translation', model=model, tokenizer=tokenizer, src_lang=src_lang, tgt_lang=tgt_lang)
trans_text = translator(sent)[0]["translation_text"]
st.write(trans_text)
st.success("Done!")
st.write("For feedback/requests, write to [email protected].") |