-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
661 lines (578 loc) · 25.9 KB
/
Copy pathapp.py
File metadata and controls
661 lines (578 loc) · 25.9 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
# app.py
import tomllib
from pathlib import Path
from typing import Any, Dict, List, Optional, TypedDict
import pandas as pd
import streamlit as st
# ---------------------------------------------------------------------------
# Imports — cleaned: each module imported exactly once with the full set
# ---------------------------------------------------------------------------
from core.profiler import (
generate_profile,
detect_duplicates,
detect_outliers,
run_duckdb_anomalies,
)
from core.scorer import (
score_column,
score_dataframe,
get_score_label,
generate_issue_summary,
)
from ui.sidebar import render_sidebar
from ui.dashboard import (
render_overview_metrics,
render_score_gauge,
render_column_table,
render_issue_list,
)
from ui.report_card import render_column_card, render_suggestion_box
from ui.login import render_login_page
from utils.cleaner import (
suggest_fixes,
apply_fixes,
export_cleaned_csv,
generate_change_log,
)
from credentials import get_user_name
# ---------------------------------------------------------------------------
# Config TypedDicts
# ---------------------------------------------------------------------------
class AppConfigScoring(TypedDict):
completeness_weight: float
uniqueness_weight: float
consistency_weight: float
outlier_weight: float
class AppConfigDetection(TypedDict):
outlier_iqr_multiplier: float
max_upload_mb: int
class AppConfig(TypedDict):
scoring: AppConfigScoring
detection: AppConfigDetection
# ---------------------------------------------------------------------------
# Exceptions
# ---------------------------------------------------------------------------
class AppConfigLoadError(Exception):
pass
class OrchestrationError(Exception):
pass
# ---------------------------------------------------------------------------
# Config loader
# ---------------------------------------------------------------------------
def load_app_config() -> AppConfig:
try:
config_path = Path(__file__).resolve().parent / "config.toml"
with open(config_path, "rb") as f:
return tomllib.load(f) # type: ignore
except FileNotFoundError:
return {
"scoring": {
"completeness_weight": 0.30,
"uniqueness_weight": 0.20,
"consistency_weight": 0.30,
"outlier_weight": 0.20,
},
"detection": {
"outlier_iqr_multiplier": 1.5,
"max_upload_mb": 200,
},
}
except tomllib.TOMLDecodeError as e:
raise AppConfigLoadError(f"Malformed TOML configuration syntax: {e}")
except Exception as e:
raise AppConfigLoadError(f"Unexpected configuration load failure: {e}")
_CONFIG: AppConfig = load_app_config()
# ---------------------------------------------------------------------------
# Session state initialiser
# ---------------------------------------------------------------------------
def initialize_session_state() -> None:
try:
defaults: Dict[str, Any] = {
"authenticated": False,
"username": None,
"user_name": None,
"raw_df": None,
"cleaned_df": None,
"selected_fixes": [],
"profile": None,
"col_scores": None,
"overall_score": None,
"issues": None,
}
for key, val in defaults.items():
if key not in st.session_state:
st.session_state[key] = val
except Exception as e:
raise OrchestrationError(f"Session state initialization failure: {e}")
# ---------------------------------------------------------------------------
# Profile enrichment — merges profiler + outlier + anomaly + duplicate data
# into a single flat dict per column that scorer and cleaner both consume
# ---------------------------------------------------------------------------
def _build_enriched_profile(df: pd.DataFrame) -> Dict[str, Dict[str, Any]]:
try:
raw_profile = generate_profile(df)
anomaly_report = run_duckdb_anomalies(df)
dup_report = detect_duplicates(df)
total_rows = len(df)
enriched: Dict[str, Dict[str, Any]] = {}
for col_name, col_profile in raw_profile.items():
outlier_report = detect_outliers(df, col_name)
mismatch_count = sum(
1 for m in anomaly_report.type_mismatches
if m.get("column") == col_name
)
enriched[col_name] = {
"dtype": col_profile.dtype,
"missing_count": col_profile.missing_count,
"missing_percentage": col_profile.missing_percentage,
"unique_count": col_profile.unique_count,
"min_value": col_profile.min_value,
"max_value": col_profile.max_value,
"mean_value": col_profile.mean_value,
"std_value": col_profile.std_value,
"top_values": col_profile.top_values,
"outlier_count": outlier_report.count,
"outlier_indices": outlier_report.indices,
"lower_fence": outlier_report.lower_fence,
"upper_fence": outlier_report.upper_fence,
"mismatch_count": mismatch_count,
# NEW — duplicate count wired into every column so scorer
# can apply the duplicate penalty correctly
"duplicate_count": dup_report.count,
"total_rows": total_rows,
}
return enriched
except Exception as e:
raise OrchestrationError(f"Profile enrichment pipeline failure: {e}")
def _build_column_scores(profile: Dict[str, Dict[str, Any]]) -> Dict[str, int]:
try:
return {col_name: score_column(stats) for col_name, stats in profile.items()}
except Exception as e:
raise OrchestrationError(f"Column score computation failure: {e}")
# ---------------------------------------------------------------------------
# CSS injection — neon dark theme
# ---------------------------------------------------------------------------
def _inject_neon_css() -> None:
st.markdown(
"""
<style>
@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;700&display=swap');
html, body, [class*="css"] {
font-family: 'JetBrains Mono', monospace !important;
}
/* ── Master background — rich midnight with vivid glow orbs ── */
.stApp {
background:
radial-gradient(ellipse at 8% 30%, rgba(0,255,255,0.13) 0%, transparent 45%),
radial-gradient(ellipse at 92% 10%, rgba(80,0,255,0.18) 0%, transparent 40%),
radial-gradient(ellipse at 50% 85%, rgba(0,120,255,0.14) 0%, transparent 45%),
radial-gradient(ellipse at 75% 55%, rgba(120,0,255,0.10) 0%, transparent 40%),
radial-gradient(ellipse at 25% 70%, rgba(0,200,255,0.09) 0%, transparent 38%),
linear-gradient(145deg, #0D0D1F 0%, #111228 35%, #0E1530 65%, #0A1525 100%) !important;
}
/* ── Sidebar — vivid glass over richer bg ── */
section[data-testid="stSidebar"] {
background: rgba(14, 18, 38, 0.55) !important;
backdrop-filter: blur(28px) saturate(180%) brightness(1.1) !important;
-webkit-backdrop-filter: blur(28px) saturate(180%) brightness(1.1) !important;
border-right: 1px solid rgba(0, 255, 255, 0.15) !important;
box-shadow: 4px 0 40px rgba(0,0,0,0.6), 0 0 0 1px rgba(80,0,255,0.06) inset !important;
}
/* ── Typography ── */
h1, h2, h3, h4, h5, h6 {
color: #00FFFF !important;
font-family: 'JetBrains Mono', monospace !important;
text-shadow: 0 0 16px rgba(0, 255, 255, 0.35), 0 0 32px rgba(0,255,255,0.1);
letter-spacing: 2px;
}
p, label, span, div {
color: #E0F7FA !important;
}
/* ── Master metric containers ── */
[data-testid="stMetric"] {
background: rgba(255, 255, 255, 0.04) !important;
border: 1px solid rgba(0, 255, 255, 0.22) !important;
border-radius: 14px !important;
padding: 20px !important;
backdrop-filter: blur(20px) saturate(200%) brightness(1.15) !important;
-webkit-backdrop-filter: blur(20px) saturate(200%) brightness(1.15) !important;
box-shadow:
0 8px 32px rgba(0, 0, 0, 0.45),
0 0 0 1px rgba(255, 255, 255, 0.05) inset,
0 1px 0 rgba(255,255,255,0.08) inset,
0 0 28px rgba(0, 255, 255, 0.06) !important;
transition: transform 0.25s ease, box-shadow 0.25s ease !important;
}
[data-testid="stMetric"]:hover {
transform: translateY(-3px) !important;
box-shadow:
0 12px 40px rgba(0, 0, 0, 0.55),
0 0 0 1px rgba(0, 255, 255, 0.15) inset,
0 0 36px rgba(0, 255, 255, 0.12) !important;
}
[data-testid="stMetricLabel"] {
color: rgba(0, 255, 255, 0.65) !important;
font-size: 10px !important;
letter-spacing: 3px !important;
text-transform: uppercase !important;
}
[data-testid="stMetricValue"] {
color: #00FFFF !important;
font-size: 30px !important;
font-weight: 700 !important;
text-shadow: 0 0 12px rgba(0, 255, 255, 0.5) !important;
}
[data-testid="stMetricDelta"] {
color: rgba(0, 255, 255, 0.55) !important;
font-size: 11px !important;
}
/* ── Buttons — glass neon ── */
.stButton > button {
background: linear-gradient(135deg, rgba(0,255,255,0.08), rgba(0,180,255,0.05)) !important;
border: 1px solid rgba(0, 255, 255, 0.4) !important;
color: #00FFFF !important;
font-family: 'JetBrains Mono', monospace !important;
font-size: 12px !important;
letter-spacing: 3px !important;
text-transform: uppercase !important;
border-radius: 8px !important;
backdrop-filter: blur(8px) !important;
transition: all 0.25s ease !important;
}
.stButton > button:hover {
background: linear-gradient(135deg, rgba(0,255,255,0.18), rgba(0,180,255,0.12)) !important;
box-shadow: 0 0 24px rgba(0, 255, 255, 0.3), 0 4px 16px rgba(0,0,0,0.4) !important;
transform: translateY(-2px) !important;
border-color: #00FFFF !important;
}
.stButton > button:active {
transform: translateY(0px) !important;
}
.stButton > button[kind="primary"] {
background: linear-gradient(135deg, rgba(0,255,255,0.15), rgba(0,200,255,0.1)) !important;
border-color: #00FFFF !important;
box-shadow: 0 0 16px rgba(0, 255, 255, 0.25) !important;
}
/* ── File uploader ── */
[data-testid="stFileUploader"] {
background: rgba(13, 18, 32, 0.5) !important;
border: 1px dashed rgba(0, 255, 255, 0.3) !important;
border-radius: 10px !important;
backdrop-filter: blur(8px) !important;
}
/* ── DataFrame ── */
.stDataFrame, [data-testid="stDataFrame"] {
background: rgba(10, 14, 26, 0.6) !important;
border: 1px solid rgba(0, 255, 255, 0.15) !important;
border-radius: 10px !important;
backdrop-filter: blur(12px) !important;
overflow: hidden;
}
/* ── Expander — vivid glass card ── */
.stExpander {
background: rgba(255, 255, 255, 0.03) !important;
border: 1px solid rgba(0, 255, 255, 0.18) !important;
border-radius: 14px !important;
backdrop-filter: blur(20px) saturate(180%) brightness(1.1) !important;
-webkit-backdrop-filter: blur(20px) saturate(180%) brightness(1.1) !important;
box-shadow:
0 4px 24px rgba(0,0,0,0.4),
0 0 0 1px rgba(255,255,255,0.05) inset,
0 1px 0 rgba(255,255,255,0.06) inset !important;
}
.stExpander summary {
color: #00FFFF !important;
letter-spacing: 1px !important;
}
.stExpander summary:hover {
color: #80FFFF !important;
}
/* ── Text inputs ── */
.stTextInput input, .stNumberInput input {
background: rgba(10, 14, 26, 0.7) !important;
border: 1px solid rgba(0, 255, 255, 0.25) !important;
border-radius: 8px !important;
color: #E0F7FA !important;
font-family: 'JetBrains Mono', monospace !important;
backdrop-filter: blur(8px) !important;
}
.stTextInput input:focus, .stNumberInput input:focus {
border-color: #00FFFF !important;
box-shadow: 0 0 0 3px rgba(0,255,255,0.1), 0 0 16px rgba(0,255,255,0.12) !important;
}
/* ── Selectbox ── */
.stSelectbox div[data-baseweb="select"] > div {
background: rgba(13, 18, 32, 0.7) !important;
border-color: rgba(0, 255, 255, 0.25) !important;
border-radius: 8px !important;
backdrop-filter: blur(8px) !important;
}
/* ── Multiselect ── */
.stMultiSelect div[data-baseweb="select"] > div {
background: rgba(13, 18, 32, 0.7) !important;
border-color: rgba(0, 255, 255, 0.25) !important;
border-radius: 8px !important;
}
/* ── Slider ── */
[data-testid="stSlider"] > div > div > div {
background: rgba(0, 255, 255, 0.3) !important;
}
[data-testid="stSlider"] > div > div > div > div {
background: #00FFFF !important;
box-shadow: 0 0 8px rgba(0,255,255,0.6) !important;
}
/* ── Radio buttons ── */
[data-testid="stRadio"] label {
color: #E0F7FA !important;
}
/* ── Dividers ── */
hr {
border-color: rgba(0, 255, 255, 0.12) !important;
}
/* ── Download button ── */
[data-testid="stDownloadButton"] > button {
background: linear-gradient(135deg, rgba(0,255,255,0.1), rgba(0,180,255,0.07)) !important;
border-color: rgba(0, 255, 255, 0.45) !important;
color: #00FFFF !important;
border-radius: 8px !important;
backdrop-filter: blur(8px) !important;
}
[data-testid="stDownloadButton"] > button:hover {
box-shadow: 0 0 20px rgba(0,255,255,0.3) !important;
transform: translateY(-1px) !important;
}
/* ── Alert / info boxes ── */
div[data-testid="stAlert"] {
background: rgba(13, 18, 32, 0.6) !important;
border-left-color: #00FFFF !important;
border-radius: 8px !important;
backdrop-filter: blur(12px) !important;
}
/* ── Spinner ── */
.stSpinner > div {
border-top-color: #00FFFF !important;
}
/* ── Tabs ── */
.stTabs [data-baseweb="tab-list"] {
background: rgba(10, 14, 26, 0.5) !important;
border-radius: 8px !important;
backdrop-filter: blur(8px) !important;
}
.stTabs [data-baseweb="tab"] {
color: rgba(0,255,255,0.6) !important;
letter-spacing: 2px !important;
}
.stTabs [aria-selected="true"] {
color: #00FFFF !important;
border-bottom-color: #00FFFF !important;
}
/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: rgba(10,14,26,0.5); }
::-webkit-scrollbar-thumb {
background: rgba(0,255,255,0.3);
border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
background: rgba(0,255,255,0.5);
}
/* ── Scanline animation ── */
@keyframes scanline {
0% { transform: translateY(-100%); }
100% { transform: translateY(100vh); }
}
.scanline {
position: fixed;
top: 0; left: 0; right: 0;
height: 2px;
background: linear-gradient(90deg, transparent, rgba(0,255,255,0.06), transparent);
animation: scanline 8s linear infinite;
pointer-events: none;
z-index: 9999;
}
</style>
<div class="scanline"></div>
""",
unsafe_allow_html=True,
)
# ---------------------------------------------------------------------------
# Landing page (shown when no dataset is loaded)
# ---------------------------------------------------------------------------
def _render_landing() -> None:
st.markdown(
"""
<div style="
text-align: center;
padding: 80px 40px;
border: 1px solid rgba(0,255,255,0.15);
border-radius: 12px;
background: rgba(0,255,255,0.02);
margin-top: 40px;
">
<h1 style="font-size: 48px; letter-spacing: 6px;">DATA QUALITY AUDITOR</h1>
<p style="color: rgba(0,255,255,0.6) !important; font-size: 14px; letter-spacing: 3px; margin-top: 12px;">
UPLOAD ANY CSV — GET A FULL QUALITY SCORE IN 10 SECONDS
</p>
<div style="margin-top: 40px; display: flex; justify-content: center; gap: 40px; flex-wrap: wrap;">
<div style="border: 1px solid rgba(0,255,255,0.2); padding: 20px 30px; border-radius: 8px; min-width: 160px;">
<div style="color: #00FFFF !important; font-size: 24px; font-weight: 700;">0–100</div>
<div style="color: rgba(0,255,255,0.5) !important; font-size: 11px; letter-spacing: 2px; margin-top: 6px;">QUALITY SCORE</div>
</div>
<div style="border: 1px solid rgba(0,255,255,0.2); padding: 20px 30px; border-radius: 8px; min-width: 160px;">
<div style="color: #00FFFF !important; font-size: 24px; font-weight: 700;">IQR</div>
<div style="color: rgba(0,255,255,0.5) !important; font-size: 11px; letter-spacing: 2px; margin-top: 6px;">OUTLIER DETECTION</div>
</div>
<div style="border: 1px solid rgba(0,255,255,0.2); padding: 20px 30px; border-radius: 8px; min-width: 160px;">
<div style="color: #00FFFF !important; font-size: 24px; font-weight: 700;">AUTO</div>
<div style="color: rgba(0,255,255,0.5) !important; font-size: 11px; letter-spacing: 2px; margin-top: 6px;">CLEAN + EXPORT</div>
</div>
</div>
<p style="color: rgba(0,255,255,0.35) !important; font-size: 12px; margin-top: 40px; letter-spacing: 1px;">
← USE THE SIDEBAR TO UPLOAD A FILE OR LOAD THE SAMPLE DATASET
</p>
</div>
""",
unsafe_allow_html=True,
)
# ---------------------------------------------------------------------------
# Main entrypoint
# ---------------------------------------------------------------------------
def main() -> None:
try:
# FIX: duplicate page_icon and duplicate initial_sidebar_state args removed
st.set_page_config(
page_title="Data Quality Auditor",
page_icon="🛡️",
layout="wide",
initial_sidebar_state="expanded",
)
initialize_session_state()
# ===== AUTHENTICATION CHECK =====
# Must happen BEFORE _inject_neon_css() and BEFORE main UI rendering
if not st.session_state.get("authenticated", False):
render_login_page()
return # Stop — don't render the main app until login succeeds
# ===== MAIN APP STARTS HERE =====
_inject_neon_css()
# ===== SIDEBAR USER INFO & LOGOUT =====
# FIX: moved here — renders immediately on login, not after data load
with st.sidebar:
username = st.session_state.get("username", "user")
st.markdown(
f"""
<div style='
background: rgba(0,255,255,0.05);
border: 1px solid rgba(0,255,255,0.2);
border-radius: 6px;
padding: 12px;
margin-bottom: 12px;
font-size: 11px;
letter-spacing: 1px;
'>
<span style='color: rgba(0,255,255,0.5);'>👤 LOGGED IN AS</span><br>
<span style='color: #00FFFF; font-weight: 700;'>{username.upper()}</span>
</div>
""",
unsafe_allow_html=True,
)
if st.button("🚪 LOGOUT", key="logout_btn", use_container_width=True):
st.session_state["authenticated"] = False
st.session_state["username"] = None
st.session_state["user_name"] = None
st.rerun()
st.markdown("---")
df: Optional[pd.DataFrame] = render_sidebar()
# New file uploaded — reset all cached analysis so it re-runs cleanly
if df is not None:
st.session_state["raw_df"] = df
st.session_state["cleaned_df"] = None
st.session_state["profile"] = None
st.session_state["col_scores"] = None
st.session_state["overall_score"] = None
st.session_state["issues"] = None
active_df: Optional[pd.DataFrame] = st.session_state.get("raw_df")
if active_df is None:
st.info(
"Awaiting data stream. Upload a CSV or load the bundled sample from the sidebar."
)
_render_landing()
return
st.markdown(
"<h1 style='letter-spacing:6px;'>🛡 DATA QUALITY AUDITOR</h1>",
unsafe_allow_html=True,
)
st.markdown("---")
# Run analysis once and cache in session state
if st.session_state.get("profile") is None:
with st.spinner("SCANNING DATA MATRIX..."):
profile = _build_enriched_profile(active_df)
col_scores = _build_column_scores(profile)
overall_score = score_dataframe(profile)
issues = generate_issue_summary(profile)
st.session_state["profile"] = profile
st.session_state["col_scores"] = col_scores
st.session_state["overall_score"] = overall_score
st.session_state["issues"] = issues
profile: Dict[str, Dict[str, Any]] = st.session_state["profile"]
col_scores: Dict[str, int] = st.session_state["col_scores"]
overall_score: int = st.session_state["overall_score"]
issues: List[Any] = st.session_state["issues"]
# Duplicate report (lightweight — not cached, uses session iqr pref)
dup_report = detect_duplicates(active_df)
duplicate_count = dup_report.count
# --- Dashboard ---
render_overview_metrics(overall_score, profile, issues)
st.markdown("<br>", unsafe_allow_html=True)
c1, c2 = st.columns([1, 2])
with c1:
render_score_gauge(overall_score)
with c2:
render_column_table(profile, col_scores)
st.markdown("---")
render_issue_list(issues)
# --- Per-column deep-dive cards ---
st.markdown("---")
st.subheader("FEATURE AXIS DEEP-DIVE REPORTS")
for col_name, stats in profile.items():
c_score = col_scores.get(col_name, 0)
render_column_card(col_name, stats, c_score, active_df)
# --- Remediation pipeline ---
st.markdown("---")
st.subheader("REMEDIATION PIPELINE")
all_suggestions = suggest_fixes(
profile,
duplicate_count=duplicate_count,
source_df=active_df,
)
render_suggestion_box(all_suggestions)
# FIX: two separate execute buttons existed (one from old code, one from new).
# Merged into a single button with change log feedback.
if st.button("EXECUTE ALL FIXES", type="primary", key="execute_fixes_btn"):
with st.spinner("APPLYING REMEDIATIONS..."):
cleaned = apply_fixes(active_df, [s.__dict__ for s in all_suggestions])
st.session_state["cleaned_df"] = cleaned
change_log = generate_change_log(active_df, cleaned)
st.success(
f"COMPLETE — {change_log.rows_dropped} rows dropped, "
f"{sum(change_log.mutations_applied.values())} values mutated."
)
cleaned_df: Optional[pd.DataFrame] = st.session_state.get("cleaned_df")
if cleaned_df is not None:
csv_bytes = export_cleaned_csv(cleaned_df)
# FIX: duplicate label and duplicate type= args removed
st.download_button(
label="⬇ DOWNLOAD CLEANED CSV",
data=csv_bytes,
file_name="audited_cleaned_dataset.csv",
mime="text/csv",
type="primary",
key="download_cleaned_csv_btn",
)
except AppConfigLoadError as e:
st.error(f"CRITICAL INIT FAILURE: {e}")
except OrchestrationError as e:
st.error(f"ORCHESTRATION FAULT: {e}")
except Exception as e:
st.error(f"UNHANDLED EXCEPTION: {e}")
if __name__ == "__main__":
main()