KhaqanNasir commited on
Commit
5720634
·
verified ·
1 Parent(s): e7ce344

Update src/app.py

Browse files
Files changed (1) hide show
  1. src/app.py +92 -98
src/app.py CHANGED
@@ -35,7 +35,7 @@ from src.models.hybrid_model import HybridFakeNewsDetector
35
  from src.config.config import *
36
  from src.data.preprocessor import TextPreprocessor
37
 
38
- # Custom CSS for enhanced, modern styling
39
  st.markdown("""
40
  <style>
41
  /* Import Google Fonts */
@@ -50,13 +50,13 @@ st.markdown("""
50
 
51
  .stApp {
52
  font-family: 'Inter', sans-serif;
53
- background: #ffffff;
54
  min-height: 100vh;
55
  color: #1a202c;
56
  }
57
 
58
- /* Hide Streamlit elements */
59
- #MainMenu {visibility: hidden;}
60
  footer {visibility: hidden;}
61
  .stDeployButton {display: none;}
62
  header {visibility: hidden;}
@@ -64,26 +64,22 @@ st.markdown("""
64
 
65
  /* Container */
66
  .container {
67
- max-width: 1280px;
68
  margin: 0 auto;
69
- padding: 2rem 1.5rem;
70
  }
71
 
72
  /* Header */
73
  .header {
74
- background: #ffffff;
75
- padding: 1rem 2rem;
76
- box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
77
- position: sticky;
78
- top: 0;
79
- z-index: 1000;
80
  }
81
 
82
  .header-title {
83
  font-size: 2rem;
84
  font-weight: 800;
85
  color: #1a202c;
86
- display: flex;
87
  align-items: center;
88
  gap: 0.5rem;
89
  }
@@ -92,12 +88,8 @@ st.markdown("""
92
  .hero {
93
  display: flex;
94
  align-items: center;
95
- gap: 3rem;
96
- margin-bottom: 4rem;
97
- background: linear-gradient(135deg, #f8fafc 0%, #edf2f7 100%);
98
- padding: 4rem 2rem;
99
- border-radius: 16px;
100
- box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
101
  }
102
 
103
  .hero-left {
@@ -115,76 +107,64 @@ st.markdown("""
115
  .hero-right img {
116
  max-width: 100%;
117
  height: auto;
118
- border-radius: 12px;
119
- box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
120
- transition: transform 0.3s ease;
121
- }
122
-
123
- .hero-right img:hover {
124
- transform: scale(1.02);
125
  }
126
 
127
  .hero-title {
128
- font-size: 3rem;
129
- font-weight: 800;
130
  color: #1a202c;
131
- margin-bottom: 1.5rem;
132
- line-height: 1.2;
133
  }
134
 
135
  .hero-text {
136
- font-size: 1.2rem;
137
  color: #4a5568;
138
- line-height: 1.7;
139
- max-width: 500px;
140
  }
141
 
142
  /* About Section */
143
  .about-section {
144
- margin-bottom: 3rem;
145
  text-align: center;
146
- padding: 2rem;
147
  }
148
 
149
  .about-title {
150
- font-size: 2.2rem;
151
- font-weight: 700;
152
  color: #1a202c;
153
- margin-bottom: 1rem;
154
  }
155
 
156
  .about-text {
157
- font-size: 1.1rem;
158
  color: #4a5568;
159
- line-height: 1.6;
160
- max-width: 700px;
161
  margin: 0 auto;
162
  }
163
 
164
  /* Input Section */
165
  .input-container {
166
- max-width: 900px;
167
  margin: 0 auto;
168
- padding: 1.5rem;
169
- background: #ffffff;
170
- border-radius: 12px;
171
- box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
172
  }
173
 
174
  .stTextArea > div > div > textarea {
175
- border-radius: 10px !important;
176
  border: 1px solid #d1d5db !important;
177
- padding: 1.2rem !important;
178
  font-size: 1rem !important;
179
  font-family: 'Inter', sans-serif !important;
180
- background: #f9fafb !important;
181
- min-height: 180px !important;
182
- transition: all 0.3s ease !important;
183
  }
184
 
185
  .stTextArea > div > div > textarea:focus {
186
  border-color: #6366f1 !important;
187
- box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1) !important;
188
  outline: none !important;
189
  }
190
 
@@ -194,38 +174,34 @@ st.markdown("""
194
 
195
  /* Button Styling */
196
  .stButton > button {
197
- background: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%) !important;
198
  color: white !important;
199
- border-radius: 10px !important;
200
- padding: 0.8rem 2.5rem !important;
201
- font-size: 1.1rem !important;
202
  font-weight: 600 !important;
203
  font-family: 'Inter', sans-serif !important;
204
- transition: all 0.3s ease !important;
205
- box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3) !important;
206
- width: 100% !important;
207
  border: none !important;
 
208
  }
209
 
210
  .stButton > button:hover {
211
- background: linear-gradient(135deg, #4f46e5 0%, #4338ca 100%) !important;
212
- transform: translateY(-2px) !important;
213
- box-shadow: 0 6px 16px rgba(99, 102, 241, 0.4) !important;
214
  }
215
 
216
  /* Results Section */
217
  .results-container {
218
- margin-top: 2rem;
219
- padding: 2rem;
220
- background: #ffffff;
221
- border-radius: 12px;
222
- box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
223
  }
224
 
225
  .result-card {
226
- padding: 1.5rem;
227
- border-radius: 10px;
228
- border-left: 5px solid transparent;
229
  margin-bottom: 1rem;
230
  }
231
 
@@ -241,8 +217,8 @@ st.markdown("""
241
 
242
  .prediction-badge {
243
  font-weight: 600;
244
- font-size: 1.1rem;
245
- margin-bottom: 1rem;
246
  display: flex;
247
  align-items: center;
248
  gap: 0.5rem;
@@ -251,25 +227,32 @@ st.markdown("""
251
  .confidence-score {
252
  font-weight: 600;
253
  margin-left: auto;
254
- font-size: 1.1rem;
255
  }
256
 
257
  /* Chart Containers */
258
  .chart-container {
259
- padding: 1.5rem;
260
- border-radius: 10px;
261
- background: #ffffff;
262
- box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
263
- margin: 1.5rem 0;
264
  }
265
 
266
  /* Footer */
267
  .footer {
268
- margin-top: 4rem;
269
- padding: 1.5rem;
270
  text-align: center;
271
  border-top: 1px solid #e5e7eb;
272
- background: #f8fafc;
 
 
 
 
 
 
 
 
 
273
  }
274
  </style>
275
  """, unsafe_allow_html=True)
@@ -345,12 +328,12 @@ def plot_confidence(probabilities):
345
  )
346
  ])
347
  fig.update_layout(
348
- title={'text': 'Prediction Confidence', 'x': 0.5, 'xanchor': 'center', 'font': {'size': 20}},
349
- xaxis=dict(title='Classification', titlefont={'size': 14}, tickfont={'size': 12}),
350
- yaxis=dict(title='Probability', range=[0, 1], tickformat='.0%', titlefont={'size': 14}, tickfont={'size': 12}),
351
  template='plotly_white',
352
- height=350,
353
- margin=dict(t=80, b=80)
354
  )
355
  return fig
356
 
@@ -372,16 +355,27 @@ def plot_attention(text, attention_weights):
372
  )
373
  ])
374
  fig.update_layout(
375
- title={'text': 'Attention Weights', 'x': 0.5, 'xanchor': 'center', 'font': {'size': 20}},
376
- xaxis=dict(title='Words', tickangle=45, titlefont={'size': 14}, tickfont={'size': 12}),
377
- yaxis=dict(title='Attention Score', titlefont={'size': 14}, tickfont={'size': 12}),
378
- template='plotly_white/pubs/DeepSearch/2025-07-25/4f0e5e9c-7e3f-4d87-9b50-3d7f1c7f5e6a.txt',
379
- height=400,
380
- margin=dict(t=80, b=100)
381
  )
382
  return fig
383
 
384
  def main():
 
 
 
 
 
 
 
 
 
 
 
385
  # Header
386
  st.markdown("""
387
  <div class="header">
@@ -398,11 +392,11 @@ def main():
398
  <div class="hero-left">
399
  <h2 class="hero-title">Instant Fake News Detection</h2>
400
  <p class="hero-text">
401
- Discover the truth behind news articles with our cutting-edge AI. Powered by a hybrid BERT-BiLSTM model, TruthCheck delivers fast, accurate, and transparent analysis of news authenticity.
402
  </p>
403
  </div>
404
  <div class="hero-right">
405
- <img src="/hero.png" alt="TruthCheck Illustration">
406
  </div>
407
  </div>
408
  </div>
@@ -414,7 +408,7 @@ def main():
414
  <div class="about-section">
415
  <h2 class="about-title">About TruthCheck</h2>
416
  <p class="about-text">
417
- TruthCheck combines advanced BERT and BiLSTM technologies to detect fake news with over 95% accuracy. Paste any news article below to receive a detailed analysis, including confidence scores and attention insights, in seconds.
418
  </p>
419
  </div>
420
  </div>
@@ -424,7 +418,7 @@ def main():
424
  st.markdown('<div class="container"><div class="input-container">', unsafe_allow_html=True)
425
  news_text = st.text_area(
426
  "Analyze a News Article",
427
- height=180,
428
  placeholder="Paste your news article here for instant AI analysis...",
429
  key="news_input"
430
  )
@@ -451,14 +445,14 @@ def main():
451
  st.markdown(f'''
452
  <div class="result-card fake-news">
453
  <div class="prediction-badge">🚨 Fake News Detected <span class="confidence-score">{result["confidence"]:.1%}</span></div>
454
- <p>Our AI has identified this content as likely misinformation based on linguistic patterns, structural analysis, and content inconsistencies.</p>
455
  </div>
456
  ''', unsafe_allow_html=True)
457
  else:
458
  st.markdown(f'''
459
  <div class="result-card real-news">
460
  <div class="prediction-badge">✅ Authentic News <span class="confidence-score">{result["confidence"]:.1%}</span></div>
461
- <p>This content appears to be legitimate based on professional writing style, factual consistency, and structural integrity.</p>
462
  </div>
463
  ''', unsafe_allow_html=True)
464
 
 
35
  from src.config.config import *
36
  from src.data.preprocessor import TextPreprocessor
37
 
38
+ # Custom CSS for streamlined styling with sidebar
39
  st.markdown("""
40
  <style>
41
  /* Import Google Fonts */
 
50
 
51
  .stApp {
52
  font-family: 'Inter', sans-serif;
53
+ background: #f8fafc;
54
  min-height: 100vh;
55
  color: #1a202c;
56
  }
57
 
58
+ /* Ensure sidebar is visible */
59
+ #MainMenu {visibility: visible;}
60
  footer {visibility: hidden;}
61
  .stDeployButton {display: none;}
62
  header {visibility: hidden;}
 
64
 
65
  /* Container */
66
  .container {
67
+ max-width: 1200px;
68
  margin: 0 auto;
69
+ padding: 1rem;
70
  }
71
 
72
  /* Header */
73
  .header {
74
+ padding: 1rem 0;
75
+ text-align: center;
 
 
 
 
76
  }
77
 
78
  .header-title {
79
  font-size: 2rem;
80
  font-weight: 800;
81
  color: #1a202c;
82
+ display: inline-flex;
83
  align-items: center;
84
  gap: 0.5rem;
85
  }
 
88
  .hero {
89
  display: flex;
90
  align-items: center;
91
+ gap: 2rem;
92
+ margin-bottom: 2rem;
 
 
 
 
93
  }
94
 
95
  .hero-left {
 
107
  .hero-right img {
108
  max-width: 100%;
109
  height: auto;
110
+ border-radius: 8px;
 
 
 
 
 
 
111
  }
112
 
113
  .hero-title {
114
+ font-size: 2.5rem;
115
+ font-weight: 700;
116
  color: #1a202c;
117
+ margin-bottom: 0.5rem;
 
118
  }
119
 
120
  .hero-text {
121
+ font-size: 1rem;
122
  color: #4a5568;
123
+ line-height: 1.5;
124
+ max-width: 450px;
125
  }
126
 
127
  /* About Section */
128
  .about-section {
129
+ margin-bottom: 2rem;
130
  text-align: center;
 
131
  }
132
 
133
  .about-title {
134
+ font-size: 1.8rem;
135
+ font-weight: 600;
136
  color: #1a202c;
137
+ margin-bottom: 0.5rem;
138
  }
139
 
140
  .about-text {
141
+ font-size: 1rem;
142
  color: #4a5568;
143
+ line-height: 1.5;
144
+ max-width: 600px;
145
  margin: 0 auto;
146
  }
147
 
148
  /* Input Section */
149
  .input-container {
150
+ max-width: 800px;
151
  margin: 0 auto;
 
 
 
 
152
  }
153
 
154
  .stTextArea > div > div > textarea {
155
+ border-radius: 8px !important;
156
  border: 1px solid #d1d5db !important;
157
+ padding: 1rem !important;
158
  font-size: 1rem !important;
159
  font-family: 'Inter', sans-serif !important;
160
+ background: #ffffff !important;
161
+ min-height: 150px !important;
162
+ transition: all 0.2s ease !important;
163
  }
164
 
165
  .stTextArea > div > div > textarea:focus {
166
  border-color: #6366f1 !important;
167
+ box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.1) !important;
168
  outline: none !important;
169
  }
170
 
 
174
 
175
  /* Button Styling */
176
  .stButton > button {
177
+ background: #6366f1 !important;
178
  color: white !important;
179
+ border-radius: 8px !important;
180
+ padding: 0.75rem 2rem !important;
181
+ font-size: 1rem !important;
182
  font-weight: 600 !important;
183
  font-family: 'Inter', sans-serif !important;
184
+ transition: all 0.2s ease !important;
 
 
185
  border: none !important;
186
+ width: 100% !important;
187
  }
188
 
189
  .stButton > button:hover {
190
+ background: #4f46e5 !important;
191
+ transform: translateY(-1px) !important;
 
192
  }
193
 
194
  /* Results Section */
195
  .results-container {
196
+ margin-top: 1rem;
197
+ padding: 1rem;
198
+ border-radius: 8px;
 
 
199
  }
200
 
201
  .result-card {
202
+ padding: 1rem;
203
+ border-radius: 8px;
204
+ border-left: 4px solid transparent;
205
  margin-bottom: 1rem;
206
  }
207
 
 
217
 
218
  .prediction-badge {
219
  font-weight: 600;
220
+ font-size: 1rem;
221
+ margin-bottom: 0.5rem;
222
  display: flex;
223
  align-items: center;
224
  gap: 0.5rem;
 
227
  .confidence-score {
228
  font-weight: 600;
229
  margin-left: auto;
230
+ font-size: 1rem;
231
  }
232
 
233
  /* Chart Containers */
234
  .chart-container {
235
+ padding: 1rem;
236
+ border-radius: 8px;
237
+ margin: 1rem 0;
 
 
238
  }
239
 
240
  /* Footer */
241
  .footer {
242
+ margin-top: 2rem;
243
+ padding: 1rem 0;
244
  text-align: center;
245
  border-top: 1px solid #e5e7eb;
246
+ }
247
+
248
+ /* Sidebar Styling */
249
+ .stSidebar {
250
+ background: #ffffff;
251
+ border-right: 1px solid #e5e7eb;
252
+ }
253
+
254
+ .stSidebar .sidebar-content {
255
+ padding: 1rem;
256
  }
257
  </style>
258
  """, unsafe_allow_html=True)
 
328
  )
329
  ])
330
  fig.update_layout(
331
+ title={'text': 'Prediction Confidence', 'x': 0.5, 'xanchor': 'center', 'font': {'size': 18}},
332
+ xaxis=dict(title='Classification', titlefont={'size': 12}, tickfont={'size': 10}),
333
+ yaxis=dict(title='Probability', range=[0, 1], tickformat='.0%', titlefont={'size': 12}, tickfont={'size': 10}),
334
  template='plotly_white',
335
+ height=300,
336
+ margin=dict(t=60, b=60)
337
  )
338
  return fig
339
 
 
355
  )
356
  ])
