File size: 779 Bytes
b5b57b6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
from transformers import pipeline

# Create a translation pipeline
translator = pipeline("translation", model="lilsha/transentoch")

def main():
    st.title("Translate English to Chinese")

    with st.form("text_field"):
        text = st.text_area('Enter text:')
        clicked = st.form_submit_button("Translate")

        if clicked:
            # Translate the input text
            translation = translator(text, src_lang="en", tgt_lang="ch")

            # Display the translated text
            if translation:
                st.write("Translation :")
                st.write(translation[0]["translation_text"])
            else:
                st.write("Translation failed. Please check your input.")

if __name__ == "__main__":
    main()