<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>GhostFlow WASM Demo</title>
<style>
body {
font-family: Arial, sans-serif;
max-width: 800px;
margin: 50px auto;
padding: 20px;
}
.demo-section {
margin: 20px 0;
padding: 20px;
border: 1px solid #ddd;
border-radius: 5px;
}
button {
background: #4CAF50;
color: white;
padding: 10px 20px;
border: none;
border-radius: 4px;
cursor: pointer;
margin: 5px;
}
button:hover {
background: #45a049;
}
pre {
background: #f4f4f4;
padding: 10px;
border-radius: 4px;
overflow-x: auto;
}
</style>
</head>
<body>
<h1>🚀 GhostFlow WebAssembly Demo</h1>
<div class="demo-section">
<h2>1. Tensor Operations</h2>
<button onclick="runTensorDemo()">Run Tensor Demo</button>
<pre id="tensor-output"></pre>
</div>
<div class="demo-section">
<h2>2. Matrix Multiplication</h2>
<button onclick="runMatmulDemo()">Run Matmul Demo</button>
<pre id="matmul-output"></pre>
</div>
<div class="demo-section">
<h2>3. Simple Model</h2>
<button onclick="runModelDemo()">Run Model Demo</button>
<pre id="model-output"></pre>
</div>
<script type="module">
import init, {
WasmTensor,
WasmModel,
version,
log
} from './pkg/ghostflow_wasm.js';
async function run() {
await init();
log('GhostFlow WASM initialized!');
document.getElementById('tensor-output').textContent =
`GhostFlow version: ${version()}`;
window.WasmTensor = WasmTensor;
window.WasmModel = WasmModel;
window.ghostflowLog = log;
}
run();
window.runTensorDemo = function() {
const output = document.getElementById('tensor-output');
try {
const t1 = WasmTensor.zeros([2, 3]);
const t2 = WasmTensor.ones([2, 3]);
const result = t1.add(t2);
output.textContent = `
Tensor 1 (zeros): shape=${JSON.stringify(t1.shape())}, data=${JSON.stringify(t1.data())}
Tensor 2 (ones): shape=${JSON.stringify(t2.shape())}, data=${JSON.stringify(t2.data())}
Result (t1 + t2): shape=${JSON.stringify(result.shape())}, data=${JSON.stringify(result.data())}
`.trim();
} catch (e) {
output.textContent = `Error: ${e}`;
}
};
window.runMatmulDemo = function() {
const output = document.getElementById('matmul-output');
try {
const a = new WasmTensor([1, 2, 3, 4], [2, 2]);
const b = new WasmTensor([5, 6, 7, 8], [2, 2]);
const result = a.matmul(b);
output.textContent = `
Matrix A: shape=${JSON.stringify(a.shape())}, data=${JSON.stringify(a.data())}
Matrix B: shape=${JSON.stringify(b.shape())}, data=${JSON.stringify(b.data())}
A @ B: shape=${JSON.stringify(result.shape())}, data=${JSON.stringify(result.data())}
`.trim();
} catch (e) {
output.textContent = `Error: ${e}`;
}
};
window.runModelDemo = function() {
const output = document.getElementById('model-output');
try {
const model = new WasmModel();
const weight = new WasmTensor([0.5, 0.3, 0.2, 0.1, 0.4, 0.5], [3, 2]);
model.addWeight(weight);
const input = new WasmTensor([1.0, 2.0, 3.0], [1, 3]);
const prediction = model.forward(input);
output.textContent = `
Model created with ${model.numWeights()} weight tensor(s)
Input: shape=${JSON.stringify(input.shape())}, data=${JSON.stringify(input.data())}
Prediction: shape=${JSON.stringify(prediction.shape())}, data=${JSON.stringify(prediction.data())}
`.trim();
} catch (e) {
output.textContent = `Error: ${e}`;
}
};
</script>
</body>
</html>