Spaces:
Runtime error
Runtime error
Update index.html
Browse files- index.html +98 -64
index.html
CHANGED
|
@@ -1,6 +1,8 @@
|
|
| 1 |
<!DOCTYPE html>
|
| 2 |
-
<html>
|
| 3 |
<head>
|
|
|
|
|
|
|
| 4 |
<title>N-Dim Triangulated LMS Mesh</title>
|
| 5 |
<script src="https://cdn.tailwindcss.com"></script>
|
| 6 |
<script src="https://cdn.plot.ly/plotly-2.24.1.min.js"></script>
|
|
@@ -8,88 +10,120 @@
|
|
| 8 |
</head>
|
| 9 |
<body class="flex flex-col h-screen overflow-hidden">
|
| 10 |
|
| 11 |
-
<
|
| 12 |
-
|
| 13 |
-
<div class="
|
| 14 |
-
|
| 15 |
-
<button onclick="
|
| 16 |
-
<button onclick="
|
|
|
|
| 17 |
</div>
|
| 18 |
</div>
|
| 19 |
|
| 20 |
<div class="flex-grow flex flex-col">
|
| 21 |
-
<
|
| 22 |
-
<div class="
|
| 23 |
-
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
</div>
|
| 26 |
</div>
|
| 27 |
|
| 28 |
<script>
|
| 29 |
let plotted = false;
|
| 30 |
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
document.getElementById('logs').innerHTML = d.logs.map(l => `<div>${l}</div>`).join('');
|
| 36 |
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
|
|
|
|
|
|
|
|
|
| 49 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
traces.push({
|
| 51 |
-
type:'scatter', mode:'
|
| 52 |
-
x:
|
| 53 |
-
|
| 54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
});
|
| 56 |
-
}
|
| 57 |
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
text: nodes.map(n => n.x.toFixed(2)),
|
| 64 |
-
textposition: 'top center',
|
| 65 |
-
textfont: {size: 10, color: '#9ca3af'},
|
| 66 |
-
marker: {
|
| 67 |
-
size: 14,
|
| 68 |
-
color: nodes.map(n => n.x), // Color maps to value!
|
| 69 |
-
colorscale: 'Viridis',
|
| 70 |
-
line: {color: '#171717', width: 2}
|
| 71 |
-
},
|
| 72 |
-
showlegend:false
|
| 73 |
-
});
|
| 74 |
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
|
|
|
| 80 |
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
margin:{l:30,r:10,t:10,b:20}, paper_bgcolor:'transparent', plot_bgcolor:'transparent',
|
| 89 |
-
xaxis:{visible:false}, yaxis:{gridcolor:'#262626'}
|
| 90 |
-
});
|
| 91 |
|
| 92 |
-
}
|
|
|
|
|
|
|
|
|
|
| 93 |
</script>
|
| 94 |
</body>
|
| 95 |
</html>
|
|
|
|
| 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>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>
|
|
|
|
| 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>
|