Spaces:
Sleeping
Sleeping
Update src/app.py
Browse files- 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
|
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: #
|
54 |
min-height: 100vh;
|
55 |
color: #1a202c;
|
56 |
}
|
57 |
|
58 |
-
/*
|
59 |
-
#MainMenu {visibility:
|
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:
|
68 |
margin: 0 auto;
|
69 |
-
padding:
|
70 |
}
|
71 |
|
72 |
/* Header */
|
73 |
.header {
|
74 |
-
|
75 |
-
|
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:
|
96 |
-
margin-bottom:
|
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:
|
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:
|
129 |
-
font-weight:
|
130 |
color: #1a202c;
|
131 |
-
margin-bottom:
|
132 |
-
line-height: 1.2;
|
133 |
}
|
134 |
|
135 |
.hero-text {
|
136 |
-
font-size:
|
137 |
color: #4a5568;
|
138 |
-
line-height: 1.
|
139 |
-
max-width:
|
140 |
}
|
141 |
|
142 |
/* About Section */
|
143 |
.about-section {
|
144 |
-
margin-bottom:
|
145 |
text-align: center;
|
146 |
-
padding: 2rem;
|
147 |
}
|
148 |
|
149 |
.about-title {
|
150 |
-
font-size:
|
151 |
-
font-weight:
|
152 |
color: #1a202c;
|
153 |
-
margin-bottom:
|
154 |
}
|
155 |
|
156 |
.about-text {
|
157 |
-
font-size:
|
158 |
color: #4a5568;
|
159 |
-
line-height: 1.
|
160 |
-
max-width:
|
161 |
margin: 0 auto;
|
162 |
}
|
163 |
|
164 |
/* Input Section */
|
165 |
.input-container {
|
166 |
-
max-width:
|
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:
|
176 |
border: 1px solid #d1d5db !important;
|
177 |
-
padding:
|
178 |
font-size: 1rem !important;
|
179 |
font-family: 'Inter', sans-serif !important;
|
180 |
-
background: #
|
181 |
-
min-height:
|
182 |
-
transition: all 0.
|
183 |
}
|
184 |
|
185 |
.stTextArea > div > div > textarea:focus {
|
186 |
border-color: #6366f1 !important;
|
187 |
-
box-shadow: 0 0 0
|
188 |
outline: none !important;
|
189 |
}
|
190 |
|
@@ -194,38 +174,34 @@ st.markdown("""
|
|
194 |
|
195 |
/* Button Styling */
|
196 |
.stButton > button {
|
197 |
-
background:
|
198 |
color: white !important;
|
199 |
-
border-radius:
|
200 |
-
padding: 0.
|
201 |
-
font-size:
|
202 |
font-weight: 600 !important;
|
203 |
font-family: 'Inter', sans-serif !important;
|
204 |
-
transition: all 0.
|
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:
|
212 |
-
transform: translateY(-
|
213 |
-
box-shadow: 0 6px 16px rgba(99, 102, 241, 0.4) !important;
|
214 |
}
|
215 |
|
216 |
/* Results Section */
|
217 |
.results-container {
|
218 |
-
margin-top:
|
219 |
-
padding:
|
220 |
-
|
221 |
-
border-radius: 12px;
|
222 |
-
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
|
223 |
}
|
224 |
|
225 |
.result-card {
|
226 |
-
padding:
|
227 |
-
border-radius:
|
228 |
-
border-left:
|
229 |
margin-bottom: 1rem;
|
230 |
}
|
231 |
|
@@ -241,8 +217,8 @@ st.markdown("""
|
|
241 |
|
242 |
.prediction-badge {
|
243 |
font-weight: 600;
|
244 |
-
font-size:
|
245 |
-
margin-bottom:
|
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:
|
255 |
}
|
256 |
|
257 |
/* Chart Containers */
|
258 |
.chart-container {
|
259 |
-
padding:
|
260 |
-
border-radius:
|
261 |
-
|
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:
|
269 |
-
padding:
|
270 |
text-align: center;
|
271 |
border-top: 1px solid #e5e7eb;
|
272 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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':
|
349 |
-
xaxis=dict(title='Classification', titlefont={'size':
|
350 |
-
yaxis=dict(title='Probability', range=[0, 1], tickformat='.0%', titlefont={'size':
|
351 |
template='plotly_white',
|
352 |
-
height=
|
353 |
-
margin=dict(t=
|
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':
|
376 |
-
xaxis=dict(title='Words', tickangle=45, titlefont={'size':
|
377 |
-
yaxis=dict(title='Attention Score', titlefont={'size':
|
378 |
-
template='plotly_white
|
379 |
-
height=
|
380 |
-
margin=dict(t=
|
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 |
-
|
402 |
</p>
|
403 |
</div>
|
404 |
<div class="hero-right">
|
405 |
-
<img src="
|
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
|
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=
|
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
|
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
|
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 |
|