hub-flow / source /src /api.js
mindchain's picture
Upload source/src/api.js with huggingface_hub
81061f7 verified
Raw History Blame Contribute Delete
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()
}