everydaytok commited on
Commit
8c77d8f
·
verified ·
1 Parent(s): 32634ef

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +198 -66
index.html CHANGED
@@ -3,127 +3,259 @@
3
  <head>
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>N-Dim Triangulated LMS Mesh</title>
7
  <script src="https://cdn.tailwindcss.com"></script>
8
  <script src="https://cdn.plot.ly/plotly-2.24.1.min.js"></script>
9
- <style>body { background:#0a0a0a; color:#e5e5e5; font-family:monospace; }</style>
 
 
 
 
 
 
 
 
 
 
10
  </head>
11
  <body class="flex flex-col h-screen overflow-hidden">
12
 
13
- <!-- Header (Mobile Responsive flex-wrap) -->
14
- <div class="flex-shrink-0 p-2 bg-neutral-900 border-b border-neutral-800 flex flex-wrap justify-between items-center gap-2">
15
- <div class="font-bold text-orange-500 text-sm md:text-base">N-DIM LATTICE MESH</div>
16
- <div class="flex flex-wrap gap-2">
17
- <button onclick="postAct('/train')" class="bg-purple-700 px-3 py-1 rounded text-xs font-bold shadow-md active:scale-95">⚡ TRAIN</button>
18
- <button onclick="postAct('/infer')" class="bg-green-700 px-3 py-1 rounded text-xs font-bold shadow-md active:scale-95">▶ INFER</button>
19
- <button onclick="postAct('/halt')" class="bg-red-800 px-3 py-1 rounded text-xs font-bold shadow-md active:scale-95">■ HALT</button>
20
  </div>
21
- </div>
 
 
 
 
 
 
22
 
23
- <div class="flex-grow flex flex-col">
24
- <!-- Error Fallback container in case JS crashes -->
25
- <div id="error-box" class="hidden bg-red-900 text-white p-2 text-xs font-bold break-words"></div>
 
 
 
26
 
27
- <!-- Plots -->
28
- <div id="mesh-plot" class="flex-grow min-h-[40vh] w-full relative"></div>
29
-
30
- <div class="h-1/3 min-h-[150px] border-t border-neutral-800 flex flex-col md:flex-row">
31
- <div class="w-full md:w-1/3 p-2 border-b md:border-b-0 md:border-r border-neutral-800 overflow-y-auto text-[10px] text-gray-400" id="logs">
32
- Waiting for backend connection...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
  </div>
34
- <div class="w-full md:w-2/3 h-full" id="err-plot"></div>
35
  </div>
36
  </div>
37
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
  <script>
39
  let plotted = false;
40
 
 
 
 
41
  async function postAct(route) {
42
  try { await fetch(route, {method:'POST'}); }
43
- catch(e) { showError("Failed to reach server: " + e.message); }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  }
45
 
46
  function showError(msg) {
47
  const box = document.getElementById('error-box');
48
- box.innerText = msg;
49
- box.classList.remove('hidden');
 
 
 
 
 
 
 
 
50
  }
51
 
52
  setInterval(async () => {
53
  try {
54
  const res = await fetch('/state');
55
- if (!res.ok) throw new Error("Server returned " + res.status);
56
  const d = await res.json();
 
57
 
58
- document.getElementById('error-box').classList.add('hidden'); // Clear errors
59
- document.getElementById('logs').innerHTML = d.logs.map(l => `<div>${l}</div>`).join('');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
 
61
- // Build traces
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
  const traces = [];
63
  const nodes = Object.values(d.nodes);
64
 
65
- // Edges (Parsed using the pipe '|' we set in Python)
66
  for(const [key, K] of Object.entries(d.springs)) {
67
  const parts = key.split('|');
68
  if (parts.length !== 2) continue;
 
69
 
70
- const u = parts[0];
71
- const v = parts[1];
72
- if(!d.nodes[u] || !d.nodes[v]) continue;
73
-
74
- const pu = d.nodes[u].pos, pv = d.nodes[v].pos;
75
  const color = K > 0 ? `rgba(217,119,6,${Math.min(K/4,1)})` : `rgba(6,182,212,${Math.min(Math.abs(K)/4,1)})`;
76
-
77
  traces.push({
78
- type:'scatter', mode:'lines',
79
- x:[pu[0], pv[0]], y:[pu[1], pv[1]],
80
- line:{ color: color, width: 1.5 + Math.abs(K) },
81
- hoverinfo:'none', showlegend:false
82
  });
83
  }
84
 
85
- // Nodes
86
  traces.push({
87
  type:'scatter', mode:'markers+text',
88
- x: nodes.map(n => n.pos[0]),
89
- y: nodes.map(n => n.pos[1]),
90
  text: nodes.map(n => n.x.toFixed(2)),
91
- textposition: 'top center',
92
- textfont: {size: 9, color: '#9ca3af'},
93
  marker: {
94
- size: 12,
95
- color: nodes.map(n => n.x),
96
- colorscale: 'Viridis',
97
- line: {color: '#171717', width: 2}
98
  },
99
  showlegend:false
100
  });
101
 
102
  const layout = {
103
- margin:{l:10,r:10,t:10,b:10},
104
- paper_bgcolor:'transparent', plot_bgcolor:'transparent',
105
  xaxis:{visible:false}, yaxis:{visible:false, scaleanchor:'x'},
106
  };
107
 
108
- if(!plotted) {
109
- Plotly.newPlot('mesh-plot', traces, layout, {responsive: true});
110
- plotted = true;
111
- } else {
112
- Plotly.react('mesh-plot', traces, layout);
113
- }
114
 
115
- // Error plot
116
- Plotly.react('err-plot', [{
117
- y: d.hist, type:'scatter', line:{color:'#22c55e'}
118
- }], {
119
- margin:{l:30,r:10,t:10,b:20}, paper_bgcolor:'transparent', plot_bgcolor:'transparent',
120
- xaxis:{visible:false}, yaxis:{gridcolor:'#262626'}
121
- });
122
 
123
- } catch (e) {
124
- showError("UI Error: " + e.message);
125
- }
126
- }, 300); // Slightly slower polling to save mobile battery
127
  </script>
128
  </body>
129
  </html>
 
3
  <head>
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Lattice Mesh + Controls</title>
7
  <script src="https://cdn.tailwindcss.com"></script>
8
  <script src="https://cdn.plot.ly/plotly-2.24.1.min.js"></script>
9
+ <style>
10
+ body { background:#06090e; color:#cbd5e1; font-family:'Courier New',monospace; }
11
+ .glass { background:rgba(10,18,35,0.98); border:1px solid #1e2d40; }
12
+ #drawer { transition:transform .3s ease; z-index:200; }
13
+ .drawer-closed { transform:translateY(100%); }
14
+ .ptype { display:inline-block; padding:1px 5px; border-radius:3px; font-size:9px; font-weight:bold; }
15
+ .pt-blend { background:#1e3a2f; color:#4ade80; }
16
+ .pt-diff { background:#1e2d4a; color:#60a5fa; }
17
+ .pt-route { background:#3a1e3a; color:#e879f9; }
18
+ .pt-manual{ background:#3a2a1e; color:#fb923c; }
19
+ </style>
20
  </head>
21
  <body class="flex flex-col h-screen overflow-hidden">
22
 
23
+ <!-- HEADER -->
24
+ <header class="glass flex-shrink-0 px-2 py-1.5 flex justify-between items-center gap-1">
25
+ <div class="flex flex-wrap gap-1 items-center text-[8px] font-bold">
26
+ <span id="b-mode" class="px-1.5 py-0.5 rounded bg-slate-800 text-slate-400 border border-slate-700">IDLE</span>
27
+ <span id="b-type" class="ptype pt-blend"></span>
28
+ <span id="b-dim" class="px-1.5 py-0.5 rounded bg-slate-900 text-slate-600 border border-slate-800">D:8</span>
 
29
  </div>
30
+ <div class="flex items-center gap-1 flex-shrink-0">
31
+ <span id="q-lbl" class="text-[8px] text-slate-600">Q:0</span>
32
+ <div id="run-dot" class="w-2 h-2 rounded-full bg-slate-700"></div>
33
+ <button onclick="postAct('/halt')" class="text-[9px] bg-red-900 hover:bg-red-800 px-2 py-1 rounded font-bold shadow">■ HALT</button>
34
+ <button onclick="openDrawer()" class="text-[9px] bg-slate-700 hover:bg-slate-600 px-2 py-1 rounded font-bold shadow">⚙ CONTROLS</button>
35
+ </div>
36
+ </header>
37
 
38
+ <!-- PLOTS -->
39
+ <div class="flex-grow flex flex-col min-h-[30vh] overflow-hidden relative">
40
+ <div id="error-box" class="hidden absolute top-0 w-full bg-red-900 text-white p-2 text-xs font-bold z-50"></div>
41
+ <div id="mesh-plot" class="flex-grow w-full"></div>
42
+ <div id="err-plot" style="height:56px" class="flex-shrink-0 border-t border-slate-900 hidden md:block"></div>
43
+ </div>
44
 
45
+ <!-- BOTTOM PANEL (Restored) -->
46
+ <div class="glass flex-shrink-0 border-t border-slate-800 h-48">
47
+ <div class="flex border-b border-slate-800 text-[10px]">
48
+ <button onclick="tab('nodes')" id="tab-nodes" class="flex-1 py-1 bg-blue-900/40 text-blue-300 font-bold">NODES</button>
49
+ <button onclick="tab('springs')" id="tab-springs" class="flex-1 py-1 text-slate-500">SPRINGS</button>
50
+ <button onclick="tab('accuracy')" id="tab-accuracy" class="flex-1 py-1 text-slate-500">ACCURACY</button>
51
+ <button onclick="tab('logs')" id="tab-logs" class="flex-1 py-1 text-slate-500">LOGS</button>
52
+ </div>
53
+ <div class="flex h-full overflow-hidden">
54
+ <!-- Tension Meter -->
55
+ <div class="w-24 flex-shrink-0 border-r border-slate-800 flex flex-col items-center justify-center p-1 gap-0.5">
56
+ <div class="text-[7px] text-slate-600 uppercase">mean error</div>
57
+ <div id="err-big" class="text-xl font-bold text-red-400 leading-none">0.00</div>
58
+ </div>
59
+ <!-- Panes -->
60
+ <div class="flex-grow overflow-y-auto p-1.5 text-[10px] pb-6">
61
+ <div id="pane-nodes"></div>
62
+ <div id="pane-springs" class="hidden"></div>
63
+ <div id="pane-accuracy" class="hidden"></div>
64
+ <div id="pane-logs" class="hidden text-[9px] text-slate-500"></div>
65
  </div>
 
66
  </div>
67
  </div>
68
 
69
+ <!-- DRAWER -->
70
+ <aside id="drawer" class="drawer-closed fixed inset-x-0 bottom-0 glass border-t border-slate-700 p-4 flex flex-col gap-3 max-h-[90vh] overflow-y-auto pb-10 shadow-2xl">
71
+ <div class="flex justify-between items-center">
72
+ <span class="text-orange-400 font-bold">CONTROL PANEL</span>
73
+ <button onclick="closeDrawer()" class="text-slate-400 text-2xl leading-none">✕</button>
74
+ </div>
75
+
76
+ <div class="grid grid-cols-1 md:grid-cols-2 gap-3">
77
+ <!-- Training -->
78
+ <div class="bg-slate-900 rounded p-3 border border-purple-900/50">
79
+ <div class="text-purple-400 text-[9px] font-bold mb-2">OFFLINE TRAINING</div>
80
+ <div class="flex gap-2 items-center">
81
+ <input id="ep-n" type="number" value="10" class="w-16 bg-black border border-slate-700 p-1 text-white text-sm text-center rounded">
82
+ <label class="text-[9px] text-slate-500 flex-1">Epochs</label>
83
+ <button onclick="doTrain()" class="bg-purple-800 hover:bg-purple-700 px-4 py-2 text-xs font-bold rounded">⚡ TRAIN</button>
84
+ </div>
85
+ </div>
86
+
87
+ <!-- Inference -->
88
+ <div class="bg-slate-900 rounded p-3 border border-green-900/50">
89
+ <div class="text-green-400 text-[9px] font-bold mb-2">BATCH INFERENCE (EWC)</div>
90
+ <div class="flex gap-2 items-center">
91
+ <input id="inf-n" type="number" value="200" class="w-16 bg-black border border-slate-700 p-1 text-white text-sm text-center rounded">
92
+ <label class="text-[9px] text-slate-500 flex-1">Samples</label>
93
+ <button onclick="doInfer()" class="bg-green-800 hover:bg-green-700 px-4 py-2 text-xs font-bold rounded">▶ RUN</button>
94
+ </div>
95
+ </div>
96
+ </div>
97
+
98
+ <!-- Manual Input -->
99
+ <div class="bg-slate-900 rounded p-3 border border-orange-900/50">
100
+ <div class="text-orange-400 text-[9px] font-bold mb-2">MANUAL INPUT OVERRIDE (D:8)</div>
101
+ <div class="space-y-2">
102
+ <div>
103
+ <label class="text-[8px] text-slate-500 block mb-0.5">Input A (comma separated)</label>
104
+ <input id="man-a" type="text" value="0.9, 0.1, 0.5, 0.2, 0.8, 0.3, 0.7, 0.4" class="w-full bg-black border border-slate-700 p-1.5 text-orange-200 text-xs rounded font-mono">
105
+ </div>
106
+ <div>
107
+ <label class="text-[8px] text-slate-500 block mb-0.5">Input B (comma separated)</label>
108
+ <input id="man-b" type="text" value="0.1, 0.9, 0.5, 0.8, 0.2, 0.7, 0.3, 0.6" class="w-full bg-black border border-slate-700 p-1.5 text-cyan-200 text-xs rounded font-mono">
109
+ </div>
110
+ <button onclick="doManual()" class="w-full bg-orange-900 hover:bg-orange-800 py-2 text-xs font-bold rounded mt-1">INJECT MANUAL ARRAYS</button>
111
+ </div>
112
+ </div>
113
+ </aside>
114
+
115
  <script>
116
  let plotted = false;
117
 
118
+ function openDrawer() { document.getElementById('drawer').classList.remove('drawer-closed'); }
119
+ function closeDrawer() { document.getElementById('drawer').classList.add('drawer-closed'); }
120
+
121
  async function postAct(route) {
122
  try { await fetch(route, {method:'POST'}); }
123
+ catch(e) { showError("Connection lost."); }
124
+ }
125
+
126
+ async function doTrain() {
127
+ const ep = parseInt(document.getElementById('ep-n').value);
128
+ await fetch('/train', {method:'POST', headers:{'Content-Type':'application/json'}, body: JSON.stringify({epochs:ep})});
129
+ closeDrawer();
130
+ }
131
+
132
+ async function doInfer() {
133
+ const n = parseInt(document.getElementById('inf-n').value);
134
+ await fetch('/infer', {method:'POST', headers:{'Content-Type':'application/json'}, body: JSON.stringify({n})});
135
+ closeDrawer();
136
+ }
137
+
138
+ async function doManual() {
139
+ const a = document.getElementById('man-a').value;
140
+ const b = document.getElementById('man-b').value;
141
+ const res = await fetch('/manual', {method:'POST', headers:{'Content-Type':'application/json'}, body: JSON.stringify({a:a, b:b})});
142
+ const data = await res.json();
143
+ if(!data.ok) alert(data.error);
144
+ else closeDrawer();
145
  }
146
 
147
  function showError(msg) {
148
  const box = document.getElementById('error-box');
149
+ box.innerText = msg; box.classList.remove('hidden');
150
+ }
151
+
152
+ function tab(name) {
153
+ ['nodes','springs','accuracy','logs'].forEach(t => {
154
+ document.getElementById(`pane-${t}`).classList.toggle('hidden', t !== name);
155
+ document.getElementById(`tab-${t}`).className = t === name
156
+ ? 'flex-1 py-1 bg-blue-900/40 text-blue-300 font-bold text-[10px]'
157
+ : 'flex-1 py-1 text-slate-500 text-[10px]';
158
+ });
159
  }
160
 
161
  setInterval(async () => {
162
  try {
163
  const res = await fetch('/state');
164
+ if (!res.ok) throw new Error("Server error");
165
  const d = await res.json();
166
+ document.getElementById('error-box').classList.add('hidden');
167
 
168
+ // Header & Badges
169
+ const mcolor = {train:'bg-yellow-700 text-yellow-100', infer:'bg-green-800 text-green-100', manual:'bg-orange-800 text-orange-100'}[d.mode] || 'bg-slate-800';
170
+ document.getElementById('b-mode').className = `px-1.5 py-0.5 rounded text-[8px] font-bold ${mcolor}`;
171
+ document.getElementById('b-mode').innerText = d.mode.toUpperCase();
172
+ document.getElementById('b-type').className = `ptype pt-${d.current_type}`;
173
+ document.getElementById('b-type').innerText = d.current_type;
174
+ document.getElementById('run-dot').className = `w-2 h-2 rounded-full ${d.running?'bg-green-400':'bg-slate-700'}`;
175
+ document.getElementById('q-lbl').innerText = `Q:${d.queue_size}`;
176
+
177
+ // Tension Meter
178
+ const col = d.error < 0.05 ? 'text-green-400' : d.error < 0.15 ? 'text-yellow-400' : 'text-red-400';
179
+ document.getElementById('err-big').className = `text-xl font-bold ${col} leading-none`;
180
+ document.getElementById('err-big').innerText = d.error.toFixed(4);
181
+
182
+ // Logs Pane
183
+ document.getElementById('pane-logs').innerHTML = d.logs.map(l => `<div>${l}</div>`).join('');
184
 
185
+ // Accuracy Pane
186
+ let ah = "";
187
+ if(Object.keys(d.type_acc).length > 0) {
188
+ ah += `<table class="w-full text-left border-collapse">
189
+ <tr class="text-slate-600 border-b border-slate-800"><th>Type</th><th>N</th><th>Avg Err</th></tr>`;
190
+ for(const [t, v] of Object.entries(d.type_acc)) {
191
+ ah += `<tr class="border-b border-slate-900/60">
192
+ <td class="py-1 text-orange-300 font-bold">${t}</td>
193
+ <td class="text-slate-400">${v.n}</td>
194
+ <td class="text-white">${v.avg_err}</td>
195
+ </tr>`;
196
+ }
197
+ ah += `</table>`;
198
+ } else { ah = "No inference data yet."; }
199
+ document.getElementById('pane-accuracy').innerHTML = ah;
200
+
201
+ // Nodes Pane (Compact for mobile)
202
+ let nh = "";
203
+ ['A','C','B'].forEach(kind => {
204
+ const k_nodes = Object.values(d.nodes).filter(n => n.kind === kind).sort((a,b)=>a.col-b.col);
205
+ if(k_nodes.length === 0) return;
206
+ const vals = k_nodes.map(n => n.x.toFixed(2)).join(', ');
207
+ const color = kind==='A'?'text-orange-400':kind==='B'?'text-purple-400':'text-sky-400';
208
+ nh += `<div class="mb-1"><span class="${color} font-bold mr-2">${kind}:</span><span class="font-mono text-slate-300 tracking-wider">${vals}</span></div>`;
209
+ });
210
+ document.getElementById('pane-nodes').innerHTML = nh;
211
+
212
+ // Plotly Update
213
  const traces = [];
214
  const nodes = Object.values(d.nodes);
215
 
 
216
  for(const [key, K] of Object.entries(d.springs)) {
217
  const parts = key.split('|');
218
  if (parts.length !== 2) continue;
219
+ if(!d.nodes[parts[0]] || !d.nodes[parts[1]]) continue;
220
 
221
+ const pu = d.nodes[parts[0]].pos, pv = d.nodes[parts[1]].pos;
 
 
 
 
222
  const color = K > 0 ? `rgba(217,119,6,${Math.min(K/4,1)})` : `rgba(6,182,212,${Math.min(Math.abs(K)/4,1)})`;
 
223
  traces.push({
224
+ type:'scatter', mode:'lines', x:[pu[0], pv[0]], y:[pu[1], pv[1]],
225
+ line:{ color: color, width: 1.5 + Math.abs(K) }, hoverinfo:'none', showlegend:false
 
 
226
  });
227
  }
228
 
 
229
  traces.push({
230
  type:'scatter', mode:'markers+text',
231
+ x: nodes.map(n => n.pos[0]), y: nodes.map(n => n.pos[1]),
 
232
  text: nodes.map(n => n.x.toFixed(2)),
233
+ textposition: 'top center', textfont: {size: 9, color: '#9ca3af'},
 
234
  marker: {
235
+ size: 14, color: nodes.map(n => n.x), colorscale: 'Viridis',
236
+ line: {color: nodes.map(n => ['A','B','C'].includes(n.kind)?'#ef4444':'#171717'), width: 2}
 
 
237
  },
238
  showlegend:false
239
  });
240
 
241
  const layout = {
242
+ margin:{l:5,r:5,t:5,b:5}, paper_bgcolor:'transparent', plot_bgcolor:'transparent',
 
243
  xaxis:{visible:false}, yaxis:{visible:false, scaleanchor:'x'},
244
  };
245
 
246
+ if(!plotted) { Plotly.newPlot('mesh-plot', traces, layout, {responsive:true}); plotted = true; }
247
+ else { Plotly.react('mesh-plot', traces, layout); }
 
 
 
 
248
 
249
+ // Mobile error chart rendering (hidden on small screens usually, but we update the logic safely)
250
+ if(document.getElementById('err-plot').offsetWidth > 0) {
251
+ Plotly.react('err-plot', [{y: d.hist, type:'scatter', line:{color:'#22c55e'}}], {
252
+ margin:{l:30,r:10,t:10,b:15}, paper_bgcolor:'transparent', plot_bgcolor:'transparent',
253
+ xaxis:{visible:false}, yaxis:{gridcolor:'#262626'}
254
+ });
255
+ }
256
 
257
+ } catch (e) { showError("UI Error: " + e.message); }
258
+ }, 300);
 
 
259
  </script>
260
  </body>
261
  </html>