File size: 1,570 Bytes
218d393 d7606e3 218d393 d7606e3 218d393 |
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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
'''Test EasyNMT opus-mt
'''
import streamlit as st
from easynmt import EasyNMT
model = EasyNMT('opus-mt')
# ---------- streamlit ----------
# When a user interacts with widgets in the app:
# Streamlit will rerun the code from top to bottom
# ---------- streamlit ----------
st.set_page_config(
page_title='EasyNMT Testing',
page_icon='📝',
layout='wide',
)
with st.container():
st.markdown('## 📑 Machine Translation')
st.write('This is a testing of EasyNMT and opus-mt model with Streamlit.')
lang_list = model.get_languages()
b_size = st.slider('Translation quality (Beam size)', 1, 10, 5)
text = ''
submit = ''
target_langs = ''
with st.form(key='nmt'):
text = st.text_area(
label='Enter text',
# placeholder='Enter a sentence. Pāḷi translation is not available now.', 1.0.0 does not have
help='Auto detect input language 170+.')
target_langs = st.multiselect(
'Translate to (can select more than one language)',
lang_list,
['en', 'vi'])
submit = st.form_submit_button(label='Translate')
if submit and text:
detected_lang = model.language_detection(text)
st.write('Dectected input language: ' + detected_lang)
if not target_langs:
st.error('Please choose at least 1 target language.')
st.stop()
for lang in target_langs:
try:
res = model.translate(text, target_lang=lang, beam_size=b_size)
if res:
st.success(lang + ' => ' + res)
except Exception as e:
st.write(e)
|