-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdashboard.html
More file actions
532 lines (472 loc) · 23.7 KB
/
dashboard.html
File metadata and controls
532 lines (472 loc) · 23.7 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
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>JPLoRA — LoRA 微调 Dashboard</title>
<style>
* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
--bg: #0f1117;
--surface: #1a1d27;
--border: #2a2d3e;
--accent: #00d4aa;
--accent2: #6c63ff;
--warn: #ffb347;
--text: #e8eaf6;
--muted: #7b7f9e;
--loss-col: #ff6b6b;
--acc-col: #00d4aa;
}
body { background: var(--bg); color: var(--text); font-family: 'SF Pro Display', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; min-height: 100vh; }
/* ── Header ── */
header {
background: var(--surface); border-bottom: 1px solid var(--border);
padding: 16px 32px; display: flex; align-items: center; justify-content: space-between;
}
header h1 { font-size: 20px; font-weight: 700; }
header h1 span { color: var(--accent); }
#status-badge {
font-size: 12px; padding: 4px 12px; border-radius: 20px;
background: #1e3a2f; color: var(--accent); border: 1px solid var(--accent);
}
#status-badge.training { background: #2a1e3a; color: var(--accent2); border-color: var(--accent2); }
#status-badge.done { background: #1e3a2f; color: var(--accent); border-color: var(--accent); }
#status-badge.waiting { background: #2d2a1a; color: var(--warn); border-color: var(--warn); }
/* ── Tabs ── */
.tabs {
background: var(--surface); border-bottom: 1px solid var(--border);
padding: 0 32px; display: flex; gap: 4px;
}
.tab {
padding: 12px 20px; cursor: pointer; font-size: 13px; font-weight: 500;
color: var(--muted); border-bottom: 2px solid transparent; transition: all 0.2s;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
/* ── Tab content ── */
.tab-content { display: none; }
.tab-content.active { display: block; }
main { max-width: 1200px; margin: 0 auto; padding: 24px 32px; }
/* ── Stat cards ── */
.cards { display: grid; grid-template-columns: repeat(5, 1fr); gap: 16px; margin-bottom: 28px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px 18px; }
.card-label-en { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
.card-label-zh { font-size: 10px; color: var(--muted); margin-top: 1px; }
.card-value { font-size: 28px; font-weight: 700; margin-top: 8px; font-variant-numeric: tabular-nums; }
.card-value.green { color: var(--accent); }
.card-value.purple { color: var(--accent2); }
.card-value.red { color: var(--loss-col); }
.card-value.warn { color: var(--warn); }
/* ── Charts ── */
.charts { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 28px; }
.chart-box { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 18px; }
.chart-title { font-size: 13px; font-weight: 600; margin-bottom: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
canvas { width: 100%; display: block; }
/* ── Eval results ── */
.eval-box { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 20px 24px; }
.eval-title { font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 16px; }
.eval-summary { display: flex; gap: 32px; margin-bottom: 20px; }
.eval-big { font-size: 36px; font-weight: 700; color: var(--accent); }
.eval-big-label { font-size: 12px; color: var(--muted); margin-top: 4px; }
.eval-mode { font-size: 13px; color: var(--muted); margin-top: 6px; }
.cat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.cat-card { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; }
.cat-name { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.cat-bar-wrap { height: 6px; background: var(--border); border-radius: 3px; margin-bottom: 4px; }
.cat-bar { height: 100%; border-radius: 3px; transition: width 0.4s; }
.cat-rate { font-size: 14px; font-weight: 700; }
.no-eval { color: var(--muted); font-size: 13px; padding: 20px 0; }
/* ── Chat (Demo Tab) ── */
.chat-layout { display: grid; grid-template-columns: 1fr 320px; gap: 20px; align-items: start; }
.chat-box { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; display: flex; flex-direction: column; height: 600px; }
.chat-messages { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 16px; }
.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
.msg { max-width: 85%; }
.msg.user { align-self: flex-end; }
.msg.bot { align-self: flex-start; }
.msg-bubble {
padding: 12px 16px; border-radius: 12px; font-size: 14px; line-height: 1.6; white-space: pre-wrap; word-break: break-word;
}
.msg.user .msg-bubble { background: var(--accent2); color: #fff; border-bottom-right-radius: 4px; }
.msg.bot .msg-bubble { background: #22253a; border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.msg-label { font-size: 11px; color: var(--muted); margin-bottom: 4px; }
.msg.user .msg-label { text-align: right; }
.chat-input-area { border-top: 1px solid var(--border); padding: 16px; display: flex; gap: 10px; }
.chat-input {
flex: 1; background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
padding: 10px 14px; color: var(--text); font-size: 14px; resize: none; height: 44px;
font-family: inherit; outline: none; transition: border-color 0.2s;
}
.chat-input:focus { border-color: var(--accent); }
.chat-send {
background: var(--accent); color: #0f1117; border: none; border-radius: 8px;
padding: 0 20px; font-size: 14px; font-weight: 700; cursor: pointer; transition: opacity 0.2s;
white-space: nowrap;
}
.chat-send:disabled { opacity: 0.4; cursor: not-allowed; }
.thinking { display: flex; gap: 4px; align-items: center; padding: 4px 0; }
.thinking span { width: 7px; height: 7px; background: var(--muted); border-radius: 50%; animation: bounce 1.2s infinite; }
.thinking span:nth-child(2) { animation-delay: 0.2s; }
.thinking span:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce { 0%,80%,100%{transform:translateY(0)} 40%{transform:translateY(-6px)} }
/* ── Model info panel ── */
.model-panel { display: flex; flex-direction: column; gap: 16px; }
.info-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 18px; }
.info-card h3 { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 12px; }
.info-row { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.info-row:last-child { border-bottom: none; }
.info-val { font-weight: 600; color: var(--accent); }
.info-val.red { color: var(--loss-col); }
.info-val.warn { color: var(--warn); }
.model-status-bar { padding: 10px 14px; border-radius: 8px; font-size: 13px; margin-bottom: 4px; }
.model-status-bar.loading { background: #2a1e3a; color: var(--accent2); border: 1px solid var(--accent2); }
.model-status-bar.ready { background: #1e3a2f; color: var(--accent); border: 1px solid var(--accent); }
.model-status-bar.error { background: #3a1e1e; color: var(--loss-col); border: 1px solid var(--loss-col); }
.model-status-bar.idle { background: #22253a; color: var(--muted); border: 1px solid var(--border); }
.quick-btns { display: flex; flex-direction: column; gap: 8px; }
.quick-btn {
background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
padding: 10px 12px; font-size: 12px; color: var(--text); cursor: pointer;
text-align: left; transition: border-color 0.2s;
}
.quick-btn:hover { border-color: var(--accent); color: var(--accent); }
footer { text-align: center; color: var(--muted); font-size: 11px; padding: 24px; }
</style>
</head>
<body>
<header>
<h1>JP<span>LoRA</span> — LoRA 微调 Dashboard</h1>
<div id="status-badge" class="waiting">⏳ 等待训练</div>
</header>
<div class="tabs">
<div class="tab active" onclick="switchTab('monitor')">📊 训练监控</div>
<div class="tab" onclick="switchTab('eval')">🎯 Eval 结果</div>
<div class="tab" onclick="switchTab('demo')">💬 对话 Demo</div>
</div>
<main>
<!-- ── Tab 1: 训练监控 ── -->
<div id="tab-monitor" class="tab-content active">
<div class="cards" style="margin-top:24px">
<div class="card">
<div class="card-label-en">step</div><div class="card-label-zh">当前步数</div>
<div class="card-value green" id="c-step">—</div>
</div>
<div class="card">
<div class="card-label-en">epoch</div><div class="card-label-zh">当前轮次</div>
<div class="card-value purple" id="c-epoch">—</div>
</div>
<div class="card">
<div class="card-label-en">loss</div><div class="card-label-zh">训练损失</div>
<div class="card-value red" id="c-loss">—</div>
</div>
<div class="card">
<div class="card-label-en">accuracy</div><div class="card-label-zh">token 准确率</div>
<div class="card-value green" id="c-acc">—</div>
</div>
<div class="card">
<div class="card-label-en">lr</div><div class="card-label-zh">学习率</div>
<div class="card-value warn" id="c-lr">—</div>
</div>
</div>
<div class="charts">
<div class="chart-box">
<div class="chart-title">Loss 曲线(越低越好)</div>
<canvas id="loss-canvas" height="180"></canvas>
</div>
<div class="chart-box">
<div class="chart-title">Token Accuracy 曲线(越高越好)</div>
<canvas id="acc-canvas" height="180"></canvas>
</div>
</div>
</div>
<!-- ── Tab 2: Eval 结果 ── -->
<div id="tab-eval" class="tab-content">
<div class="eval-box" style="margin-top:24px">
<div class="eval-title">Eval 结果 — 关键词命中率</div>
<div id="eval-content"><div class="no-eval">暂无 eval 结果,运行 python eval.py 后刷新</div></div>
</div>
</div>
<!-- ── Tab 3: 对话 Demo ── -->
<div id="tab-demo" class="tab-content">
<div class="chat-layout" style="margin-top:24px">
<!-- 对话区 -->
<div class="chat-box">
<div class="chat-messages" id="chat-messages">
<div class="msg bot">
<div class="msg-label">明略可信 AI 专家</div>
<div class="msg-bubble">你好!我是经过 LoRA 微调的明略可信 AI 专家。<br><br>你可以问我关于明略科技的使命、可信三阶段(可证→可控→可托付)、产品壁垒、市场定位、技术路线等任何问题。</div>
</div>
</div>
<div class="chat-input-area">
<textarea class="chat-input" id="chat-input" placeholder="输入问题,Enter 发送…" rows="1"></textarea>
<button class="chat-send" id="chat-send" onclick="sendMessage()">发送</button>
</div>
</div>
<!-- 右侧信息面板 -->
<div class="model-panel">
<div class="info-card">
<h3>模型状态</h3>
<div id="model-status-bar" class="model-status-bar idle">点击发送首条消息触发加载</div>
<div style="font-size:11px;color:var(--muted);margin-top:8px">首次加载约 1-2 分钟(7B 模型),加载后常驻内存</div>
</div>
<div class="info-card">
<h3>模型配置</h3>
<div class="info-row"><span>基础模型</span><span class="info-val">Qwen2.5-7B</span></div>
<div class="info-row"><span>微调方式</span><span class="info-val">LoRA</span></div>
<div class="info-row"><span>LoRA rank</span><span class="info-val">32</span></div>
<div class="info-row"><span>训练数据</span><span class="info-val">117 条</span></div>
<div class="info-row"><span>关键词命中率</span><span class="info-val" id="panel-hit-rate">—</span></div>
</div>
<div class="info-card">
<h3>快捷问题</h3>
<div class="quick-btns">
<button class="quick-btn" onclick="quickAsk('明略科技的使命是什么?')">明略科技的使命是什么?</button>
<button class="quick-btn" onclick="quickAsk('可信分为哪三个阶段?各有什么内涵?')">可信分为哪三个阶段?</button>
<button class="quick-btn" onclick="quickAsk('明略在大模型市场中的定位是什么?')">明略的市场定位是什么?</button>
<button class="quick-btn" onclick="quickAsk('明略未来5-10年的技术演进路线是什么?')">明略的技术演进路线?</button>
<button class="quick-btn" onclick="quickAsk('什么是「可控」?包含哪四个属性?')">可控的四个属性?</button>
<button class="quick-btn" onclick="quickAsk('明略的四大核心壁垒是什么?')">明略的四大核心壁垒?</button>
</div>
</div>
</div>
</div>
</div>
</main>
<footer id="footer">自动刷新 5s · JPLoRA Dashboard</footer>
<script>
// ── Tab 切换 ─────────────────────────────────────────────────────────
function switchTab(name) {
document.querySelectorAll('.tab').forEach((t, i) => {
const names = ['monitor', 'eval', 'demo'];
t.classList.toggle('active', names[i] === name);
});
document.querySelectorAll('.tab-content').forEach(c => c.classList.remove('active'));
document.getElementById('tab-' + name).classList.add('active');
if (name === 'demo') refreshModelStatus();
}
// ── 相对路径 API ──────────────────────────────────────────────────────
const API = { trainLog: 'train_log', evalResult: 'eval_result', status: 'status', ask: 'ask', modelStatus: 'model_status' };
let lossData = [], accData = [];
// ── 训练监控刷新 ─────────────────────────────────────────────────────
async function refreshStatus() {
try {
const r = await fetch(API.status);
const s = await r.json();
const badge = document.getElementById('status-badge');
if (s.last_step > 0 && s.last_loss > 0.5) {
badge.textContent = '🔥 训练中'; badge.className = 'training';
} else if (s.lora_ready) {
badge.textContent = s.merged_ready ? '⚡ 已合并权重' : '✅ 训练完成';
badge.className = 'done';
}
} catch(e) {}
}
async function refreshTrainLog() {
try {
const r = await fetch(API.trainLog);
const data = await r.json();
if (!Array.isArray(data) || data.length === 0) return;
const last = data[data.length - 1];
setText('c-step', last.step ?? '—');
setText('c-epoch', last.epoch != null ? last.epoch.toFixed(2) : '—');
setText('c-loss', last.loss != null ? last.loss.toFixed(4) : '—');
setText('c-acc', last.accuracy != null ? (last.accuracy * 100).toFixed(1) + '%' : '—');
setText('c-lr', last.lr != null ? last.lr.toExponential(1) : '—');
lossData = data.filter(d => d.loss != null).map(d => ({ x: d.step, y: d.loss }));
accData = data.filter(d => d.accuracy != null).map(d => ({ x: d.step, y: d.accuracy }));
drawCurve('loss-canvas', lossData, '#ff6b6b', true);
drawCurve('acc-canvas', accData, '#00d4aa', false);
} catch(e) {}
}
async function refreshEval() {
try {
const r = await fetch(API.evalResult);
const data = await r.json();
if (!data) return;
const avg = (data.avg_keyword_hit_rate * 100).toFixed(1);
const mode = data.mode === 'lora' ? 'LoRA 微调后' : '基础模型(未微调)';
setText('panel-hit-rate', avg + '%');
const cats = {};
for (const item of data.results) {
const cat = item.category;
if (!cats[cat]) cats[cat] = [];
cats[cat].push(item.keywords_eval.hit_rate);
}
let html = `<div class="eval-summary">
<div>
<div class="eval-big">${avg}%</div>
<div class="eval-big-label">平均关键词命中率</div>
<div class="eval-mode">${mode} · ${data.results.length} 题</div>
</div></div><div class="cat-grid">`;
for (const [cat, rates] of Object.entries(cats).sort()) {
const rate = rates.reduce((a, b) => a + b, 0) / rates.length;
const pct = (rate * 100).toFixed(0);
const color = rate >= 0.7 ? '#00d4aa' : rate >= 0.4 ? '#ffb347' : '#ff6b6b';
html += `<div class="cat-card">
<div class="cat-name">${cat}(${rates.length} 题)</div>
<div class="cat-bar-wrap"><div class="cat-bar" style="width:${pct}%;background:${color}"></div></div>
<div class="cat-rate" style="color:${color}">${pct}%</div>
</div>`;
}
html += '</div>';
document.getElementById('eval-content').innerHTML = html;
} catch(e) {}
}
// ── 对话 Demo ────────────────────────────────────────────────────────
let isAsking = false;
async function refreshModelStatus() {
try {
const r = await fetch(API.modelStatus);
const s = await r.json();
const bar = document.getElementById('model-status-bar');
if (s.error) {
bar.className = 'model-status-bar error';
bar.textContent = '❌ 加载失败:' + s.error;
} else if (s.loaded) {
bar.className = 'model-status-bar ready';
bar.textContent = s.using_merged ? '⚡ 合并权重已就绪(推理更快)' : '✅ LoRA 模型已就绪';
} else if (s.loading) {
bar.className = 'model-status-bar loading';
bar.textContent = '⏳ 模型加载中,请稍候…';
} else {
bar.className = 'model-status-bar idle';
bar.textContent = '💤 模型未加载(发送首条消息触发)';
}
} catch(e) {}
}
function addMessage(role, content, isThinking = false) {
const msgs = document.getElementById('chat-messages');
const div = document.createElement('div');
div.className = `msg ${role}`;
div.innerHTML = `
<div class="msg-label">${role === 'user' ? '姜哥' : '明略可信 AI 专家'}</div>
<div class="msg-bubble">${isThinking
? '<div class="thinking"><span></span><span></span><span></span></div>'
: escHtml(content)}</div>`;
msgs.appendChild(div);
msgs.scrollTop = msgs.scrollHeight;
return div;
}
function escHtml(s) {
return s.replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>').replace(/\n/g,'<br>');
}
async function sendMessage() {
if (isAsking) return;
const input = document.getElementById('chat-input');
const question = input.value.trim();
if (!question) return;
input.value = '';
input.style.height = '44px';
isAsking = true;
document.getElementById('chat-send').disabled = true;
addMessage('user', question);
const thinkDiv = addMessage('bot', '', true);
// 轮询直到模型就绪
let attempts = 0;
while (attempts < 120) {
try {
const r = await fetch(API.ask, {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({question, max_tokens: 400}),
});
const data = await r.json();
if (r.status === 202) {
// 模型加载中
const bar = document.getElementById('model-status-bar');
bar.className = 'model-status-bar loading';
bar.textContent = '⏳ 模型加载中(约 1-2 分钟)…';
await new Promise(res => setTimeout(res, 5000));
attempts++;
continue;
}
thinkDiv.querySelector('.msg-bubble').innerHTML = escHtml(data.answer || data.error || '未知错误');
refreshModelStatus();
break;
} catch(e) {
thinkDiv.querySelector('.msg-bubble').textContent = '网络错误,请重试';
break;
}
}
isAsking = false;
document.getElementById('chat-send').disabled = false;
document.getElementById('chat-input').focus();
}
function quickAsk(q) {
switchTab('demo');
document.getElementById('chat-input').value = q;
sendMessage();
}
// Enter 发送
document.addEventListener('DOMContentLoaded', () => {
const input = document.getElementById('chat-input');
input.addEventListener('keydown', e => {
if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); sendMessage(); }
});
});
// ── Canvas 绘图 ──────────────────────────────────────────────────────
function drawCurve(id, points, color, invertY) {
const canvas = document.getElementById(id);
if (!canvas) return;
canvas.width = canvas.parentElement.clientWidth - 36;
canvas.height = 180;
const ctx = canvas.getContext('2d');
ctx.clearRect(0, 0, canvas.width, canvas.height);
if (points.length < 2) {
ctx.fillStyle = '#7b7f9e'; ctx.font = '13px sans-serif';
ctx.fillText('等待数据…', canvas.width / 2 - 30, canvas.height / 2);
return;
}
const W = canvas.width, H = canvas.height;
const PAD = { t: 10, r: 10, b: 30, l: 46 };
const W_ = W - PAD.l - PAD.r, H_ = H - PAD.t - PAD.b;
const xs = points.map(p => p.x), ys = points.map(p => p.y);
const minX = Math.min(...xs), maxX = Math.max(...xs);
const minY = Math.min(...ys), maxY = Math.max(...ys);
const rangeY = maxY - minY || 1;
const px = x => PAD.l + ((x - minX) / (maxX - minX || 1)) * W_;
const py = y => PAD.t + (invertY ? ((y - minY) / rangeY) * H_ : (1 - (y - minY) / rangeY) * H_);
ctx.strokeStyle = '#2a2d3e'; ctx.lineWidth = 1;
for (let i = 0; i <= 4; i++) {
const yy = PAD.t + (H_ / 4) * i;
ctx.beginPath(); ctx.moveTo(PAD.l, yy); ctx.lineTo(W - PAD.r, yy); ctx.stroke();
const val = invertY ? (maxY - (rangeY / 4) * i).toFixed(2) : (minY + (rangeY / 4) * i).toFixed(2);
ctx.fillStyle = '#7b7f9e'; ctx.font = '10px monospace';
ctx.fillText(val, 2, yy + 4);
}
const grad = ctx.createLinearGradient(0, PAD.t, 0, H - PAD.b);
grad.addColorStop(0, color + '55'); grad.addColorStop(1, color + '00');
ctx.beginPath();
ctx.moveTo(px(points[0].x), py(points[0].y));
for (const p of points) ctx.lineTo(px(p.x), py(p.y));
ctx.lineTo(px(points[points.length-1].x), H - PAD.b);
ctx.lineTo(px(points[0].x), H - PAD.b);
ctx.fillStyle = grad; ctx.fill();
ctx.beginPath(); ctx.strokeStyle = color; ctx.lineWidth = 2; ctx.lineJoin = 'round';
ctx.moveTo(px(points[0].x), py(points[0].y));
for (const p of points) ctx.lineTo(px(p.x), py(p.y));
ctx.stroke();
ctx.fillStyle = '#7b7f9e'; ctx.font = '10px monospace';
[0, Math.floor(points.length / 2), points.length - 1].forEach(i => {
if (i < points.length) ctx.fillText('s' + points[i].x, px(points[i].x) - 8, H - 6);
});
}
function setText(id, val) { const el = document.getElementById(id); if (el) el.textContent = val; }
// ── 主循环 ───────────────────────────────────────────────────────────
async function refresh() {
await Promise.all([refreshStatus(), refreshTrainLog(), refreshEval()]);
document.getElementById('footer').textContent =
`上次刷新:${new Date().toLocaleTimeString('zh-CN')} · 自动刷新 5s · JPLoRA Dashboard`;
}
refresh();
setInterval(refresh, 5000);
window.addEventListener('resize', () => {
drawCurve('loss-canvas', lossData, '#ff6b6b', true);
drawCurve('acc-canvas', accData, '#00d4aa', false);
});
</script>
</body>
</html>