rocky250 commited on
Commit
543b058
·
verified ·
1 Parent(s): 9ceaff2

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +61 -40
src/streamlit_app.py CHANGED
@@ -5,11 +5,7 @@ import numpy as np
5
  from transformers import AutoTokenizer, AutoModelForSequenceClassification
6
  from normalizer import normalize
7
 
8
- st.set_page_config(page_title="Political Sentiment", page_icon="
9
-
10
- ![BangladeshFlagGifGIF](https://cdn-uploads.huggingface.co/production/uploads/68f7211464f27c4b507fff44/EJ1PKsOdbqmUx4FbiUzXm.gif)
11
-
12
- ", layout="wide")
13
 
14
  st.markdown("""
15
  <style>
@@ -17,53 +13,68 @@ st.markdown("""
17
 
18
  html, body, [class*="css"] {
19
  font-family: 'Inter', sans-serif;
 
20
  }
21
 
22
  .stApp {
23
- background-color: #f0f2f6;
 
 
 
 
24
  }
25
 
26
  .main-card {
27
  background-color: white;
28
  padding: 30px;
29
  border-radius: 15px;
30
- box-shadow: 0 4px 6px rgba(0,0,0,0.05);
31
  margin-bottom: 25px;
32
  text-align: center;
 
33
  }
34
 
35
  .result-title {
36
- color: #6c757d;
37
- font-size: 14px;
38
  text-transform: uppercase;
39
- letter-spacing: 1px;
40
  margin-bottom: 10px;
41
- font-weight: 600;
42
  }
43
 
44
  .result-value {
45
- font-size: 42px;
46
  font-weight: 800;
47
  margin: 0;
48
  }
49
 
 
 
 
 
 
 
 
 
 
50
  .model-card {
51
  background-color: white;
52
  padding: 20px;
53
  border-radius: 12px;
54
- box-shadow: 0 2px 4px rgba(0,0,0,0.02);
55
  margin-bottom: 15px;
56
- transition: transform 0.2s;
57
- border: 1px solid #eee;
58
  }
59
 
60
  .model-card:hover {
61
- transform: translateY(-2px);
62
- box-shadow: 0 4px 8px rgba(0,0,0,0.05);
63
  }
64
 
65
  .model-name {
66
- color: #1f2937;
67
  font-size: 14px;
68
  font-weight: 600;
69
  margin-bottom: 8px;
@@ -71,36 +82,37 @@ st.markdown("""
71
  padding-bottom: 5px;
72
  }
73
 
 
 
 
 
74
  .prob-label {
75
- font-size: 13px;
76
- color: #4b5563;
77
- margin-bottom: 4px;
 
78
  display: flex;
79
  justify-content: space-between;
80
  }
81
 
82
  .prob-bar-bg {
83
  width: 100%;
84
- height: 8px;
85
  background-color: #e5e7eb;
86
- border-radius: 4px;
87
  overflow: hidden;
88
  }
89
 
90
  .prob-bar-fill {
91
  height: 100%;
92
- border-radius: 4px;
93
- transition: width 0.5s ease;
94
  }
95
 
96
  .stTextArea textarea {
97
  border-radius: 12px !important;
98
- border: 1px solid #d1d5db !important;
99
  padding: 15px !important;
100
- }
101
-
102
- div[data-testid="stMetricValue"] {
103
- font-size: 20px !important;
104
  }
105
  </style>
106
  """, unsafe_allow_html=True)
@@ -149,7 +161,7 @@ def get_detailed_prediction(text):
149
  final_vote = max(set(votes), key=votes.count)
150
  return final_vote, votes, avg_probs
151
 
152
- st.markdown("<h1 style='text-align: center; color: #111827; margin-bottom: 30px;'>🇧🇩 BD Political Sentiment Analysis</h1>", unsafe_allow_html=True)
153
 
154
  with st.container():
155
  col_input, col_action = st.columns([4, 1])
@@ -163,29 +175,38 @@ if analyze_btn and user_input.strip():
163
  with st.spinner('Running Ensemble Analysis...'):
164
  final_res, all_votes, avg_probs = get_detailed_prediction(user_input)
165
 
166
- st.markdown("<div style='height: 20px'></div>", unsafe_allow_html=True)
167
 
168
  main_col, details_col = st.columns([1, 1.5], gap="large")
169
 
170
  with main_col:
171
  st.markdown(f"""
172
- <div class="main-card" style="border-top: 5px solid {label_colors[final_res]}">
173
  <div class="result-title">Ensemble Consensus</div>
174
  <div class="result-value" style="color: {label_colors[final_res]}">{final_res}</div>
175
  </div>
176
  """, unsafe_allow_html=True)
177
 
178
- st.markdown("### Probability Distribution")
 
179
  for i in range(5):
180
  label = id2label[i]
181
- prob = avg_probs[i] * 100
 
 
 
 
 
 
 
182
  color = label_colors[label]
183
- opacity = "1.0" if prob > 5 else "0.3"
 
184
 
185
  st.markdown(f"""
186
- <div style="margin-bottom: 12px; opacity: {opacity}">
187
  <div class="prob-label">
188
- <span style="font-weight: 600;">{label}</span>
189
  <span>{prob:.1f}%</span>
190
  </div>
191
  <div class="prob-bar-bg">
@@ -195,7 +216,7 @@ if analyze_btn and user_input.strip():
195
  """, unsafe_allow_html=True)
196
 
197
  with details_col:
198
- st.markdown("### Individual Model Predictions")
199
  m_names = list(models_dict.keys())
200
 
201
  row1 = st.columns(2)
@@ -210,7 +231,7 @@ if analyze_btn and user_input.strip():
210
  st.markdown(f"""
211
  <div class="model-card">
212
  <div class="model-name">{model_name}</div>
213
- <div style="color: {color}; font-weight: 700; font-size: 18px;">{vote}</div>
214
  </div>
215
  """, unsafe_allow_html=True)
216
 
 
5
  from transformers import AutoTokenizer, AutoModelForSequenceClassification
6
  from normalizer import normalize
7
 
8
+ st.set_page_config(page_title="Political Sentiment", page_icon="🇧🇩", layout="wide")
 
 
 
 
9
 
10
  st.markdown("""
11
  <style>
 
13
 
14
  html, body, [class*="css"] {
15
  font-family: 'Inter', sans-serif;
16
+ color: #000000;
17
  }
18
 
19
  .stApp {
20
+ background-color: #f4f6f9;
21
+ }
22
+
23
+ h1, h2, h3 {
24
+ color: #111827 !important;
25
  }
26
 
27
  .main-card {
28
  background-color: white;
29
  padding: 30px;
30
  border-radius: 15px;
31
+ box-shadow: 0 4px 10px rgba(0,0,0,0.08);
32
  margin-bottom: 25px;
33
  text-align: center;
34
+ border: 1px solid #e5e7eb;
35
  }
36
 
37
  .result-title {
38
+ color: #374151;
39
+ font-size: 16px;
40
  text-transform: uppercase;
41
+ letter-spacing: 1.5px;
42
  margin-bottom: 10px;
43
+ font-weight: 700;
44
  }
45
 
46
  .result-value {
47
+ font-size: 48px;
48
  font-weight: 800;
49
  margin: 0;
50
  }
51
 
52
+ .section-header {
53
+ font-size: 20px;
54
+ font-weight: 700;
55
+ color: #1f2937;
56
+ margin-bottom: 20px;
57
+ border-left: 5px solid #2563eb;
58
+ padding-left: 10px;
59
+ }
60
+
61
  .model-card {
62
  background-color: white;
63
  padding: 20px;
64
  border-radius: 12px;
65
+ box-shadow: 0 2px 5px rgba(0,0,0,0.05);
66
  margin-bottom: 15px;
67
+ border: 1px solid #e5e7eb;
68
+ transition: all 0.2s ease;
69
  }
70
 
71
  .model-card:hover {
72
+ transform: translateY(-3px);
73
+ box-shadow: 0 8px 15px rgba(0,0,0,0.1);
74
  }
75
 
76
  .model-name {
77
+ color: #4b5563;
78
  font-size: 14px;
79
  font-weight: 600;
80
  margin-bottom: 8px;
 
82
  padding-bottom: 5px;
83
  }
84
 
85
+ .prob-row {
86
+ margin-bottom: 15px;
87
+ }
88
+
89
  .prob-label {
90
+ font-size: 14px;
91
+ color: #111827;
92
+ font-weight: 600;
93
+ margin-bottom: 5px;
94
  display: flex;
95
  justify-content: space-between;
96
  }
97
 
98
  .prob-bar-bg {
99
  width: 100%;
100
+ height: 10px;
101
  background-color: #e5e7eb;
102
+ border-radius: 5px;
103
  overflow: hidden;
104
  }
105
 
106
  .prob-bar-fill {
107
  height: 100%;
108
+ border-radius: 5px;
 
109
  }
110
 
111
  .stTextArea textarea {
112
  border-radius: 12px !important;
113
+ border: 2px solid #d1d5db !important;
114
  padding: 15px !important;
115
+ font-size: 16px;
 
 
 
116
  }
117
  </style>
118
  """, unsafe_allow_html=True)
 
161
  final_vote = max(set(votes), key=votes.count)
162
  return final_vote, votes, avg_probs
163
 
164
+ st.markdown("<h1 style='text-align: center; margin-bottom: 10px;'>🇧🇩 BD Political Sentiment Analysis</h1>", unsafe_allow_html=True)
165
 
166
  with st.container():
167
  col_input, col_action = st.columns([4, 1])
 
175
  with st.spinner('Running Ensemble Analysis...'):
176
  final_res, all_votes, avg_probs = get_detailed_prediction(user_input)
177
 
178
+ st.markdown("<div style='height: 30px'></div>", unsafe_allow_html=True)
179
 
180
  main_col, details_col = st.columns([1, 1.5], gap="large")
181
 
182
  with main_col:
183
  st.markdown(f"""
184
+ <div class="main-card" style="border-top: 6px solid {label_colors[final_res]}">
185
  <div class="result-title">Ensemble Consensus</div>
186
  <div class="result-value" style="color: {label_colors[final_res]}">{final_res}</div>
187
  </div>
188
  """, unsafe_allow_html=True)
189
 
190
+ st.markdown('<div class="section-header">Probability Distribution</div>', unsafe_allow_html=True)
191
+
192
  for i in range(5):
193
  label = id2label[i]
194
+ raw_prob = avg_probs[i] * 100
195
+
196
+ # Visual cleanup: Force 0% if extremely low to reduce noise
197
+ if raw_prob < 1.0:
198
+ prob = 0.0
199
+ else:
200
+ prob = raw_prob
201
+
202
  color = label_colors[label]
203
+ # High opacity for significant numbers, low for 0-1%
204
+ opacity = "1.0" if prob > 1 else "0.3"
205
 
206
  st.markdown(f"""
207
+ <div class="prob-row" style="opacity: {opacity}">
208
  <div class="prob-label">
209
+ <span>{label}</span>
210
  <span>{prob:.1f}%</span>
211
  </div>
212
  <div class="prob-bar-bg">
 
216
  """, unsafe_allow_html=True)
217
 
218
  with details_col:
219
+ st.markdown('<div class="section-header">Individual Model Predictions</div>', unsafe_allow_html=True)
220
  m_names = list(models_dict.keys())
221
 
222
  row1 = st.columns(2)
 
231
  st.markdown(f"""
232
  <div class="model-card">
233
  <div class="model-name">{model_name}</div>
234
+ <div style="color: {color}; font-weight: 700; font-size: 20px;">{vote}</div>
235
  </div>
236
  """, unsafe_allow_html=True)
237