Sabina Muratova
commited on
Commit
•
2f5564e
1
Parent(s):
d9c64f9
Add application file
Browse files
app.py
CHANGED
@@ -1,7 +1,11 @@
|
|
1 |
import streamlit as st
|
2 |
from transformers import pipeline, AutoTokenizer, AutoModelForSeq2SeqLM
|
3 |
|
4 |
-
|
|
|
|
|
|
|
|
|
5 |
|
6 |
def translate_text(text):
|
7 |
if text:
|
@@ -10,9 +14,26 @@ def translate_text(text):
|
|
10 |
return ""
|
11 |
|
12 |
st.title("Text Translation App")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
st.subheader("Enter text to translate:")
|
14 |
|
15 |
-
user_input = st.text_area("Your text here:", height=200)
|
16 |
|
17 |
if st.button("Translate"):
|
18 |
translation = translate_text(user_input)
|
@@ -21,6 +42,7 @@ if st.button("Translate"):
|
|
21 |
else:
|
22 |
st.info("Enter text and click 'Translate' to see the result.")
|
23 |
|
|
|
24 |
if __name__ == '__main__':
|
25 |
import streamlit.web.cli as stcli
|
26 |
stcli.main()
|
|
|
1 |
import streamlit as st
|
2 |
from transformers import pipeline, AutoTokenizer, AutoModelForSeq2SeqLM
|
3 |
|
4 |
+
def initialize_translator(model_name):
|
5 |
+
return pipeline("translation", model=model_name)
|
6 |
+
|
7 |
+
model_name = "Helsinki-NLP/opus-mt-en-ru"
|
8 |
+
translator = initialize_translator(model_name)
|
9 |
|
10 |
def translate_text(text):
|
11 |
if text:
|
|
|
14 |
return ""
|
15 |
|
16 |
st.title("Text Translation App")
|
17 |
+
|
18 |
+
st.sidebar.header("Settings")
|
19 |
+
language_pair = st.sidebar.selectbox(
|
20 |
+
"Choose language pair:",
|
21 |
+
[
|
22 |
+
"English to Russian (Helsinki-NLP/opus-mt-en-ru)",
|
23 |
+
"Russian to English (Helsinki-NLP/opus-mt-ru-en)"
|
24 |
+
]
|
25 |
+
)
|
26 |
+
|
27 |
+
if "Russian to English" in language_pair:
|
28 |
+
model_name = "Helsinki-NLP/opus-mt-ru-en"
|
29 |
+
else:
|
30 |
+
model_name = "Helsinki-NLP/opus-mt-en-ru"
|
31 |
+
|
32 |
+
translator = initialize_translator(model_name)
|
33 |
+
|
34 |
st.subheader("Enter text to translate:")
|
35 |
|
36 |
+
user_input = st.text_area("Your text here (e.g., 'The weather is nice today.'):", height=200)
|
37 |
|
38 |
if st.button("Translate"):
|
39 |
translation = translate_text(user_input)
|
|
|
42 |
else:
|
43 |
st.info("Enter text and click 'Translate' to see the result.")
|
44 |
|
45 |
+
|
46 |
if __name__ == '__main__':
|
47 |
import streamlit.web.cli as stcli
|
48 |
stcli.main()
|