-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
229 lines (193 loc) · 6.45 KB
/
Copy pathapp.py
File metadata and controls
229 lines (193 loc) · 6.45 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
"""SENTINEL Fraud Detection - Streamlit Web UI.
Multi-page Streamlit application for fraud prediction, model evaluation, and transaction analysis.
"""
import streamlit as st
from pathlib import Path
import json
from ui_theme import apply_theme
st.set_page_config(
page_title="SENTINEL Fraud Detection",
layout="wide",
initial_sidebar_state="expanded",
page_icon="S",
)
# Shared mark.dev theme — MODE and accent live in ui_theme.py (tokens, type, widgets, SENTINEL components)
apply_theme()
# Sidebar
with st.sidebar:
st.markdown("""
<div class="brand-block">
<div class="brand-mark">S</div>
<h2>SENTINEL</h2>
<p>FRAUD DETECTION SYSTEM</p>
</div>
""", unsafe_allow_html=True)
st.markdown("---")
st.markdown("""
<div class="side-block">
<div class="side-label">NAVIGATION</div>
<p class="side-list">
Home Dashboard<br>
Predict Fraud<br>
Performance Metrics<br>
Transaction Analysis
</p>
</div>
""", unsafe_allow_html=True)
st.markdown("---")
st.markdown("""
<div class="side-block">
<div class="side-label">POWERED BY</div>
<p class="side-list">
XGBoost Classifier<br>
Pandas + scikit-learn<br>
DVC Pipeline
</p>
</div>
""", unsafe_allow_html=True)
st.markdown("---")
st.markdown(
'<div style="text-align: center;">'
'<span class="status-badge status-active">System Online</span>'
'</div>',
unsafe_allow_html=True,
)
# Main page content
st.markdown("""
<div class="main-header">
<h1>SENTINEL</h1>
<p>Advanced fraud detection for digital payment transactions</p>
</div>
""", unsafe_allow_html=True)
# Load metrics once (resolve path relative to this file, not cwd)
PROJECT_ROOT = Path(__file__).resolve().parent
metrics_file = PROJECT_ROOT / "metrics" / "scores.json"
scores = {}
if metrics_file.exists():
with open(metrics_file) as f:
scores = json.load(f)
# KPI Row
if not scores:
st.info("Model not yet evaluated. Run `dvc repro evaluate` to generate metrics.")
if scores:
col1, col2, col3, col4, col5 = st.columns(5)
with col1:
st.markdown(f"""
<div class="kpi-card">
<div class="kpi-value">{scores.get('accuracy', 0):.2%}</div>
<div class="kpi-label">Accuracy</div>
</div>
""", unsafe_allow_html=True)
with col2:
st.markdown(f"""
<div class="kpi-card">
<div class="kpi-value">{scores.get('precision', 0):.2%}</div>
<div class="kpi-label">Precision</div>
</div>
""", unsafe_allow_html=True)
with col3:
st.markdown(f"""
<div class="kpi-card">
<div class="kpi-value">{scores.get('recall', 0):.2%}</div>
<div class="kpi-label">Recall</div>
</div>
""", unsafe_allow_html=True)
with col4:
st.markdown(f"""
<div class="kpi-card">
<div class="kpi-value">{scores.get('f1_score', 0):.2%}</div>
<div class="kpi-label">F1 Score</div>
</div>
""", unsafe_allow_html=True)
with col5:
st.markdown(f"""
<div class="kpi-card">
<div class="kpi-value">{scores.get('auc_roc', 0):.4f}</div>
<div class="kpi-label">AUC-ROC</div>
</div>
""", unsafe_allow_html=True)
st.markdown('<div class="section-divider"></div>', unsafe_allow_html=True)
# System status row
col1, col2, col3 = st.columns(3)
with col1:
st.metric(label="Model Status", value="Active", delta="Ready")
with col2:
st.metric(label="Algorithm", value="XGBoost", delta="v2.0.3")
with col3:
st.metric(label="Processing", value="Pandas", delta="In-memory")
st.markdown('<div class="section-divider"></div>', unsafe_allow_html=True)
# Features section
st.markdown("### Capabilities")
col1, col2, col3, col4 = st.columns(4)
with col1:
st.markdown("""
<div class="feature-card">
<h4>Real-time Prediction</h4>
<p>Upload transactions and receive instant fraud probability scores with confidence levels.</p>
</div>
""", unsafe_allow_html=True)
with col2:
st.markdown("""
<div class="feature-card">
<h4>Performance Metrics</h4>
<p>Comprehensive model evaluation with ROC curves, confusion matrices, and feature analysis.</p>
</div>
""", unsafe_allow_html=True)
with col3:
st.markdown("""
<div class="feature-card">
<h4>Transaction Analysis</h4>
<p>Visualize patterns, detect anomalies, and explore statistical distributions interactively.</p>
</div>
""", unsafe_allow_html=True)
with col4:
st.markdown("""
<div class="feature-card">
<h4>Batch Processing</h4>
<p>Upload CSV files for bulk fraud screening with exportable results and summaries.</p>
</div>
""", unsafe_allow_html=True)
st.markdown('<div class="section-divider"></div>', unsafe_allow_html=True)
# Quick guide
st.markdown("### Quick Start Guide")
st.markdown("""
| Step | Action | Page |
|------|--------|------|
| 1 | Upload or enter transaction data for fraud scoring | **Predict Fraud** |
| 2 | Review model accuracy, ROC curves, and feature importance | **Performance** |
| 3 | Explore transaction distributions and correlations | **Transactions** |
""")
st.markdown('<div class="section-divider"></div>', unsafe_allow_html=True)
# Model details
col1, col2 = st.columns(2)
with col1:
st.markdown("### Model Architecture")
st.markdown("""
| Component | Detail |
|-----------|--------|
| Algorithm | Gradient Boosting (XGBoost) |
| Training Data | PaySim + Sparkov datasets |
| Features | 20+ engineered fraud indicators |
| Framework | Pandas + scikit-learn |
| Pipeline | DVC version control |
""")
with col2:
st.markdown("### Model Performance")
if scores:
st.markdown(f"""
| Metric | Score |
|--------|-------|
| Accuracy | {scores.get('accuracy', 0):.4f} |
| Precision | {scores.get('precision', 0):.4f} |
| Recall | {scores.get('recall', 0):.4f} |
| F1 Score | {scores.get('f1_score', 0):.4f} |
| AUC-ROC | {scores.get('auc_roc', 0):.4f} |
| Avg Precision | {scores.get('average_precision', 0):.4f} |
""")
else:
st.info("Run model evaluation to see metrics here.")
st.markdown("""
<div class="footer-text">
SENTINEL Fraud Detection System v2.0 | XGBoost + Pandas + DVC Pipeline
</div>
""", unsafe_allow_html=True)