sainkan commited on
Commit
2aad4cf
Β·
verified Β·
1 Parent(s): e1c9233

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -32
app.py CHANGED
@@ -9,11 +9,11 @@ language_options = {
9
  "Italian": "Helsinki-NLP/opus-mt-en-it",
10
  "Dutch": "Helsinki-NLP/opus-mt-en-nl",
11
  "Urdu": "Helsinki-NLP/opus-mt-en-ur",
12
- "Punjabi": "Helsinki-NLP/opus-mt-en-pa",
13
- "Pashto": "Helsinki-NLP/opus-mt-en-ps",
 
14
  }
15
 
16
-
17
  # Function to load the model based on the selected language
18
  @st.cache_resource
19
  def load_model(model_name):
@@ -28,40 +28,47 @@ 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 color scheme
32
  st.markdown("""
33
  <style>
34
  body {
35
- background-color: #121212;
36
  color: #e0e0e0;
37
  }
38
  .stApp {
39
- background-color: #121212;
40
  }
41
  .css-1d391kg {
42
- background-color: #1f1f1f;
43
  color: #e0e0e0;
44
  border-radius: 10px;
45
  padding: 20px;
46
  }
47
  .stButton > button {
48
- background-color: #1f1f1f;
49
  color: #e0e0e0;
50
- border: 1px solid #333;
51
  }
52
  .stButton > button:hover {
53
- background-color: #333;
54
- border: 1px solid #444;
55
  }
56
  .stTextArea textarea {
57
- background-color: #1f1f1f;
58
  color: #e0e0e0;
59
  border: 1px solid #333;
60
  }
 
 
 
 
 
 
 
61
  </style>
62
  """, unsafe_allow_html=True)
63
 
64
- # App title and subtitle with dark theme
65
  st.markdown("<h1 style='text-align: center; color: #e0e0e0;'>🌍 Polyglot Translator 🌍</h1>", unsafe_allow_html=True)
66
  st.markdown("<p style='text-align: center; color: #b0b0b0; font-size: 20px;'>Empowering You to Speak Any Language!</p>", unsafe_allow_html=True)
67
 
@@ -79,22 +86,4 @@ st.markdown("<h3 style='color: #e0e0e0;'>Enter text in English to translate:</h3
79
  text = st.text_area("", height=150)
80
 
81
  # Character count
82
- st.write(f"<p style='color: #e0e0e0;'>Character count: {len(text)}</p>", unsafe_allow_html=True)
83
-
84
- # Button to translate
85
- if st.button("Translate"):
86
- if text:
87
- # Show a spinner during the translation process
88
- with st.spinner('Translating...'):
89
- # Load model and tokenizer based on selected language
90
- model_name = language_options[language]
91
- model, tokenizer = load_model(model_name)
92
-
93
- # Perform translation
94
- translated_text = translate_text(model, tokenizer, text)
95
-
96
- # Display the translation
97
- st.markdown(f"<h3 style='color: #e0e0e0;'>Translated Text ({language}):</h3>", unsafe_allow_html=True)
98
- st.success(translated_text)
99
- else:
100
- st.error("Please enter text to translate.")
 
9
  "Italian": "Helsinki-NLP/opus-mt-en-it",
10
  "Dutch": "Helsinki-NLP/opus-mt-en-nl",
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
18
  @st.cache_resource
19
  def load_model(model_name):
 
28
  translated_text = tokenizer.decode(translated[0], skip_special_tokens=True)
29
  return translated_text
30
 
31
+ # Streamlit app layout with dark gradient theme
32
  st.markdown("""
33
  <style>
34
  body {
35
+ background: linear-gradient(to right, #0f0c29, #302b63, #24243e); /* Dark gradient */
36
  color: #e0e0e0;
37
  }
38
  .stApp {
39
+ background: linear-gradient(to right, #0f0c29, #302b63, #24243e); /* Dark gradient */
40
  }
41
  .css-1d391kg {
42
+ background: linear-gradient(to bottom, #141e30, #243b55); /* Dark gradient for text area */
43
  color: #e0e0e0;
44
  border-radius: 10px;
45
  padding: 20px;
46
  }
47
  .stButton > button {
48
+ background: linear-gradient(to right, #2c3e50, #4ca1af); /* Gradient for buttons */
49
  color: #e0e0e0;
50
+ border: 1px solid #444;
51
  }
52
  .stButton > button:hover {
53
+ background: linear-gradient(to right, #0f2027, #2c5364); /* Hover effect for buttons */
54
+ border: 1px solid #555;
55
  }
56
  .stTextArea textarea {
57
+ background: linear-gradient(to bottom, #141e30, #243b55); /* Dark gradient for text input */
58
  color: #e0e0e0;
59
  border: 1px solid #333;
60
  }
61
+ .css-1r6slb0 {
62
+ background-color: #141e30 !important; /* Sidebar background */
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 theme
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
  text = st.text_area("", height=150)
87
 
88
  # Character count
89
+ st.write(f"<p style='color: #e0