357
  fig.update_layout(
358
+ title={'text': 'Attention Weights', 'x': 0.5, 'xanchor': 'center', 'font': {'size': 18}},
359
+ xaxis=dict(title='Words', tickangle=45, titlefont={'size': 12}, tickfont={'size': 10}),
360
+ yaxis=dict(title='Attention Score', titlefont={'size': 12}, tickfont={'size': 10}),
361
+ template='plotly_white',
362
+ height=350,
363
+ margin=dict(t=60, b=80)
364
  )
365
  return fig
366
 
367
  def main():
368
+ # Sidebar
369
+ with st.sidebar:
370
+ st.markdown("## TruthCheck Menu")
371
+ st.markdown("Navigate through the options below:")
372
+ st.button("Home", disabled=True)
373
+ st.button("Analyze News", key="nav_analyze")
374
+ st.button("About", key="nav_about")
375
+ st.markdown("---")
376
+ st.markdown("**Contact**")
377
+ st.markdown("📧 [email protected]")
378
+
379
  # Header
380
  st.markdown("""
381
  <div class="header">
 
392
  <div class="hero-left">
393
  <h2 class="hero-title">Instant Fake News Detection</h2>
394
  <p class="hero-text">
395
+ Verify news articles with our AI-powered tool, driven by BERT and BiLSTM for fast and accurate authenticity analysis.
396
  </p>
397
  </div>
398
  <div class="hero-right">
399
+ <img src="hero.png" alt="TruthCheck Illustration">
400
  </div>
401
  </div>
402
  </div>
 
408
  <div class="about-section">
409
  <h2 class="about-title">About TruthCheck</h2>
410
  <p class="about-text">
411
+ TruthCheck uses a hybrid BERT-BiLSTM model to detect fake news with high accuracy. Paste an article below for instant analysis.
412
  </p>
413
  </div>
414
  </div>
 
418
  st.markdown('<div class="container"><div class="input-container">', unsafe_allow_html=True)
419
  news_text = st.text_area(
420
  "Analyze a News Article",
421
+ height=150,
422
  placeholder="Paste your news article here for instant AI analysis...",
423
  key="news_input"
424
  )
 
445
  st.markdown(f'''
446
  <div class="result-card fake-news">
447
  <div class="prediction-badge">🚨 Fake News Detected <span class="confidence-score">{result["confidence"]:.1%}</span></div>
448
+ <p>Our AI has identified this content as likely misinformation based on linguistic patterns and content analysis.</p>
449
  </div>
450
  ''', unsafe_allow_html=True)
451
  else:
452
  st.markdown(f'''
453
  <div class="result-card real-news">
454
  <div class="prediction-badge">✅ Authentic News <span class="confidence-score">{result["confidence"]:.1%}</span></div>
455
+ <p>This content appears to be legitimate based on professional writing style and factual consistency.</p>
456
  </div>
457
  ''', unsafe_allow_html=True)
458