Spaces:
Sleeping
Sleeping
Add asset cache-busting hashes, Cache-Control headers, and squiggle-windowed long-file cleanup
7667cef verified Download web/src/score-worker.js from brianbellx/codehygiene: direct link, hf CLI and curl.
- Browser
- Download file 892 Bytes
-
https://huggingface.co/spaces/brianbellx/codehygiene/resolve/main/web/src/score-worker.js
- Command line
-
hf download hf://spaces/brianbellx/codehygiene/web/src/score-worker.js
-
curl -L -o score-worker.js https://huggingface.co/spaces/brianbellx/codehygiene/resolve/main/web/src/score-worker.js
892 Bytes
| import { loadWeights, scoreCode } from "shared:engine"; | |
| const WARMUP_CODE = ["def warm(items):", " for item in items:", " return item", ""].join("\n"); | |
| const ASSET_QUERY = new URL(import.meta.url).search; | |
| const weightsReady = loadWeights(new URL(`./weights.npz${ASSET_QUERY}`, import.meta.url).href).then((weights) => { | |
| scoreCode(WARMUP_CODE, weights); | |
| return weights; | |
| }); | |
| globalThis.addEventListener("message", async (event) => { | |
| const { id, code, threshold } = event.data; | |
| try { | |
| const weights = await weightsReady; | |
| const started = performance.now(); | |
| const { score, squiggles } = scoreCode(code, weights, threshold); | |
| const ms = performance.now() - started; | |
| globalThis.postMessage({ id, result: { score, squiggles, ms } }); | |
| } catch (error) { | |
| globalThis.postMessage({ id, error: String(error && error.message ? error.message : error) }); | |
| } | |
| }); | |