Hugging Face style model pages at /<org>/<name>
- Model URLs are the repo path (case-insensitive, canonical redirect); /models/<id> redirects - Header with avatar, org/name + copy, task/format/arch/language/license pills, user tags, cross-links to the Hub (files @ sha, commits, community, base model) and tabs: rendered model card at the pinned commit, files, jobs - Sidebar: download card, local copy, model tree with related local models - Metadata gains author avatar and base relation (refetched once) - Proxy matcher excludes only exact /login and /api/auth/ paths Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d16bd6dfee
commit
1527fcd830
29 files changed
+4335
-269
No files matched your search
@@ -0,0 +1,449 @@
|
||||
import {
|
||||
ArrowDownIcon,
|
||||
BoxIcon,
|
||||
CpuIcon,
|
||||
ExternalLinkIcon,
|
||||
FileTextIcon,
|
||||
FolderIcon,
|
||||
HistoryIcon,
|
||||
LanguagesIcon,
|
||||
ListChecksIcon,
|
||||
MessagesSquareIcon,
|
||||
ScaleIcon,
|
||||
SparklesIcon,
|
||||
} from "lucide-react";
|
||||
import type { Metadata } from "next";
|
||||
import Link from "next/link";
|
||||
import { notFound, redirect } from "next/navigation";
|
||||
import { CopyButton } from "@/components/copy-button";
|
||||
import { LocalTime } from "@/components/local-time";
|
||||
import { ModelStatusBadge } from "@/components/model-status-badge";
|
||||
import { buttonVariants } from "@/components/ui/button";
|
||||
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { formatBytes, shortSha } from "@/lib/format";
|
||||
import { fetchModelCard } from "@/lib/hub/client";
|
||||
import { modelFamilies } from "@/lib/hub/metadata";
|
||||
import { getModelByRepo, relatedModels } from "@/lib/library";
|
||||
import { quantGroup } from "@/lib/selection";
|
||||
import { modelTagList } from "@/lib/tags";
|
||||
import { DownloadCard } from "./download-card";
|
||||
import { JobsTab } from "./jobs-tab";
|
||||
import { ModelCard } from "./model-card";
|
||||
import { RemoveModelButton } from "./remove-model-button";
|
||||
import { TagEditor } from "./tag-editor";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
const TABS = [
|
||||
{ id: "card", label: "Model card", icon: FileTextIcon },
|
||||
{ id: "files", label: "Files", icon: FolderIcon },
|
||||
{ id: "jobs", label: "Jobs", icon: HistoryIcon },
|
||||
] as const;
|
||||
type TabId = (typeof TABS)[number]["id"];
|
||||
|
||||
const FORMATS: Record<string, string> = {
|
||||
gguf: "GGUF",
|
||||
safetensors: "Safetensors",
|
||||
transformers: "Transformers",
|
||||
pytorch: "PyTorch",
|
||||
onnx: "ONNX",
|
||||
mlx: "MLX",
|
||||
};
|
||||
|
||||
const RELATION_LABEL: Record<string, string> = {
|
||||
quantized: "Quantized",
|
||||
finetune: "Finetuned",
|
||||
adapter: "Adapter",
|
||||
merge: "Merged",
|
||||
};
|
||||
|
||||
const titleCase = (s: string) => s.replace(/[-_]/g, " ").replace(/\b\w/g, (c) => c.toUpperCase());
|
||||
|
||||
function languageName(code: string): string | null {
|
||||
if (!/^[a-z]{2,3}$/.test(code)) return null;
|
||||
try {
|
||||
const name = new Intl.DisplayNames(["en"], { type: "language" }).of(code);
|
||||
return name && name !== code ? name : null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export async function generateMetadata({ params }: PageProps<"/[org]/[repo]">): Promise<Metadata> {
|
||||
const { org, repo } = await params;
|
||||
return { title: `${org}/${repo}` };
|
||||
}
|
||||
|
||||
export default async function ModelPage({ params, searchParams }: PageProps<"/[org]/[repo]">) {
|
||||
const { org, repo } = await params;
|
||||
const sp = await searchParams;
|
||||
const data = await getModelByRepo(`${org}/${repo}`);
|
||||
if (!data) notFound();
|
||||
const { model, files } = data;
|
||||
if (model.repoId !== `${org}/${repo}`) redirect(`/${model.repoId}`); // canonical spelling
|
||||
|
||||
const tab: TabId = TABS.some((t) => t.id === sp.tab) ? (sp.tab as TabId) : "card";
|
||||
const [author, name] = model.repoId.split("/");
|
||||
const hub = `https://huggingface.co/${model.repoId}`;
|
||||
const baseModels = model.baseModels ?? [];
|
||||
const hubTags = model.hubTags ?? [];
|
||||
|
||||
const [tags, related, card] = await Promise.all([
|
||||
modelTagList(model.id),
|
||||
relatedModels(model.id, baseModels),
|
||||
tab === "card" ? fetchModelCard(model.repoId, model.pinnedSha).catch(() => undefined) : Promise.resolve(undefined),
|
||||
]);
|
||||
|
||||
const selected = files.filter((f) => f.selected);
|
||||
const others = files.filter((f) => !f.selected);
|
||||
const selectedBytes = selected.reduce((s, f) => s + f.size, 0);
|
||||
const quants = [...new Set(selected.map((f) => quantGroup(f.path)).filter(Boolean))] as string[];
|
||||
|
||||
const formats = hubTags.filter((t) => FORMATS[t]).map((t) => FORMATS[t]);
|
||||
const languages = hubTags.map(languageName).filter(Boolean) as string[];
|
||||
const shown = new Set([...Object.keys(FORMATS), model.architecture, author.toLowerCase(), model.pipelineTag]);
|
||||
const extraTags = hubTags.filter((t) => !shown.has(t) && !languageName(t)).slice(0, 8);
|
||||
|
||||
return (
|
||||
<div className="flex flex-col">
|
||||
{/* Header, styled after the Hugging Face model page */}
|
||||
{/* Full-bleed background behind the header (the page itself is width-limited). */}
|
||||
<div className="relative isolate -mt-6 pt-6 before:absolute before:inset-y-0 before:left-1/2 before:-z-10 before:w-screen before:-translate-x-1/2 before:border-b before:border-border before:bg-gradient-to-b before:from-muted/70 before:to-background">
|
||||
<div className="flex flex-wrap items-center gap-x-2 gap-y-2">
|
||||
<Avatar url={model.authorAvatarUrl} name={author} />
|
||||
<Link href={`/?author=${encodeURIComponent(author)}`} className="text-muted-foreground hover:text-foreground hover:underline">
|
||||
{author}
|
||||
</Link>
|
||||
<span className="text-muted-foreground">/</span>
|
||||
<h1 className="text-xl font-semibold break-all">{name}</h1>
|
||||
<CopyButton value={model.repoId} label="Copy repo ID" />
|
||||
<ModelStatusBadge status={model.status} />
|
||||
{model.status === "pending" && (
|
||||
<div className="ml-auto">
|
||||
<RemoveModelButton id={model.id} />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="mt-3 flex flex-wrap items-center gap-1.5">
|
||||
{model.pipelineTag && (
|
||||
<Pill icon={MessagesSquareIcon} accent>
|
||||
{titleCase(model.pipelineTag)}
|
||||
</Pill>
|
||||
)}
|
||||
{formats.map((f) => (
|
||||
<Pill key={f} icon={BoxIcon}>
|
||||
{f}
|
||||
</Pill>
|
||||
))}
|
||||
{model.architecture && <Pill icon={CpuIcon}>{model.architecture}</Pill>}
|
||||
{languages.length > 0 && <Pill icon={LanguagesIcon}>{languages.join(", ")}</Pill>}
|
||||
{model.license && <Pill icon={ScaleIcon}>License: {model.license}</Pill>}
|
||||
{extraTags.map((t) => (
|
||||
<Pill key={t} muted>
|
||||
{t}
|
||||
</Pill>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div className="mt-3 flex flex-wrap items-center gap-2">
|
||||
<span className="text-xs text-muted-foreground">Your tags</span>
|
||||
<TagEditor modelId={model.id} tags={tags} />
|
||||
</div>
|
||||
|
||||
<div className="mt-4 flex flex-wrap gap-2">
|
||||
<ExternalButton href={hub}>🤗 Hugging Face</ExternalButton>
|
||||
<ExternalButton href={`${hub}/tree/${model.pinnedSha}`}>Files @ {shortSha(model.pinnedSha)}</ExternalButton>
|
||||
<ExternalButton href={`${hub}/commits/${encodeURIComponent(model.trackedRevision)}`}>Commits</ExternalButton>
|
||||
<ExternalButton href={`${hub}/discussions`}>Community</ExternalButton>
|
||||
{baseModels[0] && (
|
||||
<ExternalButton href={`https://huggingface.co/${baseModels[0]}`}>Base: {baseModels[0]}</ExternalButton>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<nav className="mt-4 -mb-px flex gap-1">
|
||||
{TABS.map((t) => (
|
||||
<Link
|
||||
key={t.id}
|
||||
href={t.id === "card" ? `/${model.repoId}` : `/${model.repoId}?tab=${t.id}`}
|
||||
scroll={false}
|
||||
className={cn(
|
||||
"flex items-center gap-1.5 border-b-2 px-3 py-2 text-sm transition-colors",
|
||||
tab === t.id
|
||||
? "border-foreground font-medium text-foreground"
|
||||
: "border-transparent text-muted-foreground hover:text-foreground",
|
||||
)}
|
||||
>
|
||||
<t.icon className="size-4" />
|
||||
{t.label}
|
||||
{t.id === "files" && <span className="text-xs text-muted-foreground tabular-nums">{selected.length}</span>}
|
||||
</Link>
|
||||
))}
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
<div className="grid gap-8 pt-6 lg:grid-cols-[minmax(0,1fr)_320px]">
|
||||
<section className="min-w-0">
|
||||
{tab === "card" &&
|
||||
(card ? (
|
||||
<ModelCard markdown={card} repoId={model.repoId} sha={model.pinnedSha} />
|
||||
) : (
|
||||
<p className="py-6 text-sm text-muted-foreground">
|
||||
{card === null ? "This repository has no model card." : "The model card could not be loaded."}{" "}
|
||||
<a href={hub} target="_blank" rel="noreferrer" className="underline">
|
||||
Open on Hugging Face
|
||||
</a>
|
||||
</p>
|
||||
))}
|
||||
{tab === "files" && <FilesTab repoId={model.repoId} sha={model.pinnedSha} selected={selected} others={others} />}
|
||||
{tab === "jobs" && <JobsTab modelId={model.id} />}
|
||||
</section>
|
||||
|
||||
<aside className="flex flex-col gap-4">
|
||||
<SideCard>
|
||||
<DownloadCard modelId={model.id} status={model.status} />
|
||||
</SideCard>
|
||||
|
||||
<SideCard title="Local copy" icon={ListChecksIcon}>
|
||||
<dl className="grid grid-cols-[max-content_1fr] gap-x-4 gap-y-1.5 text-sm">
|
||||
<dt className="text-muted-foreground">Selection</dt>
|
||||
<dd>{quants.length > 0 ? quants.join(", ") : `${selected.length} file${selected.length === 1 ? "" : "s"}`}</dd>
|
||||
<dt className="text-muted-foreground">Size</dt>
|
||||
<dd className="tabular-nums">{formatBytes(selectedBytes)}</dd>
|
||||
<dt className="text-muted-foreground">Commit</dt>
|
||||
<dd className="flex items-center gap-1">
|
||||
<a href={`${hub}/commit/${model.pinnedSha}`} target="_blank" rel="noreferrer" className="font-mono hover:underline" title={model.pinnedSha}>
|
||||
{shortSha(model.pinnedSha)}
|
||||
</a>
|
||||
<span className="text-muted-foreground">on {model.trackedRevision}</span>
|
||||
<CopyButton value={model.pinnedSha} label="Copy commit SHA" />
|
||||
</dd>
|
||||
<dt className="text-muted-foreground">Downloaded</dt>
|
||||
<dd>
|
||||
<LocalTime value={model.downloadedAt} />
|
||||
</dd>
|
||||
<dt className="text-muted-foreground">Path</dt>
|
||||
<dd className="flex min-w-0 items-center gap-1">
|
||||
<span className="truncate font-mono text-xs" title={`$MODELS_DIR/${model.localPath}`}>
|
||||
{model.localPath}
|
||||
</span>
|
||||
<CopyButton value={model.localPath} label="Copy path" />
|
||||
</dd>
|
||||
{model.includePatterns.length > 0 && (
|
||||
<>
|
||||
<dt className="text-muted-foreground">Include</dt>
|
||||
<dd className="flex flex-col font-mono text-xs">{model.includePatterns.map((p) => <span key={p} className="break-all">{p}</span>)}</dd>
|
||||
</>
|
||||
)}
|
||||
{model.excludePatterns.length > 0 && (
|
||||
<>
|
||||
<dt className="text-muted-foreground">Exclude</dt>
|
||||
<dd className="flex flex-col font-mono text-xs">{model.excludePatterns.map((p) => <span key={p} className="break-all">{p}</span>)}</dd>
|
||||
</>
|
||||
)}
|
||||
<dt className="text-muted-foreground">Added</dt>
|
||||
<dd>
|
||||
<LocalTime value={model.createdAt} />
|
||||
</dd>
|
||||
</dl>
|
||||
</SideCard>
|
||||
|
||||
<SideCard title="Model tree" icon={SparklesIcon}>
|
||||
<ModelTree
|
||||
repoId={model.repoId}
|
||||
baseModels={baseModels}
|
||||
relation={model.baseRelation}
|
||||
families={modelFamilies(model.repoId, baseModels)}
|
||||
/>
|
||||
{related.length > 0 && (
|
||||
<div className="mt-4 flex flex-col gap-1.5 border-t pt-3">
|
||||
<span className="text-xs text-muted-foreground">Also in your library</span>
|
||||
{related.map((r) => (
|
||||
<Link key={r.repoId} href={`/${r.repoId}`} className="flex items-center justify-between gap-2 text-sm hover:underline">
|
||||
<span className="truncate">{r.repoId}</span>
|
||||
<span className="shrink-0 text-xs text-muted-foreground">{r.quants.join(", ")}</span>
|
||||
</Link>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</SideCard>
|
||||
</aside>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function Avatar({ url, name }: { url: string | null; name: string }) {
|
||||
if (url) {
|
||||
// eslint-disable-next-line @next/next/no-img-element
|
||||
return <img src={url} alt="" className="size-6 rounded-md object-cover" referrerPolicy="no-referrer" />;
|
||||
}
|
||||
return (
|
||||
<span className="grid size-6 place-items-center rounded-md bg-muted text-xs font-semibold uppercase">
|
||||
{name.slice(0, 1)}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
function Pill({
|
||||
icon: Icon,
|
||||
accent,
|
||||
muted,
|
||||
children,
|
||||
}: {
|
||||
icon?: React.ComponentType<{ className?: string }>;
|
||||
accent?: boolean;
|
||||
muted?: boolean;
|
||||
children: React.ReactNode;
|
||||
}) {
|
||||
return (
|
||||
<span
|
||||
className={cn(
|
||||
"inline-flex items-center gap-1 rounded-md border px-2 py-0.5 text-xs",
|
||||
accent && "border-indigo-500/30 bg-indigo-500/10 text-indigo-700 dark:text-indigo-300",
|
||||
muted && "text-muted-foreground",
|
||||
)}
|
||||
>
|
||||
{Icon && <Icon className="size-3.5" />}
|
||||
{children}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
function ExternalButton({ href, children }: { href: string; children: React.ReactNode }) {
|
||||
return (
|
||||
<a href={href} target="_blank" rel="noreferrer" className={cn(buttonVariants({ variant: "outline", size: "sm" }), "border-foreground/15 bg-background shadow-xs")}>
|
||||
{children}
|
||||
<ExternalLinkIcon className="opacity-60" />
|
||||
</a>
|
||||
);
|
||||
}
|
||||
|
||||
function SideCard({
|
||||
title,
|
||||
icon: Icon,
|
||||
children,
|
||||
}: {
|
||||
title?: string;
|
||||
icon?: React.ComponentType<{ className?: string }>;
|
||||
children: React.ReactNode;
|
||||
}) {
|
||||
return (
|
||||
<div className="rounded-xl border bg-card p-4">
|
||||
{title && (
|
||||
<h3 className="mb-3 flex items-center gap-1.5 text-sm font-semibold">
|
||||
{Icon && <Icon className="size-4 text-muted-foreground" />}
|
||||
{title}
|
||||
</h3>
|
||||
)}
|
||||
{children}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function ModelTree({
|
||||
repoId,
|
||||
baseModels,
|
||||
relation,
|
||||
families,
|
||||
}: {
|
||||
repoId: string;
|
||||
baseModels: string[];
|
||||
relation: string | null;
|
||||
families: string[];
|
||||
}) {
|
||||
if (baseModels.length === 0) {
|
||||
return <p className="text-sm text-muted-foreground">Original model, family {families.join(", ")}.</p>;
|
||||
}
|
||||
return (
|
||||
<ol className="flex flex-col items-start gap-1 text-sm">
|
||||
{baseModels.map((b) => (
|
||||
<li key={b}>
|
||||
<a href={`https://huggingface.co/${b}`} target="_blank" rel="noreferrer" className="hover:underline">
|
||||
{b}
|
||||
</a>
|
||||
</li>
|
||||
))}
|
||||
<li className="flex items-center gap-1 pl-2 text-xs text-muted-foreground">
|
||||
<ArrowDownIcon className="size-3.5" />
|
||||
{relation ? (RELATION_LABEL[relation] ?? titleCase(relation)) : "Derived"}
|
||||
</li>
|
||||
<li className="font-medium">{repoId}</li>
|
||||
</ol>
|
||||
);
|
||||
}
|
||||
|
||||
function FilesTab({
|
||||
repoId,
|
||||
sha,
|
||||
selected,
|
||||
others,
|
||||
}: {
|
||||
repoId: string;
|
||||
sha: string;
|
||||
selected: { id: string; path: string; size: number; lfsSha256: string | null; state: string }[];
|
||||
others: { id: string; path: string; size: number; lfsSha256: string | null }[];
|
||||
}) {
|
||||
const blob = (path: string) => `https://huggingface.co/${repoId}/blob/${sha}/${path}`;
|
||||
return (
|
||||
<div className="flex flex-col gap-4">
|
||||
<div className="overflow-hidden rounded-xl border">
|
||||
<div className="border-b bg-muted/40 px-3 py-2 text-sm">
|
||||
<span className="font-medium">Selected files</span>{" "}
|
||||
<span className="text-muted-foreground">
|
||||
· {selected.length} · {formatBytes(selected.reduce((s, f) => s + f.size, 0))} · at {shortSha(sha)}
|
||||
</span>
|
||||
</div>
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead>File</TableHead>
|
||||
<TableHead className="text-right">Size</TableHead>
|
||||
<TableHead>Local</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{selected.map((f) => (
|
||||
<TableRow key={f.id}>
|
||||
<TableCell className="font-mono text-xs break-all whitespace-normal">
|
||||
<a href={blob(f.path)} target="_blank" rel="noreferrer" className="hover:underline">
|
||||
{f.path}
|
||||
</a>
|
||||
{f.lfsSha256 && <span className="ml-2 rounded border px-1 text-[10px] text-muted-foreground">LFS</span>}
|
||||
</TableCell>
|
||||
<TableCell className="text-right tabular-nums">{formatBytes(f.size)}</TableCell>
|
||||
<TableCell className="text-sm text-muted-foreground">{f.state}</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</div>
|
||||
|
||||
{others.length > 0 && (
|
||||
<details className="overflow-hidden rounded-xl border">
|
||||
<summary className="cursor-pointer bg-muted/40 px-3 py-2 text-sm">
|
||||
<span className="font-medium">Other files in the repo</span>{" "}
|
||||
<span className="text-muted-foreground">
|
||||
· {others.length} · {formatBytes(others.reduce((s, f) => s + f.size, 0))} · not downloaded
|
||||
</span>
|
||||
</summary>
|
||||
<Table>
|
||||
<TableBody>
|
||||
{others.map((f) => (
|
||||
<TableRow key={f.id}>
|
||||
<TableCell className="font-mono text-xs break-all whitespace-normal text-muted-foreground">
|
||||
<a href={blob(f.path)} target="_blank" rel="noreferrer" className="hover:underline">
|
||||
{f.path}
|
||||
</a>
|
||||
</TableCell>
|
||||
<TableCell className="w-28 text-right text-muted-foreground tabular-nums">{formatBytes(f.size)}</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</details>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user