File size: 775 Bytes
b9bd416
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
from transformers import pipeline, AutoTokenizer

base="Helsinki-NLP/opus-mt-en-zh"
model="edwinlaw/opus-mt-cantonese-v1"
tokenizer = AutoTokenizer.from_pretrained(base)

def translate(text, src_lang, tgt_lang):
    translator = pipeline(
        "translation",
        model=model,
        tokenizer=tokenizer,
        src_lang=src_lang,
        tgt_lang=tgt_lang,
    )
    translated_text = translator(text)
    return translated_text

st.title("Translate English into Cantonese:")

prompt = st.text_input('English sentence here')

if prompt:
    translation = translate(prompt, 'en', 'yue')
    translated_txt = translation[0]['translation_text']

    st.write(translated_txt)

    with st.expander('Chat History'):
        st.info(translated_txt)