File size: 7,330 Bytes
08d6be3 |
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 |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>FraudShield AI | Transaction Monitoring</title>
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700;800&display=swap" rel="stylesheet">
</head>
<body>
<div class="container">
<header>
<h1>FraudShield AI</h1>
<p>Advanced Real-time Credit Card Fraud Detection Pipeline</p>
</header>
<div class="main-layout">
<div class="card">
<div class="card-title">
<span>🔍</span> Sample Transactions
</div>
<div class="tabs">
<div class="tab active" id="tab-fraud">Fraud Cases</div>
<div class="tab" id="tab-normal">Legitimate</div>
</div>
<div class="samples-list" id="samples-container">
<!-- Samples will be injected here -->
<p style="text-align: center; color: #64748b;">Loading samples...</p>
</div>
</div>
<div class="card">
<div class="card-title">
<span>⚙️</span> Analysis Engine
</div>
<form id="prediction-form">
<div class="form-group">
<div>
<label style="font-size: 0.8rem; color: #94a3b8;">Amount ($)</label>
<input type="number" id="Amount" class="input-field" step="0.01" required placeholder="89.99">
</div>
<div>
<label style="font-size: 0.8rem; color: #94a3b8;">Time (Seconds)</label>
<input type="number" id="Time" class="input-field" required placeholder="0">
</div>
</div>
<div style="margin-bottom: 0.5rem; font-size: 0.8rem; color: #94a3b8;">PCA Components (V1 - V28)</div>
<div style="max-height: 200px; overflow-y: auto; padding-right: 5px;" id="v-inputs">
<!-- V1 to V28 inputs will be injected -->
</div>
<button type="submit" class="btn">Analyze Transaction</button>
</form>
<div id="result-area">
<div class="result-title" id="res-title">SAFE</div>
<div class="result-conf" id="res-conf">Confidence: 99.8%</div>
</div>
</div>
</div>
</div>
<script>
let samples = { fraud: [], normal: [] };
let activeTab = 'fraud';
// Initialize V inputs
const vContainer = document.getElementById('v-inputs');
for (let i = 1; i <= 28; i++) {
const div = document.createElement('div');
div.className = 'form-group';
div.style.marginBottom = '0.5rem';
div.innerHTML = `
<div style="grid-column: span 2">
<input type="number" step="0.000001" id="V${i}" class="input-field" placeholder="V${i} component" value="0">
</div>
`;
vContainer.appendChild(div);
}
// Fetch samples
fetch('/get_samples')
.then(res => res.json())
.then(data => {
samples = data;
renderSamples();
});
function renderSamples() {
const container = document.getElementById('samples-container');
container.innerHTML = '';
const list = activeTab === 'fraud' ? samples.fraud : samples.normal;
list.forEach(item => {
const el = document.createElement('div');
el.className = 'sample-item';
el.innerHTML = `
<div class="amount">$${item.Amount.toFixed(2)}</div>
<div class="meta">
<span>Time: ${Math.floor(item.Time)}s</span>
<span>PCA: Mixed</span>
</div>
`;
el.onclick = () => fillForm(item);
container.appendChild(el);
});
}
function fillForm(item) {
document.getElementById('Amount').value = item.Amount;
document.getElementById('Time').value = item.Time;
for (let i = 1; i <= 28; i++) {
document.getElementById(`V${i}`).value = item[`V${i}`];
}
// Trigger animation
const card = document.querySelectorAll('.card')[1];
card.style.borderColor = 'var(--primary)';
setTimeout(() => card.style.borderColor = 'var(--glass-border)', 500);
}
// Tabs
document.getElementById('tab-fraud').onclick = () => {
activeTab = 'fraud';
document.getElementById('tab-fraud').classList.add('active');
document.getElementById('tab-normal').classList.remove('active');
renderSamples();
};
document.getElementById('tab-normal').onclick = () => {
activeTab = 'normal';
document.getElementById('tab-normal').classList.add('active');
document.getElementById('tab-fraud').classList.remove('active');
renderSamples();
};
// Form Submit
document.getElementById('prediction-form').onsubmit = async (e) => {
e.preventDefault();
const btn = e.target.querySelector('button');
btn.innerHTML = 'Processing...';
btn.disabled = true;
const data = {
Amount: document.getElementById('Amount').value,
Time: document.getElementById('Time').value
};
for (let i = 1; i <= 28; i++) {
data[`V${i}`] = document.getElementById(`V${i}`).value;
}
try {
const res = await fetch('/predict', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data)
});
const result = await res.json();
const resArea = document.getElementById('result-area');
resArea.style.display = 'block';
resArea.className = result.is_fraud ? 'result-fraud' : 'result-safe';
document.getElementById('res-title').innerText = result.class;
document.getElementById('res-conf').innerText = `Confidence: ${result.confidence.toFixed(2)}%`;
} catch (err) {
alert('Analysis failed: ' + err.message);
} finally {
btn.innerHTML = 'Analyze Transaction';
btn.disabled = false;
}
};
</script>
</body>
</html>
|