Initial checkin
Browse files- app.py +30 -0
- requirements.txt +4 -0
app.py
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import pipeline, AutoTokenizer
|
3 |
+
|
4 |
+
base="Helsinki-NLP/opus-mt-en-zh"
|
5 |
+
model="edwinlaw/opus-mt-cantonese-v1"
|
6 |
+
tokenizer = AutoTokenizer.from_pretrained(base)
|
7 |
+
|
8 |
+
def translate(text, src_lang, tgt_lang):
|
9 |
+
translator = pipeline(
|
10 |
+
"translation",
|
11 |
+
model=model,
|
12 |
+
tokenizer=tokenizer,
|
13 |
+
src_lang=src_lang,
|
14 |
+
tgt_lang=tgt_lang,
|
15 |
+
)
|
16 |
+
translated_text = translator(text)
|
17 |
+
return translated_text
|
18 |
+
|
19 |
+
st.title("Translate English into Cantonese:")
|
20 |
+
|
21 |
+
prompt = st.text_input('English sentence here')
|
22 |
+
|
23 |
+
if prompt:
|
24 |
+
translation = translate(prompt, 'en', 'yue')
|
25 |
+
translated_txt = translation[0]['translation_text']
|
26 |
+
|
27 |
+
st.write(translated_txt)
|
28 |
+
|
29 |
+
with st.expander('Chat History'):
|
30 |
+
st.info(translated_txt)
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
streamlit
|
2 |
+
transformers
|
3 |
+
transformers[sentencepiece]
|
4 |
+
torch
|