File size: 1,062 Bytes
81061f7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// 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()
}