Download sync_models.js from tardellirs/typed-decisions-explorer: direct link, hf CLI and curl.
- Browser
- Download file 2.03 kB
-
https://huggingface.co/spaces/tardellirs/typed-decisions-explorer/resolve/main/sync_models.js
- Command line
-
hf download hf://spaces/tardellirs/typed-decisions-explorer/sync_models.js
-
curl -L -o sync_models.js https://huggingface.co/spaces/tardellirs/typed-decisions-explorer/resolve/main/sync_models.js
2.03 kB
| // Prints the Hugging Face model ids linked from the dataset card's leaderboard tables (one per line), | |
| // so the Space README can list them under `models:` and show up in "Spaces using this model". | |
| // Usage: node sync_models.js [--card README.md] [--write SPACE_README.md] | |
| // --card read the card from a file instead of the live dataset | |
| // --write replace the `models:` list in the Space README front matter (prints "changed" or "unchanged") | |
| const P = require('./parse.js'); | |
| const EXCLUDE = []; | |
| (async () => { | |
| const arg = (k) => { const i = process.argv.indexOf(k); return i > 0 ? process.argv[i + 1] : null; }; | |
| const src = arg('--card'); | |
| const md = src ? require('fs').readFileSync(src, 'utf8') | |
| : await (await fetch('https://huggingface.co/datasets/LocalLLaMA/typed-decisions/resolve/main/README.md')).text(); | |
| const ids = new Set(); | |
| for (const r of P.parseReadme(md).rows) { | |
| const m = r.url && r.url.match(/^https:\/\/huggingface\.co\/(?!datasets\/|spaces\/|docs\/)([\w.-]+\/[\w.-]+)\/?$/); | |
| if (m && !EXCLUDE.some((re) => re.test(m[1]))) ids.add(m[1]); | |
| } | |
| // renamed repos redirect; keep the canonical id and drop ids that no longer exist | |
| const out = new Set(); | |
| for (const id of ids) { | |
| const res = await fetch(`https://huggingface.co/api/models/${id}`); | |
| if (res.ok) out.add((await res.json()).id); | |
| else console.error(`skipped ${id}: HTTP ${res.status}`); | |
| } | |
| const list = [...out].sort((a, b) => a.localeCompare(b)); | |
| const target = arg('--write'); | |
| if (!target) { console.log(list.join('\n')); return; } | |
| const fs = require('fs'); | |
| const readme = fs.readFileSync(target, 'utf8'); | |
| const block = `models:\n${list.map((id) => `- ${id}`).join('\n')}\n`; | |
| const next = /^models:\n(?:- .*\n)*/m.test(readme) | |
| ? readme.replace(/^models:\n(?:- .*\n)*/m, block) | |
| : readme.replace(/^datasets:\n/m, `${block}datasets:\n`); | |
| if (next === readme) { console.log('unchanged'); return; } | |
| fs.writeFileSync(target, next); | |
| console.log(`changed: ${list.length} models`); | |
| })(); | |