init
Browse files- requirements.txt +2 -0
- streamlit_app.py +60 -0
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit
|
| 2 |
+
easynmt
|
streamlit_app.py
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'''Test EasyNMT opus-mt
|
| 2 |
+
|
| 3 |
+
'''
|
| 4 |
+
|
| 5 |
+
import streamlit as st
|
| 6 |
+
from easynmt import EasyNMT
|
| 7 |
+
model = EasyNMT('opus-mt')
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
# ---------- streamlit ----------
|
| 11 |
+
# When a user interacts with widgets in the app:
|
| 12 |
+
# Streamlit will rerun the code from top to bottom
|
| 13 |
+
# ---------- streamlit ----------
|
| 14 |
+
st.set_page_config(
|
| 15 |
+
page_title='EasyNMT Testing',
|
| 16 |
+
page_icon='📝',
|
| 17 |
+
layout='wide',
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
with st.container():
|
| 22 |
+
st.markdown('## 📑 Machine Translation')
|
| 23 |
+
st.write('Using EasyNMT and opus-mt model.')
|
| 24 |
+
|
| 25 |
+
lang_list = model.get_languages()
|
| 26 |
+
|
| 27 |
+
b_size = st.slider('Translation quality (Beam size)', 1, 10, 5)
|
| 28 |
+
|
| 29 |
+
text = ''
|
| 30 |
+
submit = ''
|
| 31 |
+
target_langs = ''
|
| 32 |
+
|
| 33 |
+
with st.form(key='nmt'):
|
| 34 |
+
text = st.text_area(
|
| 35 |
+
label='Enter text',
|
| 36 |
+
placeholder='Enter a sentence. Pāḷi translation is not available now.',
|
| 37 |
+
help='Auto detect input language 170+.')
|
| 38 |
+
target_langs = st.multiselect(
|
| 39 |
+
'Translate to (can select more than one language)',
|
| 40 |
+
lang_list,
|
| 41 |
+
['en', 'vi'])
|
| 42 |
+
submit = st.form_submit_button(label='Translate')
|
| 43 |
+
|
| 44 |
+
if submit and text:
|
| 45 |
+
detected_lang = model.language_detection(text)
|
| 46 |
+
|
| 47 |
+
st.write('Dectected input language: ' + detected_lang)
|
| 48 |
+
|
| 49 |
+
if not target_langs:
|
| 50 |
+
st.error('Please choose at least 1 target language.')
|
| 51 |
+
st.stop()
|
| 52 |
+
|
| 53 |
+
for lang in target_langs:
|
| 54 |
+
try:
|
| 55 |
+
res = model.translate(text, target_lang=lang, beam_size=b_size)
|
| 56 |
+
if res:
|
| 57 |
+
st.success(lang + ' => ' + res)
|
| 58 |
+
|
| 59 |
+
except Exception as e:
|
| 60 |
+
st.write(e)
|