Repository navigation
Expand file tree
/
Copy pathsimple_app.py
More file actions
238 lines (192 loc) ยท 6.91 KB
/
Copy pathsimple_app.py
File metadata and controls
238 lines (192 loc) ยท 6.91 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
#!/usr/bin/env python3
"""
Simplified AI Fraud Detection Monitor for Streamlit Cloud
"""
import streamlit as st
import pandas as pd
import numpy as np
import plotly.express as px
import plotly.graph_objects as go
import time
import datetime
import sys
import os
# Add src to path
sys.path.append('src')
st.set_page_config(
page_title="AI Fraud Detection Monitor",
page_icon="๐ก๏ธ",
layout="wide",
initial_sidebar_state="expanded"
)
# Custom CSS
st.markdown("""
<style>
.main-header {
font-size: 3rem;
font-weight: bold;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
text-align: center;
margin-bottom: 2rem;
}
.metric-card {
background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
padding: 1.5rem;
border-radius: 15px;
color: white;
box-shadow: 0 8px 32px rgba(0,0,0,0.1);
margin: 0.5rem 0;
}
</style>
""", unsafe_allow_html=True)
# Main header
st.markdown('<h1 class="main-header">๐ก๏ธ AI Fraud Detection Monitor</h1>', unsafe_allow_html=True)
# Sidebar
st.sidebar.title("๐๏ธ Controls")
st.sidebar.markdown("### Quick Actions")
if st.sidebar.button("๐ Refresh Data"):
st.rerun()
# Main content
tab1, tab2, tab3, tab4 = st.tabs(["๐ Dashboard", "๐ Streaming", "๐ Analytics", "โ๏ธ Settings"])
with tab1:
st.header("๐ Real-time Dashboard")
# Metrics
col1, col2, col3, col4 = st.columns(4)
with col1:
st.markdown('<div class="metric-card">', unsafe_allow_html=True)
st.metric("Transactions", "1,247", "+12%")
st.markdown('</div>', unsafe_allow_html=True)
with col2:
st.markdown('<div class="metric-card">', unsafe_allow_html=True)
st.metric("Fraud Detected", "8", "-3%")
st.markdown('</div>', unsafe_allow_html=True)
with col3:
st.markdown('<div class="metric-card">', unsafe_allow_html=True)
st.metric("Success Rate", "99.4%", "+0.2%")
st.markdown('</div>', unsafe_allow_html=True)
with col4:
st.markdown('<div class="metric-card">', unsafe_allow_html=True)
st.metric("Response Time", "0.8s", "-0.1s")
st.markdown('</div>', unsafe_allow_html=True)
# Indonesian Geographic Distribution
st.subheader("๐บ๏ธ Indonesian Geographic Distribution")
# Sample data for Indonesian provinces
indonesia_data = {
'Province': ['DKI Jakarta', 'Jawa Barat', 'Jawa Tengah', 'Jawa Timur', 'Sumatera Utara',
'Sulawesi Selatan', 'Banten', 'Bali', 'Sumatera Selatan', 'Riau'],
'Volume': [85, 72, 68, 65, 58, 52, 48, 45, 42, 38],
'Fraud_Rate': [0.8, 1.2, 0.9, 1.5, 0.7, 0.6, 0.8, 1.1, 0.5, 0.9]
}
df_geo = pd.DataFrame(indonesia_data)
# Create chart
fig = go.Figure()
# Add bars for volume
fig.add_trace(go.Bar(
x=df_geo['Province'],
y=df_geo['Volume'],
name='Transaction Volume',
marker_color='#667eea',
opacity=0.8
))
# Add line for fraud rate
fig.add_trace(go.Scatter(
x=df_geo['Province'],
y=df_geo['Fraud_Rate'],
name='Fraud Rate (%)',
yaxis='y2',
mode='lines+markers',
line=dict(color='#764ba2', width=3),
marker=dict(size=8, color='#764ba2')
))
fig.update_layout(
title="Transaction Volume & Fraud Rate by Indonesian Province",
xaxis_title="Province",
yaxis_title="Transaction Volume",
yaxis2=dict(title="Fraud Rate (%)", overlaying="y", side="right"),
height=500,
showlegend=True
)
st.plotly_chart(fig, use_container_width=True)
with tab2:
st.header("๐ Streaming System")
# Streaming controls
col1, col2, col3 = st.columns(3)
with col1:
if st.button("๐ Start System", type="primary"):
st.success("โ
Streaming system started!")
with col2:
if st.button("โน๏ธ Stop System"):
st.info("โน๏ธ Streaming system stopped!")
with col3:
tps = st.slider("TPS", 10, 200, 75, help="Transactions per second")
# Real-time transaction feed
st.subheader("๐ก Real-time Transaction Feed")
# Simulate real-time data
if st.button("๐ Start Generation"):
progress_bar = st.progress(0)
status_text = st.empty()
for i in range(10):
# Simulate transaction
transaction = {
'ID': f'TXN_{i+1:06d}',
'Amount': f'Rp {np.random.randint(10000, 1000000):,}',
'Location': np.random.choice(['DKI Jakarta', 'Jawa Barat', 'Jawa Tengah', 'Jawa Timur']),
'Risk': np.random.choice(['LOW', 'MEDIUM', 'HIGH']),
'Status': np.random.choice(['APPROVED', 'REVIEW', 'BLOCKED'])
}
# Display transaction
with st.container():
col1, col2, col3, col4, col5 = st.columns(5)
col1.write(transaction['ID'])
col2.write(transaction['Amount'])
col3.write(transaction['Location'])
col4.write(transaction['Risk'])
col5.write(transaction['Status'])
progress_bar.progress((i + 1) / 10)
status_text.text(f"Processing transaction {i+1}/10...")
time.sleep(0.5)
st.success("โ
Transaction generation completed!")
with tab3:
st.header("๐ Analytics")
# Payment network analysis
st.subheader("๐ณ Payment Network Analysis")
networks_data = {
'Network': ['Visa', 'Mastercard', 'JCB', 'UnionPay', 'Other'],
'Volume': [45, 35, 12, 5, 3],
'Fraud_Rate': [0.8, 1.1, 0.6, 1.3, 0.9]
}
df_networks = pd.DataFrame(networks_data)
fig_networks = px.bar(
df_networks,
x='Network',
y='Volume',
color='Fraud_Rate',
title="Payment Network Distribution (Indonesian Market)",
color_continuous_scale='RdYlGn_r'
)
st.plotly_chart(fig_networks, use_container_width=True)
with tab4:
st.header("โ๏ธ Settings")
st.subheader("๐ง System Configuration")
# Model status
st.info("โ
Fraud Detection Model: Loaded")
st.info("โ
Streaming System: Ready")
st.info("โ
Analytics Engine: Active")
# API status
st.subheader("๐ API Status")
st.success("โ
OpenAI API: Connected")
st.success("โ
FraudLabs Pro: Connected")
# Performance metrics
st.subheader("๐ Performance Metrics")
col1, col2 = st.columns(2)
with col1:
st.metric("CPU Usage", "23%")
st.metric("Memory Usage", "1.2GB")
with col2:
st.metric("Response Time", "0.8s")
st.metric("Throughput", "75 TPS")
# Footer
st.markdown("---")
st.markdown("๐ฎ๐ฉ **Indonesian Fraud Detection System** - Powered by AI & Machine Learning")