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, useState } from 'react'
|
| 2 |
+
import { api, hubTop } from './api.js'
|
| 3 |
+
import { BigChart, Stat, fmt, pct } from './components.jsx'
|
| 4 |
+
|
| 5 |
+
export function Loading({ label }) {
|
| 6 |
+
return (
|
| 7 |
+
<div className="state py-16 text-center text-sm text-[var(--dim)]">
|
| 8 |
+
<span className="mb-3 inline-block h-5 w-5 animate-spin rounded-full border-2 border-[var(--line)] border-t-[var(--dim)]" style={{ display: 'inline-block' }} />
|
| 9 |
+
<br />{label || 'Loading…'}
|
| 10 |
+
</div>
|
| 11 |
+
)
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
export function ErrBox({ e, retry }) {
|
| 15 |
+
return (
|
| 16 |
+
<div className="mt-10 rounded-xl border border-[var(--danger)]/40 bg-[var(--danger)]/5 p-8 text-center">
|
| 17 |
+
<p className="text-sm text-[var(--ink)]">Could not load data{e ? ' (' + e.message + ')' : ''}. The model-pulse API may be rate-limiting or down.</p>
|
| 18 |
+
{retry && <button onClick={retry} className="mt-3 rounded-lg border border-[var(--line)] px-4 py-2 text-sm font-semibold hover:border-[var(--accent)]">Retry</button>}
|
| 19 |
+
</div>
|
| 20 |
+
)
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
const REL_ORDER = ['quantized', 'finetune', 'adapter', 'merge']
|
| 24 |
+
const REL_LABEL = { quantized: 'Quantizations', finetune: 'Fine-tunes', adapter: 'Adapters', merge: 'Merges' }
|
| 25 |
+
|
| 26 |
+
export function ModelPage({ id, go }) {
|
| 27 |
+
const [data, setData] = useState(null)
|
| 28 |
+
const [err, setErr] = useState(null)
|
| 29 |
+
const load = () => { setErr(null); setData(null); api.model(id).then(setData).catch(setErr) }
|
| 30 |
+
useEffect(load, [id])
|
| 31 |
+
if (err) return <ErrBox e={err} retry={load} />
|
| 32 |
+
if (!data) return <Loading label={'Loading ' + id + '…'} />
|
| 33 |
+
const m = data.model || {}
|
| 34 |
+
const rel = data.series && data.series.day && data.series.day.length > 1
|
| 35 |
+
const groups = {}
|
| 36 |
+
;(data.children || []).forEach((c) => { (groups[c.relation] = groups[c.relation] || []).push(c) })
|
| 37 |
+
return (
|
| 38 |
+
<div className="rise">
|
| 39 |
+
<div className="flex flex-wrap items-center gap-2 pt-8">
|
| 40 |
+
<h1 className="break-all font-mono text-xl font-bold tracking-tight sm:text-2xl">{id}</h1>
|
| 41 |
+
{m.pipeline_tag && <span className="rounded-full border border-[var(--line)] px-2.5 py-0.5 text-[11px] text-[var(--dim)]">{m.pipeline_tag}</span>}
|
| 42 |
+
{m.is_gguf && <span className="rounded-full bg-[var(--accent)] px-2.5 py-0.5 text-[11px] font-bold text-black">GGUF</span>}
|
| 43 |
+
{m.license && <span className="hidden rounded-full border border-[var(--line)] px-2.5 py-0.5 text-[11px] text-[var(--faint)] sm:inline">{String(m.license).slice(0, 40)}</span>}
|
| 44 |
+
</div>
|
| 45 |
+
<div className="mt-2 flex flex-wrap gap-x-4 gap-y-1 font-mono text-[11.5px] text-[var(--faint)]">
|
| 46 |
+
{m.params > 0 && <span>{(m.params / 1e9).toFixed(1)}B params</span>}
|
| 47 |
+
{m.created_at && <span>created {String(m.created_at).slice(0, 10)}</span>}
|
| 48 |
+
{m.first_seen && <span>tracked since {m.first_seen}</span>}
|
| 49 |
+
{m.rank_dl30 != null && <span className="text-[var(--dim)]">rank dl30 <b className="text-[var(--ink)]">#{fmt(m.rank_dl30)}</b></span>}
|
| 50 |
+
{m.rank_7d != null && <span className="text-[var(--dim)]">rank 7d <b className="text-[var(--ink)]">#{fmt(m.rank_7d)}</b></span>}
|
| 51 |
+
<a className="underline decoration-[var(--line)] underline-offset-2 hover:decoration-[var(--dim)]" href={'https://huggingface.co/' + id} target="_blank" rel="noopener">open on the Hub ↗</a>
|
| 52 |
+
</div>
|
| 53 |
+
|
| 54 |
+
<div className="mt-6 grid grid-cols-2 divide-[var(--line)] overflow-hidden rounded-2xl border border-[var(--line)] bg-[var(--panel)] sm:grid-cols-3 lg:grid-cols-6 lg:divide-x">
|
| 55 |
+
<Stat k="Downloads 30d" v={m.dl30} sub={m.dl_7d != null ? fmt(m.dl_7d) + ' in 7d' : ''} />
|
| 56 |
+
<Stat k="All time" v={m.dl_all} />
|
| 57 |
+
<Stat k="7d vs prev" v={m.dl_7d} d={m.growth_7d != null ? pct(m.growth_7d) + ' vs week before' : ''} dCls={m.growth_7d >= 0 ? 'text-[var(--up)]' : 'text-[var(--danger)]'} />
|
| 58 |
+
<Stat k="Likes" v={m.likes} sub={m.likes_7d ? '+' + fmt(m.likes_7d) + ' in 7d' : ''} />
|
| 59 |
+
{m.fam_members != null && <Stat k="Family" v={m.fam_members} sub={fmt(m.fam_dl30) + ' dl30'} />}
|
| 60 |
+
{m.trending != null && <Stat k="Trending score" v={m.trending} />}
|
| 61 |
+
</div>
|
| 62 |
+
|
| 63 |
+
<section className="mt-8 rounded-2xl border border-[var(--line)] bg-[var(--panel)] p-4 sm:p-6">
|
| 64 |
+
<div className="flex gap-5 text-[11.5px] text-[var(--dim)]">
|
| 65 |
+
<span><i className="mr-1.5 inline-block h-2 w-2 rounded-[2px] bg-[var(--bar)]" />downloads / day</span>
|
| 66 |
+
<span><i className="mr-1.5 inline-block h-2 w-2 rounded-[2px] bg-[var(--accent)]" />cumulative</span>
|
| 67 |
+
</div>
|
| 68 |
+
{rel ? <BigChart series={data.series} /> : <p className="py-8 text-center text-sm text-[var(--dim)]">No history yet — too new.</p>}
|
| 69 |
+
</section>
|
| 70 |
+
|
| 71 |
+
{(data.children || []).length > 0 && (
|
| 72 |
+
<section className="mt-8">
|
| 73 |
+
<h2 className="border-b border-[var(--ink)] pb-2 text-[13px] font-bold uppercase tracking-[0.08em]">
|
| 74 |
+
Family <span className="font-medium normal-case tracking-normal text-[var(--faint)]">· {(data.children || []).length} derivatives (quantizations, fine-tunes, …)</span>
|
| 75 |
+
</h2>
|
| 76 |
+
{REL_ORDER.filter((r) => groups[r]).concat(Object.keys(groups).filter((r) => !REL_ORDER.includes(r))).map((rel2) => {
|
| 77 |
+
const list = groups[rel2].slice().sort((a, b) => b.dl30 - a.dl30).slice(0, 8)
|
| 78 |
+
const maxdl = Math.max(1, ...groups[rel2].map((c) => c.dl30))
|
| 79 |
+
return (
|
| 80 |
+
<div key={rel2} className="mt-5">
|
| 81 |
+
<h3 className="text-[12px] font-semibold uppercase tracking-[0.06em] text-[var(--dim)]">{REL_LABEL[rel2] || rel2} <span className="text-[var(--faint)]">· {groups[rel2].length}</span></h3>
|
| 82 |
+
<table className="mt-1 w-full">
|
| 83 |
+
<tbody>
|
| 84 |
+
{list.map((c) => (
|
| 85 |
+
<tr key={c.id} onClick={() => go('#/m/' + c.id)} className="cursor-pointer border-b border-[var(--line2)] transition-colors hover:bg-[var(--accent-soft)]/40">
|
| 86 |
+
<td className="break-all py-2.5 pl-1 pr-3 font-mono text-[12.5px]">{c.id}</td>
|
| 87 |
+
<td className="w-[130px] px-3 py-2.5"><div className="h-1.5 rounded-full bg-[var(--line2)]"><div className="h-1.5 rounded-full bg-[var(--accent)]" style={{ width: Math.max(3, (c.dl30 / maxdl) * 100) + '%' }} /></div></td>
|
| 88 |
+
<td className="tnum px-3 py-2.5 text-right text-[12.5px]">{fmt(c.dl30)}</td>
|
| 89 |
+
<td className="tnum hidden px-3 py-2.5 text-right text-[var(--dim)] sm:table-cell">{fmt(c.dl_all)}</td>
|
| 90 |
+
</tr>
|
| 91 |
+
))}
|
| 92 |
+
</tbody>
|
| 93 |
+
</table>
|
| 94 |
+
{groups[rel2].length > 8 && <p className="mt-1 text-[11px] text-[var(--faint)]">+ {groups[rel2].length - 8} more</p>}
|
| 95 |
+
</div>
|
| 96 |
+
)
|
| 97 |
+
})}
|
| 98 |
+
</section>
|
| 99 |
+
)}
|
| 100 |
+
</div>
|
| 101 |
+
)
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
export function AuthorPage({ author, go }) {
|
| 105 |
+
const [data, setData] = useState(null)
|
| 106 |
+
const [live, setLive] = useState(null)
|
| 107 |
+
const [err, setErr] = useState(null)
|
| 108 |
+
const load = () => { setErr(null); setData(null); api.author(author).then(setData).catch(setErr); hubTop('downloads', 1000).then((a) => setLive(a.filter((m) => m.id.startsWith(author + '/')))).catch(() => {}) }
|
| 109 |
+
useEffect(load, [author])
|
| 110 |
+
if (err) return <ErrBox e={err} retry={load} />
|
| 111 |
+
if (!data) return <Loading label={'Loading ' + author + '…'} />
|
| 112 |
+
const models = (data.models || []).slice().sort((a, b) => (b.dl30 || 0) - (a.dl30 || 0))
|
| 113 |
+
const totals = data.totals || {}
|
| 114 |
+
return (
|
| 115 |
+
<div className="rise">
|
| 116 |
+
<h1 className="break-all pt-8 text-2xl font-extrabold tracking-tight sm:text-3xl">{author}</h1>
|
| 117 |
+
<div className="mt-6 grid grid-cols-2 divide-[var(--line)] overflow-hidden rounded-2xl border border-[var(--line)] bg-[var(--panel)] sm:grid-cols-4 lg:divide-x">
|
| 118 |
+
<Stat k="Models" v={(data.models || []).length} />
|
| 119 |
+
<Stat k="Downloads 30d" v={totals.dl30 != null ? totals.dl30 : models.reduce((a, m) => a + (m.dl30 || 0), 0)} />
|
| 120 |
+
<Stat k="All time" v={totals.dl_all != null ? totals.dl_all : models.reduce((a, m) => a + (m.dl_all || 0), 0)} />
|
| 121 |
+
<Stat k="Likes" v={totals.likes != null ? totals.likes : models.reduce((a, m) => a + (m.likes || 0), 0)} />
|
| 122 |
+
</div>
|
| 123 |
+
<section className="mt-8 rounded-2xl border border-[var(--line)] bg-[var(--panel)] p-4 sm:p-6">
|
| 124 |
+
<h2 className="text-[12px] font-semibold uppercase tracking-[0.06em] text-[var(--dim)]">Author downloads, all models combined</h2>
|
| 125 |
+
{data.series && data.series.day && data.series.day.length > 1 ? <BigChart series={data.series} /> : <p className="py-8 text-center text-sm text-[var(--dim)]">No history yet.</p>}
|
| 126 |
+
</section>
|
| 127 |
+
<section className="mt-8">
|
| 128 |
+
<h2 className="border-b border-[var(--ink)] pb-2 text-[13px] font-bold uppercase tracking-[0.08em]">Models <span className="font-medium normal-case tracking-normal text-[var(--faint)]">· {models.length}</span></h2>
|
| 129 |
+
<table className="mt-1 w-full">
|
| 130 |
+
<thead>
|
| 131 |
+
<tr className="text-[10.5px] uppercase tracking-[0.06em] text-[var(--faint)]">
|
| 132 |
+
<th className="py-2 pl-1 text-left font-semibold">Model</th>
|
| 133 |
+
<th className="px-3 py-2 text-right font-semibold">30d</th>
|
| 134 |
+
<th className="hidden px-3 py-2 text-right font-semibold sm:table-cell">All time</th>
|
| 135 |
+
<th className="px-3 py-2 pr-1 text-right font-semibold">♥</th>
|
| 136 |
+
</tr>
|
| 137 |
+
</thead>
|
| 138 |
+
<tbody>
|
| 139 |
+
{models.map((m) => (
|
| 140 |
+
<tr key={m.id} onClick={() => go('#/m/' + m.id)} className="cursor-pointer border-b border-[var(--line2)] transition-colors hover:bg-[var(--accent-soft)]/40">
|
| 141 |
+
<td className="break-all py-2.5 pl-1 pr-3 font-mono text-[12.5px] font-semibold">{m.id.replace(author + '/', '')}{m.pipeline_tag && <span className="ml-2 hidden font-sans text-[11px] font-normal text-[var(--faint)] md:inline">{m.pipeline_tag}</span>}</td>
|
| 142 |
+
<td className="tnum px-3 py-2.5 text-right font-semibold">{fmt(m.dl30)}</td>
|
| 143 |
+
<td className="tnum hidden px-3 py-2.5 text-right sm:table-cell">{fmt(m.dl_all)}</td>
|
| 144 |
+
<td className="tnum px-3 py-2.5 pr-1 text-right text-[var(--dim)]">♥ {fmt(m.likes)}</td>
|
| 145 |
+
</tr>
|
| 146 |
+
))}
|
| 147 |
+
</tbody>
|
| 148 |
+
</table>
|
| 149 |
+
{live && <p className="mt-2 text-[11px] text-[var(--faint)]">Cross-checked live with the Hub API ({live.length} public repos).</p>}
|
| 150 |
+
</section>
|
| 151 |
+
</div>
|
| 152 |
+
)
|
| 153 |
+
}
|