Download source/src/api.js from mindchain/hub-flow: direct link, hf CLI and curl.
- Browser
- Download file 1.06 kB
-
https://huggingface.co/spaces/mindchain/hub-flow/resolve/main/source/src/api.js
- Command line
-
hf download hf://spaces/mindchain/hub-flow/source/src/api.js
-
curl -L -o api.js https://huggingface.co/spaces/mindchain/hub-flow/resolve/main/source/src/api.js
1.06 kB
| // Data sources (all public, all free): | |
| // - modelpulse.ifsp.dev — the model-pulse open API over the modelpulse/model-pulse-data dataset | |
| // - huggingface.co/api — live Hub API for "right now" lists | |
| const BASE = 'https://modelpulse.ifsp.dev' | |
| const cache = new Map() | |
| export function get(path) { | |
| if (cache.has(path)) return cache.get(path) | |
| const p = fetch(BASE + path) | |
| .then((r) => { if (!r.ok) throw new Error('HTTP ' + r.status); return r.json() }) | |
| .catch((e) => { cache.delete(path); throw e }) | |
| cache.set(path, p) | |
| return p | |
| } | |
| export const api = { | |
| model: (id) => get('/api/model/' + encodeURIComponent(id)), | |
| author: (a) => get('/api/author/' + encodeURIComponent(a)), | |
| search: (q) => get('/api/search?q=' + encodeURIComponent(q)), | |
| leaderboards: () => get('/api/leaderboards'), | |
| hub: () => get('/api/hub'), | |
| } | |
| export async function hubTop(sort, limit) { | |
| const r = await fetch('https://huggingface.co/api/models?sort=' + sort + '&direction=-1&limit=' + limit) | |
| if (!r.ok) throw new Error('HTTP ' + r.status) | |
| return r.json() | |
| } | |