saladday1's picture
code: sync from git
2471af3 verified
Raw History Blame
2.79 kB
import { useMemo } from "react"
import { REL_NAME, type Author, type Lineage, type Repo } from "@/lib/types"
import { num as fmt, hfUrl } from "@/lib/format"
import { relColor } from "@/components/rel"
import { Who } from "@/components/who"
export function TopModels({ repos, authors }: { repos: Repo[]; authors: Record<string, Author> }) {
const top = useMemo(() => [...repos].sort((a, b) => (b.dl30 ?? 0) - (a.dl30 ?? 0)).slice(0, 10), [repos])
const max = Math.max(1, ...top.map((r) => r.dl30 ?? 0))
return (
<ol className="space-y-4">
{top.map((r) => {
const [owner, name] = r.id.split("/")
return (
<li key={r.id} className="flex items-center gap-3">
<Who name={owner} authors={authors} />
<div className="min-w-0 flex-1">
<div className="flex items-baseline justify-between gap-3">
<a href={hfUrl(r.id)} target="_blank" rel="noopener" className="truncate text-[15px] hover:underline" title={r.id}>
<span className="text-muted-foreground">{owner}/</span>{name}
</a>
<span className="shrink-0 font-display text-[15px] font-semibold tabular-nums">{fmt(r.dl30)}</span>
</div>
<div className="mt-1.5 flex items-center gap-3">
<div className="h-1.5 rounded-full" style={{ width: `${Math.max(2, ((r.dl30 ?? 0) / max) * 78)}%`, background: relColor(r.rel) }} />
<span className="shrink-0 text-sm text-muted-foreground">{REL_NAME[r.rel]}</span>
</div>
</div>
</li>
)
})}
</ol>
)
}
export function TopAuthors({ L, authors }: { L: Lineage; authors: Record<string, Author> }) {
const top = (L.top_authors ?? []).slice(0, 10)
const max = Math.max(1, ...top.map((a) => a.n))
return (
<ol className="space-y-4">
{top.map((t) => (
<li key={t.a} className="flex items-center gap-3">
<Who name={t.a} authors={authors} />
<div className="min-w-0 flex-1">
<div className="flex items-baseline justify-between gap-3">
<a href={hfUrl(t.a)} target="_blank" rel="noopener" className="truncate text-[15px] hover:underline">
{authors[t.a]?.n ?? t.a}
{authors[t.a]?.n && authors[t.a].n !== t.a && <span className="ml-2 text-muted-foreground">{t.a}</span>}
</a>
<span className="shrink-0 text-[15px]"><span className="font-display font-semibold tabular-nums">{t.n}</span> {t.n === 1 ? "model" : "models"}</span>
</div>
<div className="mt-1.5 h-1.5 rounded-full bg-[var(--neutral-series)]" style={{ width: `${(t.n / max) * 100}%` }} />
</div>
</li>
))}
</ol>
)
}