File size: 2,794 Bytes
2471af3
0953253
 
2471af3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0953253
2471af3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0953253
2471af3
 
 
 
 
 
 
 
 
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { useMemo } from "react"
import type { Author, Lineage, Repo } from "@/lib/types"
import { relName, T } from "@/lib/i18n"
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">{relName(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.modelsUnit(t.n)}</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>
  )
}