Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -11,7 +11,6 @@ language_options = {
|
|
11 |
"Urdu": "Helsinki-NLP/opus-mt-en-ur",
|
12 |
"Punjabi": "Helsinki-NLP/opus-mt-en-pa", # Punjabi language model
|
13 |
"Pashto": "Helsinki-NLP/opus-mt-en-ps", # Pashto language model
|
14 |
-
# Add more languages as needed
|
15 |
}
|
16 |
|
17 |
# Function to load the model based on the selected language
|
@@ -28,47 +27,49 @@ def translate_text(model, tokenizer, text):
|
|
28 |
translated_text = tokenizer.decode(translated[0], skip_special_tokens=True)
|
29 |
return translated_text
|
30 |
|
31 |
-
# Streamlit app layout with dark gradient
|
32 |
st.markdown("""
|
33 |
<style>
|
34 |
body {
|
35 |
-
background: linear-gradient(
|
36 |
color: #e0e0e0;
|
37 |
}
|
38 |
.stApp {
|
39 |
-
background: linear-gradient(
|
40 |
}
|
41 |
.css-1d391kg {
|
42 |
-
background:
|
43 |
color: #e0e0e0;
|
44 |
border-radius: 10px;
|
45 |
padding: 20px;
|
|
|
46 |
}
|
47 |
.stButton > button {
|
48 |
-
background:
|
|
|
49 |
color: #e0e0e0;
|
50 |
-
border:
|
|
|
|
|
51 |
}
|
52 |
.stButton > button:hover {
|
53 |
-
background: linear-gradient(to right, #
|
54 |
-
border:
|
55 |
}
|
56 |
.stTextArea textarea {
|
57 |
-
background:
|
|
|
58 |
color: #e0e0e0;
|
59 |
-
border:
|
|
|
60 |
}
|
61 |
-
.
|
62 |
-
background-color:
|
63 |
-
color: #e0e0e0;
|
64 |
-
}
|
65 |
-
.css-1cpxqw2 a {
|
66 |
-
color: #e0e0e0 !important;
|
67 |
}
|
68 |
</style>
|
69 |
""", unsafe_allow_html=True)
|
70 |
|
71 |
-
# App title and subtitle with dark gradient
|
72 |
st.markdown("<h1 style='text-align: center; color: #e0e0e0;'>π Polyglot Translator π</h1>", unsafe_allow_html=True)
|
73 |
st.markdown("<p style='text-align: center; color: #b0b0b0; font-size: 20px;'>Empowering You to Speak Any Language!</p>", unsafe_allow_html=True)
|
74 |
|
@@ -86,4 +87,22 @@ st.markdown("<h3 style='color: #e0e0e0;'>Enter text in English to translate:</h3
|
|
86 |
text = st.text_area("", height=150)
|
87 |
|
88 |
# Character count
|
89 |
-
st.write(f"<p style='color: #
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
"Urdu": "Helsinki-NLP/opus-mt-en-ur",
|
12 |
"Punjabi": "Helsinki-NLP/opus-mt-en-pa", # Punjabi language model
|
13 |
"Pashto": "Helsinki-NLP/opus-mt-en-ps", # Pashto language model
|
|
|
14 |
}
|
15 |
|
16 |
# Function to load the model based on the selected language
|
|
|
27 |
translated_text = tokenizer.decode(translated[0], skip_special_tokens=True)
|
28 |
return translated_text
|
29 |
|
30 |
+
# Streamlit app layout with dark gradient colors
|
31 |
st.markdown("""
|
32 |
<style>
|
33 |
body {
|
34 |
+
background: linear-gradient(135deg, #1f1c2c, #928dab);
|
35 |
color: #e0e0e0;
|
36 |
}
|
37 |
.stApp {
|
38 |
+
background: linear-gradient(135deg, #1f1c2c, #928dab);
|
39 |
}
|
40 |
.css-1d391kg {
|
41 |
+
background-color: rgba(31, 28, 44, 0.8);
|
42 |
color: #e0e0e0;
|
43 |
border-radius: 10px;
|
44 |
padding: 20px;
|
45 |
+
border: 1px solid #333;
|
46 |
}
|
47 |
.stButton > button {
|
48 |
+
background-color: #333;
|
49 |
+
background-image: linear-gradient(to right, #4facfe, #00f2fe);
|
50 |
color: #e0e0e0;
|
51 |
+
border: none;
|
52 |
+
border-radius: 8px;
|
53 |
+
padding: 10px 20px;
|
54 |
}
|
55 |
.stButton > button:hover {
|
56 |
+
background-image: linear-gradient(to right, #00c6ff, #0072ff);
|
57 |
+
border: none;
|
58 |
}
|
59 |
.stTextArea textarea {
|
60 |
+
background-color: #333;
|
61 |
+
background-image: linear-gradient(to right, #4facfe, #00f2fe);
|
62 |
color: #e0e0e0;
|
63 |
+
border: none;
|
64 |
+
border-radius: 8px;
|
65 |
}
|
66 |
+
.stSidebar {
|
67 |
+
background-color: rgba(31, 28, 44, 0.9);
|
|
|
|
|
|
|
|
|
68 |
}
|
69 |
</style>
|
70 |
""", unsafe_allow_html=True)
|
71 |
|
72 |
+
# App title and subtitle with dark gradient
|
73 |
st.markdown("<h1 style='text-align: center; color: #e0e0e0;'>π Polyglot Translator π</h1>", unsafe_allow_html=True)
|
74 |
st.markdown("<p style='text-align: center; color: #b0b0b0; font-size: 20px;'>Empowering You to Speak Any Language!</p>", unsafe_allow_html=True)
|
75 |
|
|
|
87 |
text = st.text_area("", height=150)
|
88 |
|
89 |
# Character count
|
90 |
+
st.write(f"<p style='color: #e0e0e0;'>Character count: {len(text)}</p>", unsafe_allow_html=True)
|
91 |
+
|
92 |
+
# Button to translate
|
93 |
+
if st.button("Translate"):
|
94 |
+
if text:
|
95 |
+
# Show a spinner during the translation process
|
96 |
+
with st.spinner('Translating...'):
|
97 |
+
# Load model and tokenizer based on selected language
|
98 |
+
model_name = language_options[language]
|
99 |
+
model, tokenizer = load_model(model_name)
|
100 |
+
|
101 |
+
# Perform translation
|
102 |
+
translated_text = translate_text(model, tokenizer, text)
|
103 |
+
|
104 |
+
# Display the translation
|
105 |
+
st.markdown(f"<h3 style='color: #e0e0e0;'>Translated Text ({language}):</h3>", unsafe_allow_html=True)
|
106 |
+
st.success(translated_text)
|
107 |
+
else:
|
108 |
+
st.error("Please enter text to translate.")
|