Anirudhreddy19 commited on
Commit
cee28d3
·
verified ·
1 Parent(s): 4f3dd97

Create index.html

Browse files
Files changed (1) hide show
  1. index.html +241 -0
index.html ADDED
@@ -0,0 +1,241 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
+ <title>Payment Credit Dashboard</title>
7
+ <style>
8
+ * { box-sizing: border-box; margin: 0; padding: 0; }
9
+ body {
10
+ font-family: Arial, sans-serif;
11
+ background: linear-gradient(135deg, #0f172a, #1e293b);
12
+ color: #fff; min-height: 100vh; padding: 20px;
13
+ }
14
+ .container { max-width: 1400px; margin: 0 auto; }
15
+ .title { text-align: center; margin-bottom: 24px; }
16
+ .title h1 { color: #38bdf8; margin-bottom: 8px; }
17
+ .subtitle { color: #cbd5e1; }
18
+ .dashboard { display: grid; grid-template-columns: 1.2fr 0.8fr; gap: 20px; }
19
+ .card {
20
+ background: rgba(255, 255, 255, 0.06);
21
+ border: 1px solid rgba(255, 255, 255, 0.12);
22
+ border-radius: 14px; padding: 20px;
23
+ backdrop-filter: blur(8px); margin-bottom: 20px;
24
+ }
25
+ .card h2 { color: #38bdf8; margin-bottom: 16px; font-size: 1.05rem; }
26
+ .state-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
27
+ .state-box, .mini-box, .list-box {
28
+ background: rgba(255, 255, 255, 0.05);
29
+ border-radius: 10px; padding: 12px;
30
+ }
31
+ .label { font-size: 0.75rem; color: #94a3b8; text-transform: uppercase; margin-bottom: 6px; }
32
+ .value { font-size: 1rem; font-weight: 700; }
33
+ .hero-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 16px; }
34
+ .pill { display: inline-block; padding: 6px 10px; border-radius: 999px; font-size: 0.8rem; font-weight: 700; }
35
+ .low { background: rgba(34, 197, 94, 0.2); color: #86efac; }
36
+ .medium { background: rgba(250, 204, 21, 0.18); color: #fde68a; }
37
+ .high { background: rgba(239, 68, 68, 0.18); color: #fca5a5; }
38
+ .btn-row { display: flex; flex-wrap: wrap; gap: 10px; }
39
+ button {
40
+ border: none; border-radius: 10px; padding: 12px 16px;
41
+ font-weight: 700; cursor: pointer; transition: 0.2s ease;
42
+ }
43
+ button:hover { transform: translateY(-1px); }
44
+ .primary { background: #38bdf8; color: #082f49; }
45
+ .secondary { background: #1e293b; color: #e2e8f0; border: 1px solid rgba(255, 255, 255, 0.15); }
46
+ .action-btn { background: #334155; color: #fff; }
47
+ .action-btn:hover { background: #475569; }
48
+ ul { list-style: none; padding-left: 0; }
49
+ li { padding: 8px 0; border-bottom: 1px solid rgba(255, 255, 255, 0.08); }
50
+ li:last-child { border-bottom: none; }
51
+ .good { color: #86efac; font-weight: 700; }
52
+ .bad { color: #fca5a5; font-weight: 700; }
53
+ .reward { font-size: 2rem; font-weight: 800; color: #f8fafc; }
54
+ .muted { color: #cbd5e1; font-size: 0.95rem; }
55
+ .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
56
+ .history-item {
57
+ padding: 12px; border-radius: 10px;
58
+ background: rgba(255, 255, 255, 0.05); margin-bottom: 10px;
59
+ }
60
+ .history-top {
61
+ display: flex; justify-content: space-between; gap: 10px;
62
+ font-weight: 700; margin-bottom: 4px; text-transform: capitalize;
63
+ }
64
+ .right-col { position: sticky; top: 20px; align-self: start; }
65
+ @media (max-width: 980px) {
66
+ .dashboard { grid-template-columns: 1fr; }
67
+ .hero-row, .state-grid { grid-template-columns: 1fr; }
68
+ .right-col { position: static; }
69
+ }
70
+ </style>
71
+ </head>
72
+ <body>
73
+ <div class="container">
74
+ <div class="title">
75
+ <h1>Payment Credit Dashboard</h1>
76
+ <div class="subtitle">Evaluate multiple actions on the same transaction until you reset.</div>
77
+ </div>
78
+ <div class="dashboard">
79
+ <div>
80
+ <div class="card">
81
+ <h2>Current Transaction</h2>
82
+ <div class="hero-row">
83
+ <div class="mini-box">
84
+ <div class="label">Transaction ID</div>
85
+ <div class="value mono" id="transaction_id">-</div>
86
+ </div>
87
+ <div class="mini-box">
88
+ <div class="label">Risk Band</div>
89
+ <div id="risk_band_wrap"><span class="pill" id="risk_band">-</span></div>
90
+ </div>
91
+ <div class="mini-box">
92
+ <div class="label">Recommended Action</div>
93
+ <div class="value" id="recommended_action">-</div>
94
+ </div>
95
+ </div>
96
+ <div class="state-grid">
97
+ <div class="state-box"><div class="label">Amount</div><div class="value" id="amount">-</div></div>
98
+ <div class="state-box"><div class="label">Credit Score</div><div class="value" id="credit_score">-</div></div>
99
+ <div class="state-box"><div class="label">Available Credit</div><div class="value" id="available_credit">-</div></div>
100
+ <div class="state-box"><div class="label">Monthly Spend</div><div class="value" id="monthly_spend">-</div></div>
101
+ <div class="state-box"><div class="label">Debt To Income</div><div class="value" id="debt_to_income">-</div></div>
102
+ <div class="state-box"><div class="label">Payment History</div><div class="value" id="payment_history">-</div></div>
103
+ <div class="state-box"><div class="label">Credit Utilization</div><div class="value" id="credit_utilization">-</div></div>
104
+ <div class="state-box"><div class="label">Last Payment Date</div><div class="value" id="last_payment_date">-</div></div>
105
+ <div class="state-box"><div class="label">Account Age</div><div class="value" id="account_age_months">-</div></div>
106
+ </div>
107
+ </div>
108
+ <div class="card">
109
+ <h2>Actions</h2>
110
+ <div class="btn-row" style="margin-bottom: 12px;">
111
+ <button class="primary" onclick="resetEnvironment()">Reset Environment</button>
112
+ </div>
113
+ <div class="btn-row">
114
+ <button class="action-btn" onclick="takeAction('approve_card_1')">Approve Card 1</button>
115
+ <button class="action-btn" onclick="takeAction('approve_card_2')">Approve Card 2</button>
116
+ <button class="action-btn" onclick="takeAction('route_to_debit')">Route to Debit</button>
117
+ <button class="action-btn" onclick="takeAction('convert_to_emi')">Convert to EMI</button>
118
+ <button class="action-btn" onclick="takeAction('delay_purchase')">Delay Purchase</button>
119
+ <button class="action-btn" onclick="takeAction('decline')">Decline</button>
120
+ </div>
121
+ </div>
122
+ <div class="card">
123
+ <h2>Reasons</h2>
124
+ <ul id="reasons_list"><li class="muted">No evaluation yet.</li></ul>
125
+ </div>
126
+ <div class="card">
127
+ <h2>Action Leaderboard</h2>
128
+ <ul id="leaderboard_list"><li class="muted">No evaluation yet.</li></ul>
129
+ </div>
130
+ <div class="card">
131
+ <h2>Policy Checks</h2>
132
+ <ul id="policy_checks_list"><li class="muted">No evaluation yet.</li></ul>
133
+ </div>
134
+ </div>
135
+ <div class="right-col">
136
+ <div class="card">
137
+ <h2>Last Reward</h2>
138
+ <div class="reward" id="last_reward">-</div>
139
+ <div class="muted" id="last_action">Action tested: -</div>
140
+ </div>
141
+ <div class="card">
142
+ <h2>Action History</h2>
143
+ <div id="audit_log"><div class="muted">No actions taken yet.</div></div>
144
+ </div>
145
+ </div>
146
+ </div>
147
+ </div>
148
+ <script>
149
+ const API = "http://127.0.0.1:8000";
150
+ const money = (n) => typeof n === "number" ? new Intl.NumberFormat("en-IN", { style: "currency", currency: "INR", maximumFractionDigits: 2 }).format(n) : "-";
151
+ function setText(id, value) { const el = document.getElementById(id); if (el) el.textContent = value ? value : "-"; }
152
+ function setRiskBand(band) {
153
+ const el = document.getElementById("risk_band");
154
+ el.textContent = band || "-";
155
+ el.className = "pill " + (band || "");
156
+ }
157
+ function renderState(state) {
158
+ if (!state) return;
159
+ setText("transaction_id", state.transaction_id);
160
+ setText("amount", money(state.amount));
161
+ setText("credit_score", state.credit_score);
162
+ setText("available_credit", money(state.available_credit));
163
+ setText("monthly_spend", money(state.monthly_spend));
164
+ setText("debt_to_income", state.debt_to_income + "%");
165
+ setText("payment_history", state.payment_history + "%");
166
+ setText("credit_utilization", state.credit_utilization + "%");
167
+ setText("last_payment_date", state.last_payment_date);
168
+ setText("account_age_months", state.account_age_months + " months");
169
+ }
170
+ function renderReasons(reasons) {
171
+ reasons = reasons || [];
172
+ const box = document.getElementById("reasons_list");
173
+ if (!reasons.length) { box.innerHTML = "<li class=\"muted\">No evaluation yet.</li>"; return; }
174
+ box.innerHTML = reasons.map(r => "<li>" + r + "</li>").join("");
175
+ }
176
+ function renderLeaderboard(items) {
177
+ items = items || [];
178
+ const box = document.getElementById("leaderboard_list");
179
+ if (!items.length) { box.innerHTML = "<li class=\"muted\">No evaluation yet.</li>"; return; }
180
+ box.innerHTML = items.map((x, i) => "<li><strong>#" + (i + 1) + " " + x.action.replaceAll("_", " ") + "</strong><span style=\"float:right\">" + x.reward.toFixed(4) + "</span></li>").join("");
181
+ }
182
+ function renderPolicyChecks(items) {
183
+ items = items || [];
184
+ const box = document.getElementById("policy_checks_list");
185
+ if (!items.length) { box.innerHTML = "<li class=\"muted\">No evaluation yet.</li>"; return; }
186
+ box.innerHTML = items.map(x => "<li><div><strong>" + x.name + "</strong> - <span class=\"" + (x.passed ? "good" : "bad") + "\">" + (x.passed ? "PASS" : "FAIL") + "</span></div><div class=\"muted\">" + x.detail + "</div></li>").join("");
187
+ }
188
+ async function loadAuditLog() {
189
+ const res = await fetch(API + "/audit-log");
190
+ const data = await res.json();
191
+ const box = document.getElementById("audit_log");
192
+ if (!data.length) { box.innerHTML = "<div class=\"muted\">No actions taken yet.</div>"; return; }
193
+ box.innerHTML = data.slice().reverse().map(item => "<div class=\"history-item\"><div class=\"history-top\"><span>" + item.action.replaceAll("_", " ") + "</span><span>" + item.reward.toFixed(4) + "</span></div><div class=\"muted\">" + item.timestamp + " - " + item.transaction_id + "</div><div class=\"muted\">Risk: " + item.risk_band + " - Recommended: " + item.recommended_action.replaceAll("_", " ") + "</div></div>").join("");
194
+ }
195
+ async function loadState() {
196
+ const res = await fetch(API + "/state");
197
+ const state = await res.json();
198
+ renderState(state);
199
+ setRiskBand("");
200
+ setText("recommended_action", "-");
201
+ renderReasons([]);
202
+ renderLeaderboard([]);
203
+ renderPolicyChecks([]);
204
+ setText("last_reward", "-");
205
+ setText("last_action", "Action tested: -");
206
+ await loadAuditLog();
207
+ }
208
+ async function resetEnvironment() {
209
+ const res = await fetch(API + "/reset", { method: "POST" });
210
+ const state = await res.json();
211
+ renderState(state);
212
+ setRiskBand("");
213
+ setText("recommended_action", "-");
214
+ renderReasons([]);
215
+ renderLeaderboard([]);
216
+ renderPolicyChecks([]);
217
+ setText("last_reward", "-");
218
+ setText("last_action", "Action tested: -");
219
+ await loadAuditLog();
220
+ }
221
+ async function takeAction(action) {
222
+ const res = await fetch(API + "/step", {
223
+ method: "POST",
224
+ headers: { "Content-Type": "application/json" },
225
+ body: JSON.stringify({ action: action })
226
+ });
227
+ const data = await res.json();
228
+ renderState(data.state);
229
+ setRiskBand(data.risk_band);
230
+ setText("recommended_action", data.recommended_action.replaceAll("_", " "));
231
+ renderReasons(data.reasons || []);
232
+ renderLeaderboard(data.leaderboard || []);
233
+ renderPolicyChecks(data.policy_checks || []);
234
+ setText("last_reward", Number(data.reward).toFixed(4));
235
+ setText("last_action", "Action tested: " + data.action.replaceAll("_", " "));
236
+ await loadAuditLog();
237
+ }
238
+ loadState();
239
+ </script>
240
+ </body>
241
+ </html>