Download code/web/src/components/relation-table.tsx from MiniMaxAI/oss-ecosystem-data: direct link, hf CLI and curl.
- Browser
- Download file 3.56 kB
-
https://huggingface.co/datasets/MiniMaxAI/oss-ecosystem-data/resolve/08b0eafba522f5cf00cfab9c2f665cc634200cbb/code/web/src/components/relation-table.tsx
- Command line
-
hf download hf://datasets/MiniMaxAI/oss-ecosystem-data@08b0eafba522f5cf00cfab9c2f665cc634200cbb/code/web/src/components/relation-table.tsx
-
curl -L -o relation-table.tsx https://huggingface.co/datasets/MiniMaxAI/oss-ecosystem-data/resolve/08b0eafba522f5cf00cfab9c2f665cc634200cbb/code/web/src/components/relation-table.tsx
3.56 kB
| import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table" | |
| import { HF_RELS, REL_NAME, type Lineage, type Rel } from "@/lib/types" | |
| import { num as fmt, full } from "@/lib/format" | |
| import { RelDot, relColor } from "@/components/rel" | |
| /** | |
| * Community models by type next to what Hugging Face's model tree shows. HF has only four types, | |
| * so those come first with their own subtotal; the types HF has no place for follow, then the | |
| * total. Types with nothing in them are left out. | |
| */ | |
| export function RelationTable({ L, order }: { L: Lineage; order: Rel[] }) { | |
| const b = L.by_relation | |
| const hfRels = HF_RELS.filter((r) => b[r].n > 0 || (L.hf_tree[r] ?? 0) > 0) | |
| const extra = order.filter((r) => !HF_RELS.includes(r) && b[r].n > 0) | |
| const max = Math.max(...order.map((r) => b[r].n)) | |
| const sum = (rs: Rel[], k: "n" | "dl30" | "dlall") => rs.reduce((a, r) => a + b[r][k], 0) | |
| const hfSum = HF_RELS.reduce((a, r) => a + (L.hf_tree[r] ?? 0), 0) | |
| const row = (r: Rel) => ( | |
| <TableRow key={r} className="border-border/60 hover:bg-transparent"> | |
| <TableCell className="py-3.5"> | |
| <span className="inline-flex items-center gap-2.5"><RelDot rel={r} />{REL_NAME[r]}</span> | |
| </TableCell> | |
| <TableCell className="py-3.5"> | |
| <div className="flex items-center gap-3"> | |
| <span className="w-14 text-right font-display font-semibold tabular-nums">{full(b[r].n)}</span> | |
| <span className="hidden h-2 rounded-full sm:block" style={{ width: `${(b[r].n / max) * 160}px`, background: relColor(r) }} /> | |
| </div> | |
| </TableCell> | |
| <TableCell className="py-3.5 text-right tabular-nums">{HF_RELS.includes(r) ? full(L.hf_tree[r] ?? 0) : "—"}</TableCell> | |
| <TableCell className="py-3.5 text-right tabular-nums">{fmt(b[r].dl30)}</TableCell> | |
| <TableCell className="py-3.5 text-right tabular-nums">{fmt(b[r].dlall)}</TableCell> | |
| </TableRow> | |
| ) | |
| const total = (label: string, n: number, hf: number | null, d30: number, da: number) => ( | |
| <TableRow className="border-border/60 font-semibold hover:bg-transparent"> | |
| <TableCell className="py-3.5">{label}</TableCell> | |
| <TableCell className="py-3.5"><span className="inline-block w-14 text-right font-display tabular-nums">{full(n)}</span></TableCell> | |
| <TableCell className="py-3.5 text-right tabular-nums">{hf == null ? "—" : full(hf)}</TableCell> | |
| <TableCell className="py-3.5 text-right tabular-nums">{fmt(d30)}</TableCell> | |
| <TableCell className="py-3.5 text-right tabular-nums">{fmt(da)}</TableCell> | |
| </TableRow> | |
| ) | |
| return ( | |
| <Table className="text-[15px]"> | |
| <TableHeader> | |
| <TableRow className="border-border/60 hover:bg-transparent"> | |
| <TableHead className="text-[15px] text-muted-foreground">Type</TableHead> | |
| <TableHead className="text-[15px] text-muted-foreground">Models</TableHead> | |
| <TableHead className="text-right text-[15px] text-muted-foreground">On HF model tree</TableHead> | |
| <TableHead className="text-right text-[15px] text-muted-foreground">Downloads, 30 days</TableHead> | |
| <TableHead className="text-right text-[15px] text-muted-foreground">All-time</TableHead> | |
| </TableRow> | |
| </TableHeader> | |
| <TableBody> | |
| {hfRels.map(row)} | |
| {extra.length > 0 && total("Subtotal", sum(HF_RELS, "n"), hfSum, sum(HF_RELS, "dl30"), sum(HF_RELS, "dlall"))} | |
| {extra.map(row)} | |
| {total("Total", L.n_models, extra.length ? null : hfSum, L.dl30, L.dlall)} | |
| </TableBody> | |
| </Table> | |
| ) | |
| } | |