Download source/scripts/trace.mjs from WilburDev/earshelf: direct link, hf CLI and curl.
- Browser
- Download file 1.36 kB
-
https://huggingface.co/spaces/WilburDev/earshelf/resolve/main/source/scripts/trace.mjs
- Command line
-
hf download hf://spaces/WilburDev/earshelf/source/scripts/trace.mjs
-
curl -L -o trace.mjs https://huggingface.co/spaces/WilburDev/earshelf/resolve/main/source/scripts/trace.mjs
1.36 kB
| import { chromium } from '@playwright/test'; | |
| const dtype = process.argv[2]; | |
| const b = await chromium.launch({ channel: 'chrome' }); | |
| const ctx = await b.newContext(); | |
| await ctx.route(/huggingface\.co/, (r) => { console.log('BLOCKED', r.request().url()); r.abort(); }); | |
| const p = await ctx.newPage(); | |
| p.on('requestfailed', (r) => console.log('FAILED', r.url())); | |
| ctx.on('request', (r) => { if (/models|onnx|\.bin/.test(r.url())) console.log('REQ', r.url().replace('http://localhost:4175/', '')); }); | |
| await p.goto('http://localhost:4175/'); | |
| const workerUrl = await p.evaluate(async () => { | |
| const idx = performance.getEntriesByType('resource').map((r) => r.name).find((n) => /assets\/index-.*\.js$/.test(n)); | |
| const src = await (await fetch(idx)).text(); | |
| return new URL('assets/' + src.match(/tts-worker-[\w-]+\.js/)[0], location.href).href; | |
| }); | |
| const r = await p.evaluate(async ({ workerUrl, dtype }) => { | |
| const w = new Worker(workerUrl, { type: 'module' }); | |
| return await new Promise((resolve) => { | |
| w.onmessage = (e) => { if (['ready', 'loadError'].includes(e.data.type)) resolve(e.data); }; | |
| w.postMessage({ type: 'load', device: 'wasm', dtype, threads: 4, ortBase: new URL('ort/', location.href).href, modelBase: new URL('models/kokoro/', location.href).href }); | |
| }); | |
| }, { workerUrl, dtype }); | |
| console.log(JSON.stringify(r)); | |
| await b.close(); | |