Repository navigation
Expand file tree
/
Copy pathapp.py
More file actions
11869 lines (10607 loc) · 419 KB
/
Copy pathapp.py
File metadata and controls
11869 lines (10607 loc) · 419 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import html
import re
import time
# Added for easier analytics data aggregation
from collections import defaultdict
from datetime import datetime
from io import StringIO
import numpy as np
import pandas as pd
import plotly.express as px
import plotly.graph_objects as go
import streamlit as st
import torch
from transformers import (
AutoModelForSequenceClassification,
AutoTokenizer,
pipeline,
)
import models.redos_guard
import models.rules_simulator
import models.workspace_manager
# --- Streamlit Page Configuration ---
st.set_page_config(
page_title="Spamlyser Pro - Ensemble Edition",
page_icon="🛡️",
layout="wide",
initial_sidebar_state="expanded",
)
# Load unified global styles
try:
from page_functions import load_global_styles
load_global_styles()
except Exception:
pass
# Inject accessibility enhancements and theme manager
try:
from assets.accessibility import inject_accessibility
inject_accessibility()
except ImportError:
pass
try:
from assets.theme_manager import init_theme, inject_theme_toggle
init_theme()
except ImportError:
pass
# Initialize models and check availability
try:
from models.model_init import MODEL_STATUS
if not MODEL_STATUS:
st.warning(
"⚠️ Some AI models may not be fully available. Basic functionality will still work, but advanced features may be limited."
)
except ImportError:
st.warning(
"⚠️ Model initialization module not found. Some features may be limited."
)
# Import required model components with error handling
try:
from models.export_feature import export_results_button
from models.smart_preprocess import normalize_label
from models.text_sanitizer import (
safe_regex_findall,
safe_regex_search,
sanitize_text,
strip_html_unsafe,
validate_sms_message,
)
from models.threat_analyzer import (
THREAT_CATEGORIES,
classify_threat_type,
get_threat_specific_advice,
)
from models.word_analyzer import WordAnalyzer
except ImportError as e:
st.error(f"Error importing model components: {e!s}")
st.info(
"Please ensure all required model files are present in the models directory."
)
# from ensemble_classifier_method import EnsembleSpamClassifier, ModelPerformanceTracker, PredictionResult
# Dummy classes if you don't have the actual files for testing
try:
from models.ensemble_classifier_method import (
EnsembleSpamClassifier,
ModelPerformanceTracker,
PredictionResult,
)
except ImportError:
st.warning(
"`ensemble_classifier_method.py` not found. Using dummy classes. Please provide the actual file for full functionality."
)
class PredictionResult:
def __init__(self, label, score, spam_probability=None):
self.label = label
self.score = score
self.spam_probability = spam_probability
class ModelPerformanceTracker:
def __init__(self):
self.stats = {}
def update_performance(self, model_name, correct):
pass
def get_all_stats(self):
return {}
def save_to_file(self, filename):
pass
class EnsembleSpamClassifier:
def __init__(self, performance_tracker):
self.performance_tracker = performance_tracker
self.default_weights = {
"DistilBERT": 0.25,
"BERT": 0.25,
"RoBERTa": 0.25,
"ALBERT": 0.25,
}
self.model_weights = self.default_weights.copy()
def update_model_weights(self, weights):
self.model_weights.update(weights)
def get_model_weights(self):
return self.model_weights
def get_ensemble_prediction(self, predictions, method):
# Dummy implementation for ensemble prediction
if not predictions:
return {
"label": "UNKNOWN",
"confidence": 0.0,
"spam_probability": 0.0,
"method": method,
"details": "No model predictions",
}
# Simple majority voting for dummy
spam_votes = sum(
1 for p in predictions.values() if p["label"] == "SPAM"
)
ham_votes = sum(
1 for p in predictions.values() if p["label"] == "HAM"
)
if spam_votes > ham_votes:
label = "SPAM"
score = (
sum(
p["score"]
for p in predictions.values()
if p["label"] == "SPAM"
)
/ spam_votes
if spam_votes
else 0
)
spam_prob = score # Simplified
elif ham_votes > spam_votes:
label = "HAM"
score = (
sum(
p["score"]
for p in predictions.values()
if p["label"] == "HAM"
)
/ ham_votes
if ham_votes
else 0
)
spam_prob = 1 - score # Simplified
else: # Tie or no clear majority, default to HAM for safety or SPAM for caution
label = "HAM"
score = 0.5
spam_prob = 0.5
return {
"label": label,
"confidence": score,
"spam_probability": spam_prob,
"method": method,
"details": f"Dummy {method} applied",
}
def get_all_predictions(self, predictions):
# Dummy method to return results for all ensemble methods
dummy_results = {}
for method_key in [
"majority_voting",
"weighted_average",
"confidence_weighted",
"adaptive_threshold",
"meta_ensemble",
]:
dummy_results[method_key] = self.get_ensemble_prediction(
predictions, method_key
)
return dummy_results
# Core Python imports
import re
import time
from rate_limit import check_rate_limit, check_debounce
from io import StringIO
from typing import List
torch.classes.__path__ = []
# Import navigation component
try:
from models.navigation import top_navigation_bar
except ImportError:
def top_navigation_bar():
pass # Silent fallback
# --- Session State Initialization ---
# Initialize all session state variables
if "current_page" not in st.session_state:
st.session_state.current_page = "home"
# Initialize sender reputation tracker
if "sender_reputation" not in st.session_state:
try:
from models.sender_reputation import SenderReputation
st.session_state.sender_reputation = SenderReputation()
except ImportError:
st.session_state.sender_reputation = None
# Navigation function
def navigate_to(page_name):
"""Function to navigate to different pages"""
st.session_state.current_page = page_name
st.rerun()
# Page registry for navigation
PAGES = {
"home": "🏠 Home",
"analyzer": "🔍 SMS Analyzer",
"about": "ℹ️ About",
"features": "⚡ Features",
"analytics": "📊 Analytics",
"trends": "📈 Trend Analytics",
"dashboard": "📈 Dashboard",
"anomaly": "🔍 Anomaly Detection",
"models": "🤖 Models",
"model_compare": "🔄 Compare",
"feedback": "💬 Feedback",
"help": "❓ Help",
"contact": "📞 Contact",
"docs": "📚 Docs",
"api": "🔌 API",
"what_if": "🧪 What-If",
"senders": "👤 Senders",
"benchmarks": "⏱️ Benchmarks",
"settings": "⚙️ Settings",
}
# --- Custom CSS for Styling ---
st.markdown(
"""
<style>
/* Theme-aware base styles */
:root {
--bg-gradient-start: #f5f7fa;
--bg-gradient-end: #eef2f5;
--card-bg: #ffffff;
--card-border: #e0e0e0;
--card-shadow: rgba(0, 0, 0, 0.1);
--text-primary: #333333;
--text-secondary: #666666;
--accent-color: #00d4aa;
--spam-color: #ff4444;
--ham-color: #44bb44;
--hover-scale: 1.02;
--hover-shadow: rgba(0, 0, 0, 0.15);
--hover-glow: rgba(0, 212, 170, 0.3);
}
/* Dark theme overrides */
@media (prefers-color-scheme: dark) {
:root {
--bg-gradient-start: #0f0f0f;
--bg-gradient-end: #1a1a1a;
--card-bg: #1e1e1e;
--card-border: #404040;
--card-shadow: rgba(0, 0, 0, 0.3);
--text-primary: #ffffff;
--text-secondary: #bbbbbb;
--hover-shadow: rgba(0, 0, 0, 0.5);
--hover-glow: rgba(0, 212, 170, 0.4);
}
}
.main {
background: linear-gradient(135deg, var(--bg-gradient-start) 0%, var(--bg-gradient-end) 100%);
color: var(--text-primary);
}
.stApp {
background: linear-gradient(135deg, var(--bg-gradient-start) 0%, var(--bg-gradient-end) 100%);
}
/* Enhanced Button Hover Effects */
.stButton > button {
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
transform-origin: center !important;
position: relative !important;
overflow: hidden !important;
}
.stButton > button:hover {
transform: translateY(-2px) scale(var(--hover-scale)) !important;
box-shadow: 0 8px 25px var(--hover-shadow) !important;
filter: brightness(1.05) !important;
}
.stButton > button:active {
transform: translateY(0) scale(0.98) !important;
transition: all 0.1s ease !important;
}
/* Primary Button Hover Effects */
.stButton > button[kind="primary"]:hover {
background: linear-gradient(45deg, #00d4aa, #00b894) !important;
box-shadow: 0 8px 25px var(--hover-glow) !important;
border-color: #00a085 !important;
}
/* Secondary Button Hover Effects */
.stButton > button[kind="secondary"]:hover {
background: linear-gradient(45deg, #f8f9fa, #e9ecef) !important;
border-color: #00d4aa !important;
color: #00d4aa !important;
box-shadow: 0 8px 25px rgba(0, 212, 170, 0.2) !important;
}
/* Dark theme button hover effects */
@media (prefers-color-scheme: dark) {
.stButton > button[kind="secondary"]:hover {
background: linear-gradient(45deg, #2d2d2d, #404040) !important;
border-color: #00d4aa !important;
color: #00d4aa !important;
}
}
/* Card Styles with Enhanced Hover Effects */
.metric-container, .prediction-card, .ensemble-card, .feature-card,
.model-info, .ensemble-method, .method-comparison {
padding: 20px;
border-radius: 12px;
margin: 15px 0;
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
color: var(--text-primary);
cursor: pointer;
position: relative;
overflow: hidden;
}
.metric-container:hover, .prediction-card:hover, .ensemble-card:hover,
.feature-card:hover, .model-info:hover, .ensemble-method:hover,
.method-comparison:hover {
transform: translateY(-4px) scale(var(--hover-scale));
box-shadow: 0 12px 30px var(--hover-shadow);
border-color: var(--accent-color);
}
/* Light theme card styles */
.metric-container {
background: linear-gradient(145deg, #f0f2f6, #ffffff);
border: 1px solid var(--card-border);
box-shadow: 0 4px 12px var(--card-shadow);
}
.prediction-card {
background: var(--card-bg);
border: 1px solid var(--card-border);
box-shadow: 0 6px 16px var(--card-shadow);
text-align: center;
padding: 25px;
}
.ensemble-card {
background: linear-gradient(145deg, #f0f0ff, #ffffff);
border: 2px solid #6366f1;
}
.spam-alert {
background: linear-gradient(145deg, #fff0f0, #ffffff);
border: 2px solid var(--spam-color);
color: var(--spam-color);
}
.ham-safe {
background: linear-gradient(145deg, #f0fff0, #ffffff);
border: 2px solid var(--ham-color);
color: var(--ham-color);
}
.analysis-header {
background: linear-gradient(90deg, #f0f0f0, #e0e0e0);
padding: 15px;
border-radius: 10px;
margin: 20px 0;
border-left: 4px solid var(--accent-color);
color: var(--text-primary);
transition: all 0.3s ease;
}
.analysis-header:hover {
transform: translateX(5px);
box-shadow: 0 8px 20px var(--hover-shadow);
}
.feature-card {
background: rgba(255, 255, 255, 0.8);
backdrop-filter: blur(10px);
border: 1px solid var(--card-border);
}
.model-info {
background: linear-gradient(145deg, #f0f0f0, #ffffff);
border-left: 4px solid var(--accent-color);
}
.ensemble-method {
background: linear-gradient(145deg, #f0f0ff, #ffffff);
border-left: 4px solid #6366f1;
}
.method-comparison {
background: rgba(255, 255, 255, 0.8);
border: 1px solid var(--card-border);
}
/* Interactive Elements Hover Effects */
.stSelectbox > div > div:hover,
.stTextInput > div > div > input:hover,
.stTextArea > div > div > textarea:hover,
.stSlider > div > div > div:hover {
border-color: var(--accent-color) !important;
box-shadow: 0 0 0 2px rgba(0, 212, 170, 0.2) !important;
transition: all 0.3s ease !important;
}
/* Form Elements Hover Effects */
.stForm > div {
transition: all 0.3s ease;
}
.stForm:hover {
transform: translateY(-2px);
box-shadow: 0 8px 25px var(--hover-shadow);
}
/* Navigation Button Hover Effects */
.stButton > button[data-testid="baseButton-secondary"]:hover {
background: linear-gradient(45deg, #f8f9fa, #e9ecef) !important;
border-color: var(--accent-color) !important;
color: var(--accent-color) !important;
transform: translateY(-2px) scale(1.02) !important;
}
/* Export and Action Button Hover Effects */
.stButton > button:has-text("Export"):hover,
.stButton > button:has-text("Analyze"):hover,
.stButton > button:has-text("Clear"):hover {
background: linear-gradient(45deg, #00d4aa, #00b894) !important;
box-shadow: 0 8px 25px var(--hover-glow) !important;
transform: translateY(-2px) scale(1.02) !important;
}
/* Dark theme overrides */
@media (prefers-color-scheme: dark) {
.metric-container {
background: linear-gradient(145deg, #1e1e1e, #2a2a2a);
border: 1px solid #333;
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}
.prediction-card {
background: linear-gradient(145deg, #1a1a1a, #2d2d2d);
border: 1px solid #404040;
box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4);
}
.ensemble-card {
background: linear-gradient(145deg, #1a1a2a, #2d2d3d);
border: 2px solid #6366f1;
}
.spam-alert {
background: linear-gradient(145deg, #2a1a1a, #3d2626);
border: 2px solid #ff4444;
color: #ff6b6b;
}
.ham-safe {
background: linear-gradient(145deg, #1a2a1a, #263d26);
border: 2px solid #44ff44;
color: #6bff6b;
}
.analysis-header {
background: linear-gradient(90deg, #333, #555);
border-left: 4px solid #00d4aa;
color: #ffffff;
}
.feature-card {
background: rgba(255, 255, 255, 0.05);
border: 1px solid rgba(255, 255, 255, 0.1);
}
.model-info {
background: linear-gradient(145deg, #252525, #3a3a3a);
border-left: 4px solid #00d4aa;
}
.ensemble-method {
background: linear-gradient(145deg, #252545, #3a3a5a);
border-left: 4px solid #6366f1;
}
.method-comparison {
background: rgba(255, 255, 255, 0.03);
border: 1px solid rgba(255, 255, 255, 0.1);
}
.stButton > button[kind="secondary"]:hover {
background: linear-gradient(45deg, #2d2d2d, #404040) !important;
border-color: #00d4aa !important;
color: #00d4aa !important;
}
}
/* Special hover effects for specific button types */
.stButton > button[aria-label*="Analyze"]:hover,
.stButton > button[aria-label*="Start"]:hover {
background: linear-gradient(45deg, #00d4aa, #00b894) !important;
box-shadow: 0 8px 25px var(--hover-glow) !important;
transform: translateY(-3px) scale(1.03) !important;
}
.stButton > button[aria-label*="Export"]:hover,
.stButton > button[aria-label*="Download"]:hover {
background: linear-gradient(45deg, #6366f1, #4f46e5) !important;
box-shadow: 0 8px 25px rgba(99, 102, 241, 0.3) !important;
transform: translateY(-2px) scale(1.02) !important;
}
.stButton > button[aria-label*="Clear"]:hover,
.stButton > button[aria-label*="Reset"]:hover {
background: linear-gradient(45deg, #ef4444, #dc2626) !important;
box-shadow: 0 8px 25px rgba(239, 68, 68, 0.3) !important;
transform: translateY(-2px) scale(1.02) !important;
}
/* Smooth transitions for all interactive elements */
* {
transition: all 0.2s ease !important;
}
/* Remove transition from elements that shouldn't have it */
.stMarkdown, .stText, .stMetric, .stDataFrame {
transition: none !important;
}
/* Additional Streamlit-specific button targeting */
div[data-testid="stButton"] > button:hover,
.stButton > button:hover,
button[data-testid="baseButton-primary"]:hover,
button[data-testid="baseButton-secondary"]:hover {
transform: translateY(-2px) scale(1.02) !important;
box-shadow: 0 8px 25px var(--hover-shadow) !important;
filter: brightness(1.05) !important;
}
/* Ensure form submit buttons have hover effects */
.stForm > div > div > button:hover {
transform: translateY(-2px) scale(1.02) !important;
box-shadow: 0 8px 25px var(--hover-glow) !important;
}
/* Download button hover effects */
.stDownloadButton > button:hover {
background: linear-gradient(45deg, #6366f1, #4f46e5) !important;
box-shadow: 0 8px 25px rgba(99, 102, 241, 0.3) !important;
transform: translateY(-2px) scale(1.02) !important;
}
/* File uploader hover effects */
.stFileUploader > div:hover {
border-color: var(--accent-color) !important;
box-shadow: 0 0 0 2px rgba(0, 212, 170, 0.2) !important;
}
/* Radio button hover effects */
.stRadio > div > label:hover {
background-color: rgba(0, 212, 170, 0.1) !important;
border-radius: 8px !important;
transition: all 0.3s ease !important;
}
/* Checkbox hover effects */
.stCheckbox > label:hover {
background-color: rgba(0, 212, 170, 0.1) !important;
border-radius: 8px !important;
transition: all 0.3s ease !important;
}
/* Number input hover effects */
.stNumberInput > div > div > input:hover {
border-color: var(--accent-color) !important;
box-shadow: 0 0 0 2px rgba(0, 212, 170, 0.2) !important;
}
/* Date input hover effects */
.stDateInput > div > div > input:hover {
border-color: var(--accent-color) !important;
box-shadow: 0 0 0 2px rgba(0, 212, 170, 0.2) !important;
}
/* Time input hover effects */
.stTimeInput > div > div > input:hover {
border-color: var(--accent-color) !important;
box-shadow: 0 0 0 2px rgba(0, 212, 170, 0.2) !important;
}
/* Color picker hover effects */
.stColorPicker > div > div:hover {
border-color: var(--accent-color) !important;
box-shadow: 0 0 0 2px rgba(0, 212, 170, 0.2) !important;
}
/* Multiselect hover effects */
.stMultiSelect > div > div:hover {
border-color: var(--accent-color) !important;
box-shadow: 0 0 0 2px rgba(0, 212, 170, 0.2) !important;
}
/* Expander hover effects */
.stExpander > div > div:hover {
background-color: rgba(0, 212, 170, 0.05) !important;
border-radius: 8px !important;
transition: all 0.3s ease !important;
}
/* Tabs hover effects */
.stTabs > div > div > div > button:hover {
background-color: rgba(0, 212, 170, 0.1) !important;
border-radius: 8px !important;
transform: translateY(-1px) !important;
}
/* Sidebar hover effects and scrolling fix */
.stSidebar > div:hover {
box-shadow: 0 4px 12px var(--hover-shadow) !important;
}
/* Ensure sidebar can scroll properly */
.stSidebar {
overflow-y: auto !important;
overflow-x: hidden !important;
position: relative !important;
z-index: 999 !important;
}
.stSidebar > div {
overflow-y: auto !important;
overflow-x: hidden !important;
height: 100vh !important;
max-height: 100vh !important;
}
/* Progress bar hover effects */
.stProgress > div:hover {
box-shadow: 0 0 10px var(--hover-glow) !important;
}
/* Balloons animation enhancement */
.stBalloons {
animation: bounce 0.6s ease-in-out !important;
}
@keyframes bounce {
0%, 20%, 50%, 80%, 100% {
transform: translateY(0);
}
40% {
transform: translateY(-10px);
}
60% {
transform: translateY(-5px);
}
}
/* Success/Error message hover effects */
.stSuccess:hover,
.stError:hover,
.stWarning:hover,
.stInfo:hover {
transform: translateY(-2px) !important;
box-shadow: 0 8px 25px var(--hover-shadow) !important;
}
/* Container hover effects */
.stContainer:hover {
transform: translateY(-1px) !important;
box-shadow: 0 4px 12px var(--hover-shadow) !important;
}
/* Minimal fix for overlapping issues - only for dashboard elements */
.stTooltip {
z-index: 9999 !important;
position: fixed !important;
}
/* Fix only dashboard-specific elements */
.metric-container {
position: relative !important;
z-index: 1 !important;
margin: 10px 0 !important;
}
/* Fix column layout for dashboard cards */
.stColumns {
display: flex !important;
flex-wrap: wrap !important;
gap: 10px !important;
margin: 0 !important;
padding: 0 !important;
}
.stColumns > div {
flex: 1 !important;
min-width: 0 !important;
margin: 0 !important;
padding: 0 !important;
}
/* Dashboard container fixes */
.dashboard-content {
position: relative !important;
z-index: 1 !important;
margin: 20px 0 !important;
}
.dashboard-tabs-container {
position: relative !important;
z-index: 1 !important;
margin: 20px 0 !important;
}
.dashboard-tab-content {
position: relative !important;
z-index: 1 !important;
margin: 20px 0 !important;
padding: 10px 0 !important;
}
/* Smooth scrolling for navigation */
html {
scroll-behavior: smooth !important;
}
/* Content sections for navigation */
.content-section {
scroll-margin-top: 100px !important;
padding: 20px 0 !important;
}
/* Navigation button scroll effects */
.nav-scroll-button {
transition: all 0.3s ease !important;
cursor: pointer !important;
}
.nav-scroll-button:hover {
transform: translateY(-2px) !important;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15) !important;
}
/* Active button styling */
.stButton > button:active,
.stButton > button:focus {
background-color: #4ecdc4 !important;
color: #ffffff !important;
border: 2px solid #4ecdc4 !important;
box-shadow: 0 0 10px rgba(78, 205, 196, 0.5) !important;
}
/* Clicked button styling */
.nav-button-clicked {
background-color: #4ecdc4 !important;
color: #ffffff !important;
border: 2px solid #4ecdc4 !important;
box-shadow: 0 0 10px rgba(78, 205, 196, 0.5) !important;
}
</style>
""",
unsafe_allow_html=True,
)
# Add JavaScript for button click styling
st.markdown(
"""
<script>
function handleNavClick(buttonId) {
// Remove clicked class from all nav buttons
document.querySelectorAll('.nav-button').forEach(btn => {
btn.classList.remove('nav-button-clicked');
});
// Add clicked class to the clicked button
const button = document.querySelector(`[data-testid="${buttonId}"]`);
if (button) {
button.classList.add('nav-button-clicked');
}
}
</script>
""",
unsafe_allow_html=True,
)
# --- Page Functions ---
def show_home_page():
"""Beautiful and comprehensive home page"""
# Hero Section
st.markdown(
"""
<div style="
text-align: center;
padding: 40px 20px;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
border-radius: 20px;
margin-bottom: 40px;
box-shadow: 0 10px 30px rgba(102, 126, 234, 0.4);
color: white;
">
<h1 style="
font-size: 4rem;
margin: 0 0 20px 0;
text-shadow: 0 0 30px rgba(255,255,255,0.3);
font-weight: 700;
">
🛡️ Spamlyser Pro
</h1>
<h2 style="
font-size: 1.8rem;
margin: 0 0 30px 0;
opacity: 0.9;
font-weight: 400;
">
Advanced AI-Powered SMS Threat Detection System
</h2>
<p style="
font-size: 1.2rem;
margin: 0;
opacity: 0.8;
max-width: 600px;
margin: 0 auto;
line-height: 1.6;
">
Protect yourself from malicious SMS messages using cutting-edge machine learning models and ensemble AI technology.
</p>
</div>
""",
unsafe_allow_html=True,
)
# Quick Action Buttons
st.markdown("### 🚀 Quick Actions")
col_btn1, col_btn2, col_btn3, col_btn4 = st.columns(4)
with col_btn1:
if st.button(
"🔍 Start Analysis",
type="primary",
use_container_width=True,
help="Analyze SMS messages for threats",
):
navigate_to("analyzer")
with col_btn2:
if st.button(
"📊 Analytics",
use_container_width=True,
help="View performance metrics",
):
navigate_to("analytics")
with col_btn3:
if st.button(
"⚡ Features",
use_container_width=True,
help="Explore all features",
):
navigate_to("features")
with col_btn4:
if st.button(
"ℹ️ About",
use_container_width=True,
help="Learn more about Spamlyser",
):
navigate_to("about")
st.markdown("---")
# Feature Showcase
st.markdown("### 🌟 Why Choose Spamlyser Pro?")
col1, col2 = st.columns(2)
with col1:
st.markdown(
"""
<div style="
background: linear-gradient(135deg, #ff9a9e 0%, #fecfef 100%);
padding: 25px;
border-radius: 15px;
margin-bottom: 20px;
box-shadow: 0 5px 15px rgba(255, 154, 158, 0.3);
">
<h3 style="color: #fff; margin: 0 0 15px 0;">🤖 AI-Powered Detection</h3>
<p style="color: #fff; margin: 0; opacity: 0.9; line-height: 1.6;">
Uses state-of-the-art transformer models including BERT, RoBERTa, DistilBERT, and ALBERT
for maximum accuracy in threat detection.
</p>
</div>
""",
unsafe_allow_html=True,
)
st.markdown(
"""
<div style="
background: linear-gradient(135deg, #a8edea 0%, #fed6e3 100%);
padding: 25px;
border-radius: 15px;
margin-bottom: 20px;
box-shadow: 0 5px 15px rgba(168, 237, 234, 0.3);
">
<h3 style="color: #333; margin: 0 0 15px 0;">⚡ Real-Time Analysis</h3>
<p style="color: #333; margin: 0; opacity: 0.8; line-height: 1.6;">
Get instant results with lightning-fast processing. Analyze SMS messages
in milliseconds with our optimized AI pipeline.
</p>
</div>
""",
unsafe_allow_html=True,
)
with col2:
st.markdown(
"""
<div style="
background: linear-gradient(135deg, #ffecd2 0%, #fcb69f 100%);
padding: 25px;
border-radius: 15px;
margin-bottom: 20px;
box-shadow: 0 5px 15px rgba(255, 236, 210, 0.3);
">
<h3 style="color: #333; margin: 0 0 15px 0;">🔒 Advanced Security</h3>
<p style="color: #333; margin: 0; opacity: 0.8; line-height: 1.6;">
Comprehensive threat classification including phishing, fraud, malware,
and social engineering attack detection.
</p>
</div>
""",
unsafe_allow_html=True,
)
st.markdown(
"""
<div style="
background: linear-gradient(135deg, #d299c2 0%, #fef9d7 100%);
padding: 25px;
border-radius: 15px;