Spaces:
Configuration error
Configuration error
translation
Browse files
app.py
CHANGED
@@ -1,47 +1,53 @@
|
|
1 |
import streamlit as st
|
2 |
-
from transformers import
|
3 |
|
4 |
print("Loading the model...")
|
5 |
|
6 |
# Title and Description
|
7 |
-
st.title("
|
8 |
st.write("""
|
9 |
### Powered by Hugging Face and Streamlit
|
10 |
-
This app uses a pre-trained NLP model from Hugging Face to
|
11 |
-
|
12 |
""")
|
13 |
|
14 |
-
# Initialize Hugging Face
|
15 |
@st.cache_resource
|
16 |
-
def
|
17 |
-
print("
|
18 |
-
|
|
|
|
|
19 |
|
20 |
-
|
21 |
|
22 |
-
|
23 |
-
|
|
|
|
|
|
|
|
|
24 |
|
25 |
-
|
26 |
-
|
27 |
-
|
|
|
|
|
|
|
28 |
if user_input.strip():
|
29 |
-
result =
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
st.subheader("Sentiment Analysis Result")
|
35 |
-
st.write(f"**Sentiment:** {sentiment}")
|
36 |
-
st.write(f"**Confidence Score:** {score:.2f}")
|
37 |
else:
|
38 |
-
st.warning("Please enter some text to
|
39 |
|
40 |
# Sidebar with About Information
|
41 |
st.sidebar.title("About")
|
42 |
st.sidebar.info("""
|
43 |
This app demonstrates the use of Hugging Face's NLP models with Streamlit.
|
44 |
-
It uses the `
|
45 |
""")
|
46 |
|
47 |
-
print('
|
|
|
1 |
import streamlit as st
|
2 |
+
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer, TranslationPipeline
|
3 |
|
4 |
print("Loading the model...")
|
5 |
|
6 |
# Title and Description
|
7 |
+
st.title("Translation Web App")
|
8 |
st.write("""
|
9 |
### Powered by Hugging Face and Streamlit
|
10 |
+
This app uses a pre-trained NLP model from Hugging Face to translate text between languages.
|
11 |
+
Enter text in the source language, select source and target languages, and see the translation!
|
12 |
""")
|
13 |
|
14 |
+
# Initialize Hugging Face Translation Pipeline
|
15 |
@st.cache_resource
|
16 |
+
def load_translation_pipeline():
|
17 |
+
print("Loading translation model...")
|
18 |
+
model = AutoModelForSeq2SeqLM.from_pretrained('issai/tilmash')
|
19 |
+
tokenizer = AutoTokenizer.from_pretrained("issai/tilmash")
|
20 |
+
return TranslationPipeline(model=model, tokenizer=tokenizer, max_length=1000)
|
21 |
|
22 |
+
tilmash = load_translation_pipeline()
|
23 |
|
24 |
+
languages = {
|
25 |
+
"Kazakh (Cyrillic)": "kaz_Cyrl",
|
26 |
+
"Russian (Cyrillic)": "rus_Cyrl",
|
27 |
+
"English (Latin)": "eng_Latn",
|
28 |
+
"Turkish (Latin)": "tur_Latn"
|
29 |
+
}
|
30 |
|
31 |
+
src_lang = st.selectbox("Select source language:", options=list(languages.keys()), index=0)
|
32 |
+
tgt_lang = st.selectbox("Select target language:", options=list(languages.keys()), index=2)
|
33 |
+
|
34 |
+
user_input = st.text_area("Enter text to translate:", "")
|
35 |
+
|
36 |
+
if st.button("Translate Text"):
|
37 |
if user_input.strip():
|
38 |
+
result = tilmash(user_input, src_lang=languages[src_lang], tgt_lang=languages[tgt_lang])
|
39 |
+
translation = result[0]['translation_text']
|
40 |
+
|
41 |
+
st.subheader("Translation Result")
|
42 |
+
st.write(f"**Translated Text:** {translation}")
|
|
|
|
|
|
|
43 |
else:
|
44 |
+
st.warning("Please enter some text to translate!")
|
45 |
|
46 |
# Sidebar with About Information
|
47 |
st.sidebar.title("About")
|
48 |
st.sidebar.info("""
|
49 |
This app demonstrates the use of Hugging Face's NLP models with Streamlit.
|
50 |
+
It uses the `issai/tilmash` model for translation between languages such as Kazakh, Russian, English, and Turkish.
|
51 |
""")
|
52 |
|
53 |
+
print('After translation operation')
|