-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
461 lines (393 loc) · 15 KB
/
index.html
File metadata and controls
461 lines (393 loc) · 15 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Fraud Detection System</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
padding: 20px;
display: flex;
justify-content: center;
align-items: center;
}
.container {
background: white;
border-radius: 20px;
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
max-width: 800px;
width: 100%;
padding: 40px;
}
h1 {
color: #333;
margin-bottom: 10px;
font-size: 32px;
}
.subtitle {
color: #666;
margin-bottom: 30px;
font-size: 16px;
}
.form-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 20px;
margin-bottom: 30px;
}
.form-group {
display: flex;
flex-direction: column;
}
.form-group.full-width {
grid-column: 1 / -1;
}
label {
font-weight: 600;
margin-bottom: 8px;
color: #333;
font-size: 14px;
}
input,
select {
padding: 12px;
border: 2px solid #e0e0e0;
border-radius: 8px;
font-size: 14px;
transition: border-color 0.3s;
}
input:focus,
select:focus {
outline: none;
border-color: #667eea;
}
button {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
padding: 15px 40px;
border: none;
border-radius: 8px;
font-size: 16px;
font-weight: 600;
cursor: pointer;
transition: transform 0.2s, box-shadow 0.2s;
width: 100%;
}
button:hover {
transform: translateY(-2px);
box-shadow: 0 10px 20px rgba(102, 126, 234, 0.4);
}
button:active {
transform: translateY(0);
}
button:disabled {
background: #ccc;
cursor: not-allowed;
transform: none;
}
.result {
margin-top: 30px;
padding: 20px;
border-radius: 12px;
display: none;
animation: slideIn 0.5s;
}
@keyframes slideIn {
from {
opacity: 0;
transform: translateY(-20px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
.result.fraud {
background: #fee;
border: 2px solid #f44;
}
.result.legit {
background: #efe;
border: 2px solid #4f4;
}
.result-title {
font-size: 24px;
font-weight: bold;
margin-bottom: 10px;
}
.result.fraud .result-title {
color: #c00;
}
.result.legit .result-title {
color: #060;
}
.result-details {
font-size: 16px;
color: #333;
margin-bottom: 15px;
}
.hidden-features {
margin-top: 15px;
padding-top: 15px;
border-top: 2px dashed #ccc;
}
.toggle-features {
background: none;
border: none;
color: #667eea;
cursor: pointer;
font-size: 14px;
font-weight: 600;
padding: 8px 0;
text-decoration: underline;
width: auto;
}
.toggle-features:hover {
color: #764ba2;
transform: none;
box-shadow: none;
}
.features-content {
display: none;
margin-top: 15px;
background: #f9f9f9;
padding: 15px;
border-radius: 8px;
font-size: 14px;
}
.features-content.show {
display: block;
animation: slideIn 0.3s;
}
.feature-item {
padding: 8px 0;
display: flex;
justify-content: space-between;
border-bottom: 1px solid #e0e0e0;
}
.feature-item:last-child {
border-bottom: none;
}
.feature-label {
font-weight: 600;
color: #555;
}
.feature-value {
color: #333;
}
.error {
background: #fee;
border: 2px solid #f44;
color: #c00;
padding: 15px;
border-radius: 8px;
margin-top: 20px;
display: none;
}
.loading {
display: none;
text-align: center;
margin-top: 20px;
color: #667eea;
font-weight: 600;
}
@media (max-width: 600px) {
.form-grid {
grid-template-columns: 1fr;
}
.container {
padding: 20px;
}
}
</style>
</head>
<body>
<div class="container">
<h1>🔍 Fraud Detection System</h1>
<p class="subtitle">Enter transaction details to check for fraudulent activity</p>
<form id="fraudForm">
<div class="form-grid">
<div class="form-group">
<label for="category">Category</label>
<select id="category" required>
<option value="">Select category</option>
<option value="gas_transport">Gas & Transport</option>
<option value="grocery_pos">Grocery</option>
<option value="entertainment">Entertainment</option>
<option value="food_dining">Food & Dining</option>
<option value="shopping_net">Online Shopping</option>
<option value="shopping_pos">In-Store Shopping</option>
<option value="home">Home</option>
<option value="health_fitness">Health & Fitness</option>
<option value="travel">Travel</option>
<option value="misc_net">Misc Online</option>
<option value="misc_pos">Misc In-Store</option>
<option value="personal_care">Personal Care</option>
<option value="kids_pets">Kids & Pets</option>
</select>
</div>
<div class="form-group">
<label for="amt">Amount ($)</label>
<input type="number" id="amt" step="0.01" min="0" required placeholder="0.00">
</div>
<div class="form-group">
<label for="gender">Gender</label>
<select id="gender" required>
<option value="">Select gender</option>
<option value="M">Male</option>
<option value="F">Female</option>
</select>
</div>
<div class="form-group">
<label for="job">Job</label>
<input type="text" id="job" required placeholder="e.g., Engineer, Teacher">
</div>
<div class="form-group">
<label for="distance">Distance (km)</label>
<input type="number" id="distance" step="0.1" min="0" required placeholder="0.0">
</div>
<div class="form-group">
<label for="age">Cardholder Age</label>
<input type="number" id="age" min="18" max="120" required placeholder="25">
</div>
<div class="form-group full-width">
<label for="dayofweek">Day of Week</label>
<select id="dayofweek" required>
<option value="">Select day</option>
<option value="Monday">Monday</option>
<option value="Tuesday">Tuesday</option>
<option value="Wednesday">Wednesday</option>
<option value="Thursday">Thursday</option>
<option value="Friday">Friday</option>
<option value="Saturday">Saturday</option>
<option value="Sunday">Sunday</option>
</select>
</div>
</div>
<button type="submit" id="submitBtn">Analyze Transaction</button>
</form>
<div class="loading" id="loading">
Analyzing transaction...
</div>
<div class="error" id="error"></div>
<div class="result" id="result">
<div class="result-title" id="resultTitle"></div>
<div class="result-details" id="resultDetails"></div>
<div class="hidden-features">
<button class="toggle-features" id="toggleFeatures" type="button">
🔍 Show Generated Features
</button>
<div class="features-content" id="featuresContent"></div>
</div>
</div>
</div>
<script>
const API_URL = 'http://127.0.0.1:8000';
document.getElementById('fraudForm').addEventListener('submit', async (e) => {
e.preventDefault();
const submitBtn = document.getElementById('submitBtn');
const loading = document.getElementById('loading');
const result = document.getElementById('result');
const error = document.getElementById('error');
// Hide previous results
result.style.display = 'none';
error.style.display = 'none';
// Show loading
loading.style.display = 'block';
submitBtn.disabled = true;
// Collect form data
const data = {
category: document.getElementById('category').value,
amt: parseFloat(document.getElementById('amt').value),
gender: document.getElementById('gender').value,
job: document.getElementById('job').value,
distance: parseFloat(document.getElementById('distance').value),
cardholder_age: parseInt(document.getElementById('age').value),
dayofweek: document.getElementById('dayofweek').value
};
try {
const response = await fetch(`${API_URL}/predict`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(data)
});
if (!response.ok) {
throw new Error('API request failed');
}
const prediction = await response.json();
// Display result
result.style.display = 'block';
result.className = 'result ' + (prediction.label === 'FRAUD' ? 'fraud' : 'legit');
document.getElementById('resultTitle').textContent =
prediction.label === 'FRAUD' ? '⚠️ FRAUD DETECTED' : '✅ LEGITIMATE TRANSACTION';
document.getElementById('resultDetails').textContent =
`Confidence: ${(prediction.probability * 100).toFixed(2)}%`;
// Display generated features if available
if (prediction.generated_features) {
const featuresContent = document.getElementById('featuresContent');
const features = prediction.generated_features;
featuresContent.innerHTML = `
<div class="feature-item">
<span class="feature-label">City Population:</span>
<span class="feature-value">${features.city_pop.toLocaleString()}</span>
</div>
<div class="feature-item">
<span class="feature-label">Transaction Hour:</span>
<span class="feature-value">${features.trans_hour}:00</span>
</div>
<div class="feature-item">
<span class="feature-label">Night Transaction:</span>
<span class="feature-value">${features.night_trans ? 'Yes' : 'No'}</span>
</div>
<div class="feature-item">
<span class="feature-label">Transactions in Last 30min:</span>
<span class="feature-value">${features.trans_30min}</span>
</div>
<div class="feature-item">
<span class="feature-label">Amount Spent in Last 30min:</span>
<span class="feature-value">${features.amt_30min.toLocaleString()}</span>
</div>
<div class="feature-item">
<span class="feature-label">Time Since Last Transaction:</span>
<span class="feature-value">${features.time_since_last_trans} minutes</span>
</div>
<div class="feature-item">
<span class="feature-label">Amount vs Average User Amount:</span>
<span class="feature-value">${features.amt_vs_avg_user_amt.toFixed(2)}%</span>
</div>
`;
}
} catch (err) {
error.style.display = 'block';
error.textContent = '❌ Error: Could not connect to API. Make sure your FastAPI server is running on http://127.0.0.1:8000';
console.error(err);
} finally {
loading.style.display = 'none';
submitBtn.disabled = false;
}
});
// Toggle features visibility
document.getElementById('toggleFeatures').addEventListener('click', function () {
const featuresContent = document.getElementById('featuresContent');
const toggleBtn = document.getElementById('toggleFeatures');
if (featuresContent.classList.contains('show')) {
featuresContent.classList.remove('show');
toggleBtn.textContent = '🔍 Show Generated Features';
} else {
featuresContent.classList.add('show');
toggleBtn.textContent = '🔼 Hide Generated Features';
}
});
</script>
</body>
</html>