Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -26,9 +26,28 @@ def translate_text(model, tokenizer, text):
|
|
| 26 |
translated_text = tokenizer.decode(translated[0], skip_special_tokens=True)
|
| 27 |
return translated_text
|
| 28 |
|
| 29 |
-
# Streamlit app layout
|
| 30 |
-
st.markdown("
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
# Sidebar for language selection and instructions
|
| 34 |
st.sidebar.title("Language Options")
|
|
@@ -40,10 +59,11 @@ st.sidebar.write("2. Select the target language from the options.")
|
|
| 40 |
st.sidebar.write("3. Click **Translate** to get the result.")
|
| 41 |
|
| 42 |
# Input text
|
| 43 |
-
|
|
|
|
| 44 |
|
| 45 |
# Character count
|
| 46 |
-
st.write(f"Character count: {len(text)}")
|
| 47 |
|
| 48 |
# Button to translate
|
| 49 |
if st.button("Translate"):
|
|
@@ -58,9 +78,7 @@ if st.button("Translate"):
|
|
| 58 |
translated_text = translate_text(model, tokenizer, text)
|
| 59 |
|
| 60 |
# Display the translation
|
| 61 |
-
st.markdown(f"<h3 style='color:
|
| 62 |
st.success(translated_text)
|
| 63 |
else:
|
| 64 |
st.error("Please enter text to translate.")
|
| 65 |
-
|
| 66 |
-
unsafe_allow_html=True
|
|
|
|
| 26 |
translated_text = tokenizer.decode(translated[0], skip_special_tokens=True)
|
| 27 |
return translated_text
|
| 28 |
|
| 29 |
+
# Streamlit app layout with CSS for background and design
|
| 30 |
+
st.markdown("""
|
| 31 |
+
<style>
|
| 32 |
+
body {
|
| 33 |
+
background: linear-gradient(to right, #4facfe, #00f2fe);
|
| 34 |
+
color: white;
|
| 35 |
+
}
|
| 36 |
+
.stApp {
|
| 37 |
+
background: linear-gradient(to bottom, #4facfe, #00f2fe);
|
| 38 |
+
}
|
| 39 |
+
.css-1d391kg {
|
| 40 |
+
background-color: rgba(0, 0, 0, 0.7);
|
| 41 |
+
color: white;
|
| 42 |
+
border-radius: 10px;
|
| 43 |
+
padding: 20px;
|
| 44 |
+
}
|
| 45 |
+
</style>
|
| 46 |
+
""", unsafe_allow_html=True)
|
| 47 |
+
|
| 48 |
+
# App title and subtitle with attractive design
|
| 49 |
+
st.markdown("<h1 style='text-align: center; color: white;'>π Polyglot Translator π</h1>", unsafe_allow_html=True)
|
| 50 |
+
st.markdown("<p style='text-align: center; color: #ffffff; font-size: 20px;'>Empowering You to Speak Any Language!</p>", unsafe_allow_html=True)
|
| 51 |
|
| 52 |
# Sidebar for language selection and instructions
|
| 53 |
st.sidebar.title("Language Options")
|
|
|
|
| 59 |
st.sidebar.write("3. Click **Translate** to get the result.")
|
| 60 |
|
| 61 |
# Input text
|
| 62 |
+
st.markdown("<h3 style='color: white;'>Enter text in English to translate:</h3>", unsafe_allow_html=True)
|
| 63 |
+
text = st.text_area("", height=150)
|
| 64 |
|
| 65 |
# Character count
|
| 66 |
+
st.write(f"<p style='color: white;'>Character count: {len(text)}</p>", unsafe_allow_html=True)
|
| 67 |
|
| 68 |
# Button to translate
|
| 69 |
if st.button("Translate"):
|
|
|
|
| 78 |
translated_text = translate_text(model, tokenizer, text)
|
| 79 |
|
| 80 |
# Display the translation
|
| 81 |
+
st.markdown(f"<h3 style='color: white;'>Translated Text ({language}):</h3>", unsafe_allow_html=True)
|
| 82 |
st.success(translated_text)
|
| 83 |
else:
|
| 84 |
st.error("Please enter text to translate.")
|
|
|
|
|
|