-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.py
More file actions
3060 lines (2796 loc) · 175 KB
/
Copy pathapp.py
File metadata and controls
3060 lines (2796 loc) · 175 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 streamlit as st
import pickle
import numpy as np
import pandas as pd
import os
import plotly.graph_objects as go
# ═══════════════════════════════════════════════
# PAGE CONFIG
# ═══════════════════════════════════════════════
st.set_page_config(
page_title="ShopSense AI · E-Commerce Intelligence",
page_icon="",
layout="wide",
initial_sidebar_state="expanded"
)
# ═══════════════════════════════════════════════
# GLOBAL CSS
# ═══════════════════════════════════════════════
st.markdown("""
<style>
@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:wght@400;700;900&family=DM+Sans:wght@300;400;500;600&family=Space+Mono:wght@400;700&display=swap');
:root {
--bg:#0A0A0F; --bg2:#12121A; --bg3:#1A1A26; --border:#2A2A3E;
--accent1:#8B5CF6; --accent2:#EC4899; --accent3:#06B6D4;
--gold:#F59E0B; --success:#10B981; --danger:#EF4444;
--text:#E8E8F0; --muted:#6B7280; --card-bg:rgba(26,26,38,0.95);
}
html, body, [class*="css"] { font-family: 'DM Sans', sans-serif; color: var(--text); }
.stApp { background: var(--bg); }
#MainMenu, footer, header { visibility: hidden; }
.block-container { padding: 0 2rem 2rem 2rem; max-width: 1400px; }
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--accent1); border-radius: 3px; }
[data-testid="stSidebar"] { background: var(--bg2) !important; border-right: 1px solid var(--border); }
[data-testid="stSidebar"] * { color: var(--text) !important; }
[data-testid="stSidebar"] .stButton > button {
display: flex !important; align-items: center !important; gap: 10px !important;
width: 100% !important; padding: 10px 14px !important; border-radius: 10px !important;
margin: 2px 0 !important; cursor: pointer !important; border: 1px solid transparent !important;
font-size: 0.88em !important; font-weight: 400 !important; color: #6B7280 !important;
background: transparent !important; box-shadow: none !important; text-align: left !important;
justify-content: flex-start !important; letter-spacing: 0 !important;
transition: all 0.2s ease !important; min-height: unset !important; height: auto !important;
}
[data-testid="stSidebar"] .stButton > button:hover {
background: rgba(139,92,246,0.08) !important; border-color: rgba(139,92,246,0.25) !important;
color: #E8E8F0 !important; transform: none !important; box-shadow: none !important;
}
[data-testid="stSidebar"] * { color: var(--text) !important; }
/* ── SIDEBAR TOUJOURS VISIBLE ── */
[data-testid="collapsedControl"] { display: none !important; }
[data-testid="stSidebarCollapsedControl"] { display: none !important; }
section[data-testid="stSidebar"] {
min-width: 260px !important;
max-width: 260px !important;
transform: none !important;
visibility: visible !important;
}
[data-testid="stSidebar"] .nav-active .stButton > button {
background: linear-gradient(135deg,rgba(139,92,246,0.18),rgba(236,72,153,0.09)) !important;
border-color: rgba(139,92,246,0.5) !important; color: #E8E8F0 !important; font-weight: 600 !important;
}
.hero {
background: radial-gradient(ellipse at 30% 50%, #8B5CF620 0%, transparent 60%),
radial-gradient(ellipse at 70% 20%, #EC489915 0%, transparent 60%),
linear-gradient(135deg, #0A0A0F 0%, #12121A 100%);
border: 1px solid var(--border); border-radius: 20px;
padding: 60px 50px; margin-bottom: 30px; position: relative; overflow: hidden;
}
.hero::before {
content: ''; position: absolute; top: -50%; left: -50%; width: 200%; height: 200%;
background: repeating-linear-gradient(45deg, transparent, transparent 30px,
rgba(139,92,246,0.02) 30px, rgba(139,92,246,0.02) 31px);
pointer-events: none;
}
.hero-badge {
display: inline-block;
background: linear-gradient(135deg, rgba(139,92,246,0.2), rgba(236,72,153,0.13));
border: 1px solid rgba(139,92,246,0.4); color: var(--accent1);
padding: 6px 16px; border-radius: 20px; font-size: 0.78em; font-weight: 600;
letter-spacing: 1.5px; text-transform: uppercase; margin-bottom: 20px;
font-family: 'Space Mono', monospace;
}
.hero h1 {
font-family: 'Playfair Display', serif; font-size: 3.2em; font-weight: 900;
line-height: 1.1; margin: 0 0 16px 0;
background: linear-gradient(135deg, #fff 30%, #8B5CF6 70%, #EC4899);
-webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}
.hero p { font-size: 1.05em; color: var(--muted); line-height: 1.7; max-width: 600px; margin: 0; }
.card {
background: var(--card-bg); border: 1px solid var(--border);
border-radius: 16px; padding: 24px; margin-bottom: 20px;
position: relative; overflow: hidden;
}
.card::before {
content: ''; position: absolute; top: 0; left: 0; right: 0; height: 2px;
background: linear-gradient(90deg, var(--accent1), var(--accent2), var(--accent3));
}
.nav-active { display: block; }
.fb-btn > div > button {
background: transparent !important; border: 1px solid rgba(42,42,62,0.5) !important;
color: #4B5563 !important; font-size: 0.72em !important; padding: 4px 10px !important;
font-weight: 400 !important; box-shadow: none !important; min-height: unset !important;
height: auto !important; letter-spacing: 0 !important; margin-top: 2px !important;
border-radius: 6px !important;
}
.sec-title { font-family: 'Playfair Display', serif; font-size: 1.9em; font-weight: 700; color: #fff; margin: 0 0 6px 0; }
.sec-sub { color: var(--muted); font-size: 0.9em; margin-bottom: 24px; line-height: 1.6; }
.styled-table { width: 100%; border-collapse: collapse; font-size: 0.88em; }
.styled-table th { background: var(--bg3); color: var(--accent1); padding: 12px 16px;
text-align: left; font-family: 'Space Mono', monospace; font-size: 0.78em;
letter-spacing: 0.5px; border-bottom: 1px solid var(--border); }
.styled-table td { padding: 11px 16px; color: var(--text); border-bottom: 1px solid rgba(42,42,62,0.3); }
.styled-table tr:hover td { background: var(--bg3); }
.main-btn > div > button,
.stButton > button {
background: linear-gradient(135deg, var(--accent1), var(--accent2)) !important;
color: white !important; border: none !important; border-radius: 12px !important;
padding: 14px 28px !important; font-weight: 600 !important; font-size: 1em !important;
letter-spacing: 0.5px !important; box-shadow: 0 8px 30px rgba(139,92,246,0.3) !important;
transition: all 0.3s ease !important;
}
.stButton > button:hover { transform: translateY(-2px) !important; box-shadow: 0 12px 40px rgba(139,92,246,0.45) !important; }
.fancy-divider { height: 1px; background: linear-gradient(90deg, transparent, rgba(139,92,246,0.3), rgba(236,72,153,0.3), transparent); margin: 32px 0; }
.tl-item { display: flex; gap: 16px; padding: 0 0 24px 0; position: relative; }
.tl-item::before { content: ''; position: absolute; left: 19px; top: 40px; bottom: 0; width: 1px; background: var(--border); }
.tl-item:last-child::before { display: none; }
.tl-dot { width: 38px; height: 38px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 1em; flex-shrink: 0; border: 2px solid var(--border); background: var(--bg2); z-index: 1; }
.tl-content h4 { margin: 6px 0 4px 0; font-size: 0.93em; color: #fff; font-weight: 600; }
.tl-content p { margin: 0; font-size: 0.82em; color: var(--muted); line-height: 1.5; }
.concl-item { display: flex; gap: 14px; align-items: flex-start; padding: 14px 0; border-bottom: 1px solid rgba(42,42,62,0.4); }
.concl-item:last-child { border-bottom: none; }
.concl-icon { width: 38px; height: 38px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 1.1em; flex-shrink: 0; background: var(--bg2); }
.concl-text h4 { margin: 0 0 4px 0; font-size: 0.92em; color: #fff; }
.concl-text p { margin: 0; font-size: 0.82em; color: var(--muted); line-height: 1.5; }
</style>
""", unsafe_allow_html=True)
# ═══════════════════════════════════════════════
# LOAD MODELS
# ═══════════════════════════════════════════════
BASE_DIR = os.path.dirname(__file__)
@st.cache_resource
def load_assets():
def _open(name):
path = os.path.join(BASE_DIR, "model", name)
return pickle.load(open(path, "rb"))
load_errors = {}
models = scaler = feature_cols = scaled_cols = None
try:
models = _open("models.pkl")
except Exception as e:
load_errors["models.pkl"] = str(e)
try:
scaler = _open("scaler.pkl")
except Exception as e:
load_errors["scaler.pkl"] = str(e)
try:
feature_cols = _open("feature_columns.pkl")
except Exception as e:
load_errors["feature_columns.pkl"] = str(e)
try:
scaled_cols = _open("scaled_columns.pkl")
except Exception as e:
load_errors["scaled_columns.pkl"] = str(e)
full_ok = (models is not None and scaler is not None
and feature_cols is not None and scaled_cols is not None)
if full_ok or models is not None:
models_ok = True
else:
models_ok = False
return models, scaler, feature_cols, scaled_cols, models_ok, load_errors
_assets = load_assets()
(models, scaler, feature_cols, scaled_cols, models_ok, _load_errors) = _assets
# ✅ Pipeline complet si les 4 fichiers sont présents
pipeline_ok = (models is not None and scaler is not None
and feature_cols is not None and scaled_cols is not None)
# ═══════════════════════════════════════════════
# PAGES DEFINITION
# ═══════════════════════════════════════════════
PAGES = [
("01", "Accueil"),
("02", "Exploration des Données"),
("03", "Modélisation ML"),
("04", "Non Supervisé"),
("05", "Prédiction"),
("06", "Explication IA"),
("07", "Valeur Ajoutée"),
("08", "Conclusion"),
]
# ═══════════════════════════════════════════════
# SIDEBAR
# ═══════════════════════════════════════════════
if "page" not in st.session_state:
st.session_state.page = 0
with st.sidebar:
st.markdown("""
<div style='padding:20px 10px 10px 10px;'>
<div style='font-family:"Space Mono",monospace;font-size:0.62em;color:#4B5563;
letter-spacing:2px;text-transform:uppercase;'>v1.0 · BSDSI 2026</div>
<div style='font-family:"Playfair Display",serif;font-size:1.6em;font-weight:900;
margin-top:4px;background:linear-gradient(135deg,#8B5CF6,#EC4899);
-webkit-background-clip:text;-webkit-text-fill-color:transparent;'>
ShopSense AI
</div>
</div>
<div style='height:1px;background:linear-gradient(90deg,transparent,#2A2A3E,transparent);
margin:10px 0 16px 0;'></div>
<div style='font-family:"Space Mono",monospace;font-size:0.62em;color:#4B5563;
letter-spacing:2px;text-transform:uppercase;padding:0 10px 10px 10px;'>
NAVIGATION
</div>
""", unsafe_allow_html=True)
for i, (icon, label) in enumerate(PAGES):
is_active = st.session_state.page == i
if is_active:
st.markdown("<div class='nav-active'>", unsafe_allow_html=True)
if st.button(f"{icon} {label}", key=f"nav_btn_{i}", use_container_width=True):
st.session_state.page = i
st.rerun()
if is_active:
st.markdown("</div>", unsafe_allow_html=True)
st.markdown("""
<div style='height:1px;background:linear-gradient(90deg,transparent,#2A2A3E,transparent);
margin:16px 0;'></div>
<div style='padding:0 10px;font-family:"Space Mono",monospace;font-size:0.63em;
color:#374151;line-height:1.8;'>
BEN ZHIR Wafa<br>IKSOD Salma<br>
<span style='color:#4B5563;'>Enc. AIT BAHA Tarek</span>
</div>
""", unsafe_allow_html=True)
# ── Statut pipeline ──────────────────────────────────────
if pipeline_ok:
st.markdown("""
<div style='margin:10px 10px 0 10px;padding:8px 10px;
background:rgba(16,185,129,0.08);
border:1px solid rgba(16,185,129,0.3);border-radius:8px;'>
<div style='font-family:"Space Mono",monospace;font-size:0.6em;
color:#10B981;letter-spacing:1px;'>PIPELINE COMPLET ✓</div>
<div style='font-size:0.7em;color:#6B7280;margin-top:2px;'>
models + scaler + features ✓
</div>
</div>""", unsafe_allow_html=True)
elif models_ok:
st.markdown("""
<div style='margin:10px 10px 0 10px;padding:8px 10px;
background:rgba(245,158,11,0.08);
border:1px solid rgba(245,158,11,0.3);border-radius:8px;'>
<div style='font-family:"Space Mono",monospace;font-size:0.6em;
color:#F59E0B;letter-spacing:1px;'>MODE APPROX.</div>
<div style='font-size:0.7em;color:#6B7280;margin-top:2px;'>
scaler/features manquants
</div>
</div>""", unsafe_allow_html=True)
if _load_errors:
for fname, err in _load_errors.items():
st.markdown(
f"<div style='margin:4px 10px;padding:6px 8px;"
f"background:rgba(239,68,68,0.06);border-radius:6px;"
f"font-size:0.62em;color:#EF4444;font-family:monospace;'>"
f"<strong>{fname}</strong><br>{err[:80]}</div>",
unsafe_allow_html=True)
else:
st.markdown("""
<div style='margin:10px 10px 0 10px;padding:8px 10px;
background:rgba(239,68,68,0.08);
border:1px solid rgba(239,68,68,0.3);border-radius:8px;'>
<div style='font-family:"Space Mono",monospace;font-size:0.6em;
color:#EF4444;letter-spacing:1px;'>AUCUN MODELE</div>
<div style='font-size:0.7em;color:#6B7280;margin-top:2px;'>
model/models.pkl introuvable
</div>
</div>""", unsafe_allow_html=True)
PAGE = st.session_state.page
# ══════════════════════════════════════════════════════════════
# HELPERS
# ══════════════════════════════════════════════════════════════
def sentiment_quick(text):
pos = ["love","great","amazing","perfect","beautiful","excellent","wonderful",
"fantastic","adorable","best","comfortable","flattering","soft","gorgeous",
"cute","nice","happy","fits","quality","lovely","pretty"]
neg = ["hate","terrible","awful","horrible","bad","poor","ugly","worst",
"uncomfortable","disappointing","waste","return","cheap","stiff",
"scratchy","tight","loose","ruined","small","large","boring"]
t = text.lower()
p = sum(1 for w in pos if w in t)
n = sum(1 for w in neg if w in t)
if p > n: return "Positif 😊", "#10B981", p / (p + n + 0.1)
if n > p: return "Négatif 😞", "#EF4444", n / (p + n + 0.1)
return "Neutre 😐", "#F59E0B", 0.5
def preprocess(review, rating, feedback, age,
division="General", department="Tops", class_name="Blouses"):
"""
Reconstruit EXACTEMENT le vecteur X du notebook :
- TextBlob pour polarity et subjectivity
- review_length en nombre de mots
- One-Hot Encoding pour Division, Department, Class
- StandardScaler sur les 6 colonnes numériques
- Ordre des colonnes identique à feature_cols sauvegardé
"""
if not pipeline_ok:
return None, "none"
try:
from textblob import TextBlob
blob = TextBlob(str(review))
polarity = blob.sentiment.polarity
subjectivity = blob.sentiment.subjectivity
review_length = len(str(review).split())
# Construire un dict avec TOUTES les colonnes initialisées à False/0
row = {}
for col in feature_cols:
row[col] = False
# Colonnes numériques (avant scaling)
row["Age"] = float(age)
row["Rating"] = float(rating)
row["Positive Feedback Count"] = float(feedback)
row["review_length"] = float(review_length)
row["polarity"] = float(polarity)
row["subjectivity"] = float(subjectivity)
# Clothing ID — valeur médiane du dataset
if "Clothing ID" in feature_cols:
row["Clothing ID"] = 936.0
# One-Hot Encoding — Division Name
div_col = f"Division Name_{division}"
if div_col in feature_cols:
row[div_col] = True
# One-Hot Encoding — Department Name
dept_col = f"Department Name_{department}"
if dept_col in feature_cols:
row[dept_col] = True
# One-Hot Encoding — Class Name
class_col = f"Class Name_{class_name}"
if class_col in feature_cols:
row[class_col] = True
# Créer le DataFrame dans le bon ordre
X_df = pd.DataFrame([row], columns=feature_cols)
# Appliquer StandardScaler sur les 6 colonnes numériques
X_df[scaled_cols] = scaler.transform(X_df[scaled_cols])
return X_df.values, "full"
except Exception:
return None, "none"
def predict_manual(review, rating, feedback, age):
"""Fallback uniquement si les fichiers pkl sont manquants."""
import math
try:
from textblob import TextBlob
polarity = TextBlob(str(review)).sentiment.polarity
except Exception:
polarity = 0.0
review_length = len(str(review).split())
rating_norm = (rating - 4.2) / 1.11
polarity_norm = (polarity - 0.28) / 0.22
feedback_norm = (min(feedback, 10) - 2.54) / 5.70
length_norm = (min(review_length, 50) - 20) / 15
score = (rating_norm * 0.79
+ polarity_norm * 0.21
+ feedback_norm * 0.03
+ length_norm * 0.02)
proba = 1 / (1 + math.exp(-score * 3.5))
proba = round(max(0.02, min(0.98, proba)), 4)
return int(proba >= 0.5), proba
def proba_bar_html(value, color, label="Probabilité de succès"):
pct = int(value * 100)
return f"""
<div style='margin:14px 0;'>
<div style='display:flex;justify-content:space-between;
font-family:"Space Mono",monospace;font-size:0.8em;margin-bottom:6px;'>
<span style='color:#9CA3AF;'>{label}</span>
<span style='color:{color};font-weight:700;'>{pct}%</span>
</div>
<div style='background:#1A1A26;border-radius:4px;height:8px;overflow:hidden;'>
<div style='width:{pct}%;height:100%;border-radius:4px;background:{color};'></div>
</div>
</div>"""
PLOTLY_BASE = dict(
paper_bgcolor="rgba(0,0,0,0)", plot_bgcolor="rgba(0,0,0,0)",
font=dict(color="#6B7280"), margin=dict(t=50, b=20, l=20, r=20),
)
# ══════════════════════════════════════════════════════════════
# PAGE 0 — ACCUEIL
# ══════════════════════════════════════════════════════════════
if PAGE == 0:
st.markdown("""
<div class='hero'>
<div class='hero-badge'>✦ Machine Learning · NLP · E-Commerce</div>
<h1>Prédiction du Succès<br>des Produits E-Commerce</h1>
<p>Un système d'intelligence artificielle supervisé qui analyse les avis clients,
les notes et les métadonnées produits pour prédire si un article sera recommandé —
avec explications SHAP en temps réel.</p>
</div>
""", unsafe_allow_html=True)
c1, c2, c3, c4 = st.columns(4)
for col, (num, lbl, clr) in zip([c1, c2, c3, c4], [
("23,486", "Avis analysés", "#8B5CF6"),
("82.6%", "Taux recommandation","#10B981"),
("93.7%", "Accuracy modèle", "#06B6D4"),
("3", "Modèles comparés", "#F59E0B"),
]):
with col:
st.markdown(f"""
<div class='card' style='text-align:center;padding:28px 16px;'>
<div style='font-family:"Space Mono",monospace;font-size:2em;font-weight:700;color:{clr};'>{num}</div>
<div style='color:#6B7280;font-size:0.8em;margin-top:6px;'>{lbl}</div>
</div>""", unsafe_allow_html=True)
st.markdown("<div class='fancy-divider'></div>", unsafe_allow_html=True)
# ── LIGNE 1 : À propos | Technologies ────────────────────────────
col_l, col_r = st.columns([1.1, 0.9], gap="large")
with col_l:
st.markdown("<div class='card'>", unsafe_allow_html=True)
st.markdown("<div class='sec-title'>À propos du projet</div>", unsafe_allow_html=True)
st.markdown("<div class='sec-sub'>Women's Clothing E-Commerce Reviews Dataset — BSDSI 2025-2026</div>", unsafe_allow_html=True)
for clr, icon, title, desc in [
("#8B5CF6","","Problématique",
"Prédire si un produit sera recommandé à partir des avis clients, notes et données démographiques."),
("#EC4899","","Données analysées",
"23 486 avis sur des vêtements féminins : âge, rating 1-5, texte, feedbacks, département, classe."),
("#06B6D4","","Approche ML",
"Classification binaire supervisée avec TF-IDF, polarité TextBlob, puis Random Forest optimisé."),
("#10B981","","Valeur ajoutée",
"L'application explique chaque décision via SHAP, aidant les équipes produit à agir."),
]:
st.markdown(f"""
<div class='tl-item'>
<div class='tl-dot' style='border-color:{clr};'>{icon}</div>
<div class='tl-content'><h4>{title}</h4><p>{desc}</p></div>
</div>""", unsafe_allow_html=True)
st.markdown("</div>", unsafe_allow_html=True)
with col_r:
st.markdown("<div class='card'>", unsafe_allow_html=True)
st.markdown("<div class='sec-title'>Technologies</div>", unsafe_allow_html=True)
st.markdown("<div class='sec-sub'>Stack utilisé dans ce projet</div>", unsafe_allow_html=True)
for clr, bg, name, desc in [
("#8B5CF6","#1A1026","Python 3.11","Langage principal"),
("#06B6D4","#001820","Streamlit","Interface web interactive"),
("#F59E0B","#1A1100","Scikit-learn","Modèles ML & évaluation"),
("#10B981","#001811","TextBlob","Analyse de sentiment NLP"),
("#EC4899","#1A0011","Pandas / NumPy","Manipulation des données"),
("#6366F1","#0D0D20","SHAP","Explicabilité IA"),
("#F97316","#1A0D00","Plotly","Visualisations interactives"),
("#34D399","#001810","TF-IDF","Vectorisation du texte"),
]:
st.markdown(f"""
<div style='display:flex;align-items:center;gap:12px;padding:9px 0;border-bottom:1px solid rgba(42,42,62,0.4);'>
<div style='width:36px;height:36px;border-radius:8px;background:{bg};
border:1px solid rgba(42,42,62,0.5);display:flex;align-items:center;
justify-content:center;flex-shrink:0;'>
<div style='width:10px;height:10px;border-radius:50%;background:{clr};'></div>
</div>
<div>
<div style='font-weight:600;font-size:0.88em;color:#E8E8F0;'>{name}</div>
<div style='font-size:0.75em;color:#6B7280;'>{desc}</div>
</div>
</div>""", unsafe_allow_html=True)
st.markdown("</div>", unsafe_allow_html=True)
st.markdown("<div class='fancy-divider'></div>", unsafe_allow_html=True)
# ══════════════════════════════════════════════════════════════
# ── SECTION PLEINE LARGEUR : Colonnes du dataset ──────────────
# ══════════════════════════════════════════════════════════════
st.markdown("""
<div style='font-family:"Space Mono",monospace;font-size:0.68em;color:#8B5CF6;
letter-spacing:2px;text-transform:uppercase;margin-bottom:18px;'>
● Colonnes du dataset
</div>""", unsafe_allow_html=True)
# Mini stats
st.markdown("""
<div style='display:grid;grid-template-columns:repeat(4,1fr);gap:12px;margin-bottom:20px;'>
<div style='background:rgba(26,26,38,0.95);border:1px solid #2A2A3E;border-radius:12px;padding:16px;text-align:center;'>
<div style='font-family:"Space Mono",monospace;font-size:1.6em;font-weight:700;color:#8B5CF6;'>23 486</div>
<div style='font-size:0.75em;color:#6B7280;margin-top:4px;'>Avis clients</div>
</div>
<div style='background:rgba(26,26,38,0.95);border:1px solid #2A2A3E;border-radius:12px;padding:16px;text-align:center;'>
<div style='font-family:"Space Mono",monospace;font-size:1.6em;font-weight:700;color:#06B6D4;'>10</div>
<div style='font-size:0.75em;color:#6B7280;margin-top:4px;'>Colonnes</div>
</div>
<div style='background:rgba(26,26,38,0.95);border:1px solid #2A2A3E;border-radius:12px;padding:16px;text-align:center;'>
<div style='font-family:"Space Mono",monospace;font-size:1.6em;font-weight:700;color:#10B981;'>82.6%</div>
<div style='font-size:0.75em;color:#6B7280;margin-top:4px;'>Recommandés</div>
</div>
<div style='background:rgba(26,26,38,0.95);border:1px solid #2A2A3E;border-radius:12px;padding:16px;text-align:center;'>
<div style='font-family:"Space Mono",monospace;font-size:1.6em;font-weight:700;color:#F59E0B;'>3 526</div>
<div style='font-size:0.75em;color:#6B7280;margin-top:4px;'>Val. manquantes</div>
</div>
</div>""", unsafe_allow_html=True)
# ── Colonnes : chaque carte générée SÉPARÉMENT pour éviter le bug f-string ──
cols_data = [
("Clothing ID", "int64", "Identifiant", "#8B5CF6",
"rgba(139,92,246,0.12)", "rgba(139,92,246,0.4)", False),
("Age", "int64", "Numérique", "#06B6D4",
"rgba(6,182,212,0.12)", "rgba(6,182,212,0.4)", False),
("Title", "object", "Texte", "#EC4899",
"rgba(236,72,153,0.12)", "rgba(236,72,153,0.4)", False),
("Review Text", "object", "NLP", "#F59E0B",
"rgba(245,158,11,0.12)", "rgba(245,158,11,0.4)", False),
("Rating", "int64 · 1–5", "Numérique", "#10B981",
"rgba(16,185,129,0.12)", "rgba(16,185,129,0.4)", False),
("Recommended IND", "int64 · 0/1", "Target", "#EF4444",
"rgba(239,68,68,0.15)", "rgba(239,68,68,0.6)", True),
("Positive Feedback", "int64", "Engagement", "#6366F1",
"rgba(99,102,241,0.12)", "rgba(99,102,241,0.4)", False),
("Division Name", "object · 3", "Catégoriel", "#F97316",
"rgba(249,115,22,0.12)", "rgba(249,115,22,0.4)", False),
("Department Name", "object · 6", "Catégoriel", "#34D399",
"rgba(52,211,153,0.12)", "rgba(52,211,153,0.4)", False),
("Class Name", "object · 20", "Catégoriel", "#A78BFA",
"rgba(167,139,250,0.12)","rgba(167,139,250,0.4)",False),
]
# On génère le HTML des 10 cartes EN UNE SEULE chaîne — sans f-string imbriquée
cards_html = (
"<div style='display:grid;grid-template-columns:repeat(5,1fr);"
"gap:14px;margin-bottom:22px;'>"
)
for name, dtype, badge, clr, bg_card_inner, bd_clr, is_target in cols_data:
top_bar_color = clr
border_col = bd_clr if is_target else "#2A2A3E"
border_width = "2px" if is_target else "1px"
dot_icon = "" if is_target else ""
dot_circle = (
"" if is_target else
"<div style='width:10px;height:10px;border-radius:50%;"
"background:" + clr + ";'></div>"
)
icon_bg = bg_card_inner
card = (
"<div style='background:rgba(26,26,38,0.95);"
"border:" + border_width + " solid " + border_col + ";"
"border-radius:14px;padding:18px 16px;"
"position:relative;overflow:hidden;'>"
# barre couleur top
"<div style='position:absolute;top:0;left:0;right:0;height:3px;"
"background:" + top_bar_color + ";'></div>"
# icône rond ou emoji
"<div style='width:38px;height:38px;border-radius:10px;"
"background:" + icon_bg + ";"
"border:1px solid " + bd_clr + ";"
"display:flex;align-items:center;justify-content:center;"
"margin-bottom:11px;font-size:1.1em;'>"
+ dot_icon + dot_circle +
"</div>"
# nom colonne
"<div style='font-size:0.87em;font-weight:700;color:#E8E8F0;"
"margin-bottom:4px;line-height:1.3;'>" + name + "</div>"
# type
"<div style='font-family:\"Space Mono\",monospace;font-size:0.66em;"
"color:#6B7280;margin-bottom:9px;'>" + dtype + "</div>"
# badge
"<span style='display:inline-block;font-size:0.68em;padding:3px 10px;"
"border-radius:20px;background:" + icon_bg + ";"
"color:" + clr + ";border:1px solid " + bd_clr + ";"
"font-family:\"Space Mono\",monospace;font-weight:600;'>"
+ badge +
"</span>"
"</div>"
)
cards_html += card
cards_html += "</div>"
st.markdown(cards_html, unsafe_allow_html=True)
# ── Barre distribution variable cible ────────────────────────
st.markdown("""
<div style='background:rgba(26,26,38,0.95);border:1px solid #2A2A3E;
border-radius:14px;padding:18px 24px;margin-bottom:24px;'>
<div style='display:flex;align-items:center;justify-content:space-between;margin-bottom:10px;'>
<div style='font-family:"Space Mono",monospace;font-size:0.75em;
font-weight:600;color:#E8E8F0;'>
Distribution — Variable Cible (Recommended IND)
</div>
<div style='font-family:"Space Mono",monospace;font-size:0.65em;color:#6B7280;'>
23 486 avis · Déséquilibre 82/18
</div>
</div>
<div style='height:10px;background:#1A1A26;border-radius:6px;
overflow:hidden;display:flex;'>
<div style='width:82.6%;background:linear-gradient(90deg,#8B5CF6,#EC4899);
border-radius:6px 0 0 6px;'></div>
<div style='width:17.4%;background:#EF4444;
border-radius:0 6px 6px 0;'></div>
</div>
<div style='display:flex;justify-content:space-between;margin-top:8px;'>
<span style='font-family:"Space Mono",monospace;font-size:0.72em;color:#8B5CF6;
display:flex;align-items:center;gap:6px;'>
<span style='width:8px;height:8px;border-radius:50%;background:#8B5CF6;
display:inline-block;'></span>
82.6% — Recommandé (1) · 19 342 avis
</span>
<span style='font-family:"Space Mono",monospace;font-size:0.72em;color:#EF4444;
display:flex;align-items:center;gap:6px;'>
17.4% — Non recommandé (0) · 4 144 avis
<span style='width:8px;height:8px;border-radius:50%;background:#EF4444;
display:inline-block;'></span>
</span>
</div>
</div>""", unsafe_allow_html=True)
# ══════════════════════════════════════════════════════════════
# ── TABLEAU df.head(5) — pleine largeur ───────────────────────
# ══════════════════════════════════════════════════════════════
st.markdown("""
<div style='font-family:"Space Mono",monospace;font-size:0.68em;color:#8B5CF6;
letter-spacing:2px;text-transform:uppercase;margin-bottom:14px;'>
● Aperçu du dataset — df.head(5)
</div>""", unsafe_allow_html=True)
overview_rows = [
(0, 767, 33, 4, 1, 0, "Initmates", "Intimate", "Intimates",
"Absolutely wonderful - silky and sexy and comfortable..."),
(1, 1080, 34, 5, 1, 4, "General", "Dresses", "Dresses",
"Love this dress! it's sooo pretty. i happened to find it..."),
(2, 1077, 60, 3, 0, 0, "General", "Dresses", "Dresses",
"I had such high hopes for this dress and really wanted it..."),
(3, 1049, 50, 5, 1, 0, "Gen. Petite", "Bottoms", "Pants",
"I love, love, love this jumpsuit. it's fun, flirty and..."),
(4, 847, 47, 5, 1, 6, "General", "Tops", "Blouses",
"This shirt is very flattering to all due to the adjustable..."),
]
stars = {1:"★", 2:"★★", 3:"★★★", 4:"★★★★", 5:"★★★★★"}
star_clr = {5:"#F59E0B", 4:"#F59E0B", 3:"#EF4444", 2:"#EF4444", 1:"#EF4444"}
# Header du tableau
table_html = """
<div style='background:rgba(26,26,38,0.95);border:1px solid #2A2A3E;
border-radius:16px;overflow:hidden;position:relative;margin-bottom:8px;'>
<div style='position:absolute;top:0;left:0;right:0;height:3px;
background:linear-gradient(90deg,#8B5CF6,#EC4899,#06B6D4);'></div>
<div style='padding:16px 20px 12px;border-bottom:1px solid rgba(42,42,62,0.6);
display:flex;align-items:center;justify-content:space-between;'>
<div>
<div style='font-family:"Space Mono",monospace;font-size:0.80em;font-weight:600;
color:#E8E8F0;letter-spacing:0.5px;'>
Women's Clothing E-Commerce Reviews Dataset
</div>
<div style='font-size:0.75em;color:#6B7280;margin-top:3px;'>
Avis clients sur des vetements feminins — variable cible : Recommended IND
</div>
</div>
<div style='font-family:"Space Mono",monospace;font-size:0.72em;color:#10B981;
background:rgba(16,185,129,0.1);border:1px solid rgba(16,185,129,0.3);
padding:5px 14px;border-radius:20px;white-space:nowrap;'>
23 486 lignes · 11 colonnes
</div>
</div>
<div style='overflow-x:auto;'>
<table style='width:100%;border-collapse:collapse;font-size:0.87em;'>
<thead>
<tr style='background:rgba(18,18,26,0.95);'>
<th style='padding:11px 16px;text-align:left;color:#8B5CF6;font-family:"Space Mono",monospace;font-size:0.80em;border-bottom:1px solid #2A2A3E;'>#</th>
<th style='padding:11px 16px;text-align:left;color:#8B5CF6;font-family:"Space Mono",monospace;font-size:0.80em;border-bottom:1px solid #2A2A3E;white-space:nowrap;'>Clothing ID</th>
<th style='padding:11px 16px;text-align:left;color:#8B5CF6;font-family:"Space Mono",monospace;font-size:0.80em;border-bottom:1px solid #2A2A3E;'>Age</th>
<th style='padding:11px 16px;text-align:left;color:#8B5CF6;font-family:"Space Mono",monospace;font-size:0.80em;border-bottom:1px solid #2A2A3E;'>Rating</th>
<th style='padding:11px 16px;text-align:left;color:#8B5CF6;font-family:"Space Mono",monospace;font-size:0.80em;border-bottom:1px solid #2A2A3E;'>Recommended</th>
<th style='padding:11px 16px;text-align:left;color:#8B5CF6;font-family:"Space Mono",monospace;font-size:0.80em;border-bottom:1px solid #2A2A3E;white-space:nowrap;'>Feedback +</th>
<th style='padding:11px 16px;text-align:left;color:#8B5CF6;font-family:"Space Mono",monospace;font-size:0.80em;border-bottom:1px solid #2A2A3E;'>Division</th>
<th style='padding:11px 16px;text-align:left;color:#8B5CF6;font-family:"Space Mono",monospace;font-size:0.80em;border-bottom:1px solid #2A2A3E;'>Department</th>
<th style='padding:11px 16px;text-align:left;color:#8B5CF6;font-family:"Space Mono",monospace;font-size:0.80em;border-bottom:1px solid #2A2A3E;'>Class</th>
<th style='padding:11px 16px;text-align:left;color:#8B5CF6;font-family:"Space Mono",monospace;font-size:0.80em;border-bottom:1px solid #2A2A3E;'>Review Text</th>
</tr>
</thead>
<tbody>"""
# Lignes du tableau
for row_data in overview_rows:
idx, cloth_id, age, rating, rec, fb, div_n, dept, cls, review = row_data
if rec == 1:
rec_html = (
"<span style='display:inline-flex;align-items:center;"
"justify-content:center;width:28px;height:28px;border-radius:50%;"
"background:rgba(16,185,129,0.15);border:1px solid rgba(16,185,129,0.5);"
"color:#10B981;font-weight:700;font-size:0.9em;'>✓</span>"
)
else:
rec_html = (
"<span style='display:inline-flex;align-items:center;"
"justify-content:center;width:28px;height:28px;border-radius:50%;"
"background:rgba(239,68,68,0.15);border:1px solid rgba(239,68,68,0.5);"
"color:#EF4444;font-weight:700;font-size:0.9em;'>✗</span>"
)
sc = star_clr[rating]
row_bg = "rgba(239,68,68,0.03)" if rec == 0 else "transparent"
stars_s = stars[rating]
table_html += (
"<tr style='border-bottom:1px solid rgba(42,42,62,0.3);"
"background:" + row_bg + ";'>"
"<td style='padding:13px 16px;color:#4B5563;"
"font-family:\"Space Mono\",monospace;font-size:0.85em;'>"
+ str(idx) + "</td>"
"<td style='padding:13px 16px;color:#06B6D4;"
"font-family:\"Space Mono\",monospace;font-weight:600;'>"
+ str(cloth_id) + "</td>"
"<td style='padding:13px 16px;color:#06B6D4;"
"font-family:\"Space Mono\",monospace;'>"
+ str(age) + "</td>"
"<td style='padding:13px 16px;color:" + sc + ";"
"font-family:\"Space Mono\",monospace;white-space:nowrap;font-weight:600;'>"
+ stars_s + " " + str(rating) + "</td>"
"<td style='padding:13px 16px;'>" + rec_html + "</td>"
"<td style='padding:13px 16px;color:#06B6D4;"
"font-family:\"Space Mono\",monospace;'>"
+ str(fb) + "</td>"
"<td style='padding:13px 16px;color:#EC4899;font-weight:500;'>"
+ div_n + "</td>"
"<td style='padding:13px 16px;color:#9CA3AF;'>"
+ dept + "</td>"
"<td style='padding:13px 16px;color:#A78BFA;font-weight:500;'>"
+ cls + "</td>"
"<td style='padding:13px 16px;color:#6B7280;max-width:260px;"
"overflow:hidden;text-overflow:ellipsis;white-space:nowrap;"
"font-style:italic;'>"
+ review + "</td>"
"</tr>"
)
# Footer du tableau
table_html += """
</tbody>
</table>
</div>
<div style='padding:11px 20px;border-top:1px solid rgba(42,42,62,0.4);
display:flex;align-items:center;gap:20px;flex-wrap:wrap;'>
<span style='display:flex;align-items:center;gap:6px;
font-size:0.75em;color:#6B7280;'>
<span style='width:8px;height:8px;border-radius:50%;background:#10B981;
display:inline-block;flex-shrink:0;'></span>Recommande (1)
</span>
<span style='display:flex;align-items:center;gap:6px;
font-size:0.75em;color:#6B7280;'>
<span style='width:8px;height:8px;border-radius:50%;background:#EF4444;
display:inline-block;flex-shrink:0;'></span>Non recommande (0)
</span>
<span style='display:flex;align-items:center;gap:6px;
font-size:0.75em;color:#6B7280;'>
<span style='width:8px;height:8px;border-radius:50%;background:#F59E0B;
display:inline-block;flex-shrink:0;'></span>Rating 1-5
</span>
<span style='margin-left:auto;font-family:"Space Mono",monospace;
font-size:0.68em;color:#4B5563;'>
df.shape : (23 486, 11)
</span>
</div>
</div>"""
st.markdown(table_html, unsafe_allow_html=True)
# ══════════════════════════════════════════════════════════════
# PAGE 1 — EDA
# ══════════════════════════════════════════════════════════════
elif PAGE == 1:
st.markdown("""
<div style='padding:40px 0 24px 0;'>
<div class='hero-badge'>📊 Analyse Exploratoire</div>
<div class='sec-title' style='font-size:2.2em;margin-top:10px;'>Exploration des Données</div>
<div class='sec-sub'>Analyse du Women's Clothing E-Commerce Reviews Dataset avant la modélisation</div>
</div>""", unsafe_allow_html=True)
cols6 = st.columns(6)
for col, (num, lbl, clr) in zip(cols6, [
("23,486","Avis clients","#8B5CF6"), ("10","Colonnes","#06B6D4"),
("82.6%","Recommandés","#10B981"), ("17.4%","Non recommandés","#EF4444"),
("3,526","Valeurs manquantes","#F59E0B"), ("4.18","Rating moyen","#EC4899"),
]):
with col:
st.markdown(f"""
<div class='card' style='text-align:center;padding:18px 10px;'>
<div style='font-family:"Space Mono",monospace;font-size:1.5em;font-weight:700;color:{clr};'>{num}</div>
<div style='color:#6B7280;font-size:0.75em;margin-top:4px;'>{lbl}</div>
</div>""", unsafe_allow_html=True)
st.markdown("<div class='fancy-divider'></div>", unsafe_allow_html=True)
c1, c2 = st.columns(2, gap="large")
with c1:
fig = go.Figure(go.Bar(
x=["⭐1","⭐2","⭐3","⭐4","⭐5"],
y=[1206, 782, 1898, 5113, 13538],
marker_color=["#EF4444","#F97316","#F59E0B","#10B981","#8B5CF6"],
text=[1206,782,1898,5113,13538], textposition="outside",
textfont=dict(color="#E8E8F0", size=11),
))
fig.update_layout(**PLOTLY_BASE, height=300, showlegend=False,
title=dict(text="Distribution des Ratings", font=dict(color="#E8E8F0", size=15, family="Playfair Display")),
xaxis=dict(gridcolor="#2A2A3E", tickfont=dict(color="#E8E8F0")),
yaxis=dict(gridcolor="#2A2A3E", tickfont=dict(color="#6B7280")),
)
st.plotly_chart(fig, use_container_width=True)
with c2:
fig2 = go.Figure(go.Pie(
labels=["Recommandé (1)", "Non recommandé (0)"],
values=[82.56, 17.44], hole=0.65,
marker=dict(colors=["#8B5CF6","#EF4444"], line=dict(color="#0A0A0F", width=3)),
textinfo="label+percent", textfont=dict(color="#E8E8F0", size=11),
))
fig2.add_annotation(text="<b>82.6%</b>", x=0.5, y=0.56, showarrow=False,
font=dict(color="#E8E8F0", size=22))
fig2.add_annotation(text="Recommandés", x=0.5, y=0.42, showarrow=False,
font=dict(color="#6B7280", size=12))
fig2.update_layout(**PLOTLY_BASE, height=300,
title=dict(text="Variable Cible — Recommended IND", font=dict(color="#E8E8F0", size=15, family="Playfair Display")),
legend=dict(font=dict(color="#E8E8F0"), bgcolor="rgba(0,0,0,0)"),
)
st.plotly_chart(fig2, use_container_width=True)
c3, c4 = st.columns(2, gap="large")
with c3:
age_g = ["18-25","26-33","34-41","42-49","50-57","58-65","66+"]
age_c = [1820, 4210, 5630, 4890, 3740, 2100, 1096]
fig3 = go.Figure(go.Bar(
x=age_g, y=age_c,
marker=dict(color=age_c, colorscale=[[0,"#1A1026"],[0.5,"#8B5CF6"],[1,"#EC4899"]]),
))
fig3.update_layout(**PLOTLY_BASE, height=270, showlegend=False,
title=dict(text="Distribution de l'Âge", font=dict(color="#E8E8F0", size=15, family="Playfair Display")),
xaxis=dict(gridcolor="#2A2A3E", tickfont=dict(color="#E8E8F0")),
yaxis=dict(gridcolor="#2A2A3E", tickfont=dict(color="#6B7280")),
)
st.plotly_chart(fig3, use_container_width=True)
with c4:
cats = ["Rating 1","Rating 2","Rating 3","Rating 4","Rating 5"]
fig4 = go.Figure()
fig4.add_trace(go.Bar(name="Recommandé ✓", x=cats, y=[6.8,23.4,52.1,85.3,97.8], marker_color="#8B5CF6", opacity=0.9))
fig4.add_trace(go.Bar(name="Non recommandé ✗", x=cats, y=[93.2,76.6,47.9,14.7,2.2], marker_color="#EF4444", opacity=0.9))
fig4.update_layout(**PLOTLY_BASE, barmode="stack", height=270,
title=dict(text="Rating vs Recommandation (%)", font=dict(color="#E8E8F0", size=15, family="Playfair Display")),
xaxis=dict(gridcolor="#2A2A3E", tickfont=dict(color="#E8E8F0")),
yaxis=dict(gridcolor="#2A2A3E", tickfont=dict(color="#6B7280"), ticksuffix="%"),
legend=dict(font=dict(color="#E8E8F0"), bgcolor="rgba(0,0,0,0)"),
)
st.plotly_chart(fig4, use_container_width=True)
st.markdown("<div class='card'>", unsafe_allow_html=True)
st.markdown("""<div style='font-family:"Space Mono",monospace;font-size:0.68em;
color:#8B5CF6;letter-spacing:1px;margin-bottom:18px;'>
CORRÉLATIONS AVEC RECOMMENDED IND</div>
<div style='display:grid;grid-template-columns:repeat(3,1fr);gap:14px;'>
""", unsafe_allow_html=True)
corr_html = ""
for name, val, clr, pct in [
("Rating","0.79","#8B5CF6",79), ("Polarity (TextBlob)","0.21","#06B6D4",21),
("Subjectivity","0.15","#10B981",15), ("Age","0.03","#F59E0B",3),
("Positive Feedback","-0.07","#F97316",7), ("Review Length","-0.05","#EC4899",5),
]:
bc = "#EF4444" if val.startswith("-") else clr
corr_html += f"""
<div style='background:#12121A;border-radius:10px;padding:14px;border:1px solid #2A2A3E;'>
<div style='display:flex;justify-content:space-between;margin-bottom:8px;'>
<span style='font-size:0.83em;color:#E8E8F0;font-weight:500;'>{name}</span>
<span style='font-family:"Space Mono",monospace;font-size:0.83em;color:{bc};font-weight:700;'>{val}</span>
</div>
<div style='background:#0A0A0F;border-radius:4px;height:6px;'>
<div style='width:{pct}%;height:100%;border-radius:4px;background:{bc};'></div>
</div>
</div>"""
st.markdown(corr_html + "</div></div>", unsafe_allow_html=True)
# ══════════════════════════════════════════════════════════════
# PAGE 2 — MODÉLISATION ML
# ══════════════════════════════════════════════════════════════
elif PAGE == 2:
st.markdown("""
<div style='padding:40px 0 24px 0;'>
<div class='hero-badge'> Machine Learning</div>
<div class='sec-title' style='font-size:2.2em;margin-top:10px;'>Modélisation & Performances</div>
<div class='sec-sub'>3 modèles · Cross-Validation · GridSearchCV / RandomizedSearchCV · Avant vs Après optimisation</div>
</div>""", unsafe_allow_html=True)
tab1, tab2, tab3, tab4, tab5 = st.tabs([
"Résultats de Base", "Cross-Validation", "Optimisation GridSearch",
"Comparaison Finale", "Feature Importances",
])
with tab1:
st.markdown("""
<div class='card' style='margin-top:16px;'>
<div style='font-family:"Space Mono",monospace;font-size:0.68em;color:#8B5CF6;
letter-spacing:1px;margin-bottom:18px;'>MÉTRIQUES DE BASE (SANS OPTIMISATION)</div>
<table class='styled-table'><thead><tr>
<th>MODÈLE</th><th>ACCURACY</th><th>PRECISION</th>
<th>RECALL</th><th>F1-SCORE</th><th>F1 Classe 0</th><th>STATUT</th>
</tr></thead><tbody>
<tr>
<td><strong style='color:#06B6D4;'>Logistic Regression</strong></td>
<td>93.5%</td><td>97.0%</td><td>94.9%</td><td>96.0%</td><td>82.1%</td>
<td><span style='background:rgba(6,182,212,0.1);border:1px solid rgba(6,182,212,0.3);
color:#06B6D4;padding:3px 10px;border-radius:12px;font-size:0.77em;'>Baseline</span></td>
</tr>
<tr>
<td><strong style='color:#10B981;'>Decision Tree</strong></td>
<td>92.2%</td><td>95.5%</td><td>94.9%</td><td>95.2%</td><td>77.9%</td>
<td><span style='background:rgba(239,68,68,0.1);border:1px solid rgba(239,68,68,0.3);
color:#EF4444;padding:3px 10px;border-radius:12px;font-size:0.77em;'>Overfitting</span></td>
</tr>
<tr style='background:rgba(139,92,246,0.05);'>
<td><strong style='color:#A78BFA;'>✦ Random Forest</strong></td>
<td><strong style='color:#8B5CF6;'>93.2%</strong></td>
<td><strong style='color:#8B5CF6;'>97.2%</strong></td>
<td>94.5%</td>
<td><strong style='color:#8B5CF6;'>95.8%</strong></td>
<td><strong style='color:#8B5CF6;'>81.7%</strong></td>
<td><span style='background:rgba(139,92,246,0.1);border:1px solid rgba(139,92,246,0.3);
color:#8B5CF6;padding:3px 10px;border-radius:12px;font-size:0.77em;'>Meilleur</span></td>
</tr>
</tbody></table>
</div>""", unsafe_allow_html=True)
c1, c2 = st.columns(2, gap="large")
with c1:
cats = ["Accuracy","Precision","Recall","F1-Score"]
fig_r = go.Figure()