-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathui.html
More file actions
300 lines (257 loc) · 8.93 KB
/
ui.html
File metadata and controls
300 lines (257 loc) · 8.93 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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Financial Advice LLM</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
padding: 20px;
}
.container {
background: white;
border-radius: 12px;
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
padding: 40px;
max-width: 600px;
width: 100%;
}
h1 {
color: #333;
margin-bottom: 10px;
font-size: 28px;
}
.subtitle {
color: #666;
margin-bottom: 30px;
font-size: 14px;
}
.form-group {
margin-bottom: 20px;
}
label {
display: block;
color: #333;
font-weight: 600;
margin-bottom: 8px;
font-size: 14px;
}
textarea {
width: 100%;
padding: 12px;
border: 2px solid #e0e0e0;
border-radius: 8px;
font-family: inherit;
font-size: 14px;
resize: vertical;
transition: border-color 0.3s ease;
}
textarea:focus {
outline: none;
border-color: #667eea;
box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}
button {
width: 100%;
padding: 12px 24px;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
border: none;
border-radius: 8px;
font-size: 16px;
font-weight: 600;
cursor: pointer;
transition: transform 0.2s ease, box-shadow 0.2s ease;
}
button:hover {
transform: translateY(-2px);
box-shadow: 0 8px 20px rgba(102, 126, 234, 0.3);
}
button:active {
transform: translateY(0);
}
.response-section {
margin-top: 30px;
}
.response-label {
color: #333;
font-weight: 600;
margin-bottom: 12px;
font-size: 14px;
display: block;
}
#response {
background: #f5f5f5;
border-left: 4px solid #667eea;
padding: 16px;
border-radius: 6px;
color: #333;
line-height: 1.6;
min-height: 60px;
white-space: pre-wrap;
word-break: break-word;
}
#response:empty {
background: #f5f5f5;
color: #999;
}
#response:empty::before {
content: "Response will appear here...";
color: #999;
}
.loading {
color: #667eea;
font-style: italic;
}
.samples-section {
margin-bottom: 25px;
padding: 16px;
background: #f9f9f9;
border-radius: 8px;
border: 1px solid #e0e0e0;
}
.samples-label {
color: #333;
font-weight: 600;
margin-bottom: 12px;
font-size: 14px;
display: block;
}
.samples-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
.sample-btn {
padding: 8px 12px;
background: white;
color: #667eea;
border: 1.5px solid #667eea;
border-radius: 6px;
font-size: 12px;
font-weight: 500;
cursor: pointer;
transition: all 0.2s ease;
text-align: left;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.sample-btn:hover {
background: #f0f0ff;
transform: translateY(-1px);
}
.sample-btn.active {
background: #667eea;
color: white;
}
@media (max-width: 500px) {
.samples-grid {
grid-template-columns: 1fr;
}
}
</style>
</head>
<body>
<div class="container">
<h1>💰 Financial Advisor</h1>
<p class="subtitle">Get personalized financial advice about budgeting & saving</p>
<div class="samples-section">
<label class="samples-label">📋 Sample Query:</label>
<div class="samples-grid" id="samplesGrid"></div>
</div>
<div class="form-group">
<label for="query">Your Question:</label>
<textarea id="query" rows="8" placeholder="Ask about budgeting, saving strategies, financial planning, etc.">
Profile: subscription-maximizer.
Window: last 30 days.
Totals: Income HKD 19,359; Spend HKD 20,918; Net HKD -1,559.
Top spend: Rent:11684, Shopping:3713, Utilities:1434.
Recurring: HKD 11,888 across 2 items.
Delivery orders (approx): 0.
Task: Suggest 2-3 actionable steps to reduce spend with ~HKD monthly savings estimates.
</textarea>
</div>
<button onclick="sendQuery()">Get Advice</button>
<div class="response-section">
<label class="response-label">Response:</label>
<div id="response"></div>
</div>
</div>
<script>
const prompts = [
"Profile: subscription-maximizer.\nWindow: last 30 days.\nTotals: Income HKD 19,359; Spend HKD 20,918; Net HKD -1,559.\nTop spend: Rent:11684, Shopping:3713, Utilities:1434.\nRecurring: HKD 11,888 across 2 items.\nDelivery orders (approx): 0.\nTask: Suggest 2-3 actionable steps to reduce spend with ~HKD monthly savings estimates.",
"Profile: stretched renter.\nWindow: last 90 days.\nTotals: Income SGD 64,674; Spend SGD 61,870; Net SGD 2,804.\nTop spend: Rent:40851, Utilities:4604, Shopping:4331.\nRecurring: SGD 41,631 across 1 items.\nDelivery orders (approx): 10.\nTask: Provide 2-3 practical budgeting suggestions with estimated SGD monthly savings.",
"Profile: aggressive saver.\nWindow: last 180 days.\nTotals: Income SGD 226,446; Spend SGD 76,245; Net SGD 150,201.\nTop spend: Rent:26586, Shopping:15762, Entertainment:8785.\nRecurring: SGD 27,354 across 1 items.\nDelivery orders (approx): 11.\nTask: Suggest 2-3 actionable steps to reduce spend with ~SGD monthly savings estimates.",
"Profile: unsteady-income spender.\nWindow: last 7 days.\nTotals: Income HKD 0; Spend HKD 1,816; Net HKD -1,816.\nTop spend: Dining:723, Entertainment:670, Groceries:335.\nRecurring: HKD 0 across 0 items.\nDelivery orders (approx): 2.\nTask: Provide 2-3 practical budgeting suggestions with estimated HKD monthly savings.",
"Profile: shopper with flexible spend.\nWindow: last 30 days.\nTotals: Income HKD 12,484; Spend HKD 13,323; Net HKD -839.\nTop spend: Rent:5493, Shopping:2917, Utilities:1264.\nRecurring: HKD 5,590 across 1 items.\nDelivery orders (approx): 1.\nTask: Give 2-3 concrete budgeting tips with rough HKD savings per month.",
"Profile: delivery-focused foodie.\nWindow: last 45 days.\nTotals: Income USD 24,293; Spend USD 25,108; Net USD -815.\nTop spend: Rent:10694, Shopping:5538, Entertainment:2644.\nRecurring: USD 10,843 across 1 items.\nDelivery orders (approx): 6.\nTask: Give 2-3 concrete budgeting tips with rough USD savings per month.",
];
function initializeSamples() {
const grid = document.getElementById("samplesGrid");
prompts.forEach((prompt, index) => {
const profileMatch = prompt.match(/Profile: ([^.]+)/);
const profile = profileMatch ? profileMatch[1] : `Sample ${index + 1}`;
const btn = document.createElement("button");
btn.type = "button";
btn.className = "sample-btn";
btn.textContent = profile;
btn.onclick = () => selectSample(index, btn);
grid.appendChild(btn);
});
}
function selectSample(index, btn) {
const textarea = document.getElementById("query");
textarea.value = prompts[index];
// Update active state
document.querySelectorAll(".sample-btn").forEach(b => b.classList.remove("active"));
btn.classList.add("active");
// Focus textarea for better UX
textarea.focus();
}
async function sendQuery() {
const query = document.getElementById("query").value;
const responseDiv = document.getElementById("response");
if (!query.trim()) {
responseDiv.innerText = "Please enter a question.";
return;
}
const button = document.querySelector("button");
button.disabled = true;
button.innerText = "Loading...";
responseDiv.className = "loading";
responseDiv.innerText = "Fetching advice...";
try {
const res = await fetch("https://1lv2h7f7mi.execute-api.us-east-1.amazonaws.com/prod/predict", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ query })
});
const data = await res.json();
const output = data.response.split("-").join("\n\n").trim();
responseDiv.className = "";
responseDiv.innerText = output ?? data.error ?? "Unexpected error";
} catch (error) {
responseDiv.className = "";
responseDiv.innerText = "Error: " + error.message;
} finally {
button.disabled = false;
button.innerText = "Get Advice";
}
}
// Initialize sample buttons on page load
document.addEventListener("DOMContentLoaded", initializeSamples);
</script>
</body>
</html>