Spaces:
Running
Running
Download source/scripts/smoke-node.mjs from Segizu/monitor-de-mesas: direct link, hf CLI and curl.
- Browser
- Download file 1.17 kB
-
https://huggingface.co/spaces/Segizu/monitor-de-mesas/resolve/main/source/scripts/smoke-node.mjs
- Command line
-
hf download hf://spaces/Segizu/monitor-de-mesas/source/scripts/smoke-node.mjs
-
curl -L -o smoke-node.mjs https://huggingface.co/spaces/Segizu/monitor-de-mesas/resolve/main/source/scripts/smoke-node.mjs
1.17 kB
| // Node smoke: runs REAL inference with onnxruntime-node (not WASM/browser). Does not replace browser verification. | |
| import { pipeline, env, RawImage } from '@huggingface/transformers'; | |
| import { readFileSync } from 'node:fs'; | |
| import { MODEL_ID, MODEL_REVISION, MODEL_DTYPE, EXAMPLES } from '../src/config.js'; | |
| env.allowLocalModels = false; | |
| const t0 = performance.now(); | |
| const det = await pipeline('zero-shot-object-detection', MODEL_ID, { revision: MODEL_REVISION, dtype: MODEL_DTYPE, device: 'cpu' }); | |
| console.log('load_ms', Math.round(performance.now() - t0)); | |
| for (const ex of EXAMPLES) { | |
| const img = await RawImage.read(new URL('../public/examples/' + ex.file, import.meta.url).pathname); | |
| const t = performance.now(); | |
| const out = await det(img, ex.labels, { threshold: ex.threshold, percentage: false }); | |
| const ms = Math.round(performance.now() - t); | |
| const counts = {}; | |
| for (const d of out) counts[d.label] = (counts[d.label] || 0) + 1; | |
| console.log(JSON.stringify({ id: ex.id, size: [img.width, img.height], ms, n: out.length, counts, top: out.slice(0, 4).map(d => ({ l: d.label, s: +d.score.toFixed(3), b: Object.values(d.box).map(Math.round) })) })); | |
| } | |