import { ArrowDownIcon, BoxIcon, CpuIcon, FileTextIcon, FolderIcon, HistoryIcon, LanguagesIcon, ListChecksIcon, MessagesSquareIcon, GaugeIcon, ScaleIcon, SparklesIcon, TriangleAlertIcon, } from "lucide-react"; import type { Metadata } from "next"; import Link from "next/link"; import { notFound, redirect } from "next/navigation"; import { Suspense } from "react"; import { CopyButton } from "@/components/copy-button"; import { BenchmarkStateBadge } from "@/components/benchmark-state"; import { PageHero } from "@/components/hero/page-hero"; import { HubStateBadge } from "@/components/hub-state-badge"; import { LocalTime } from "@/components/local-time"; import { ModelStatusBadge } from "@/components/model-status-badge"; import { cn } from "@/lib/utils"; import { formatBytes, shortSha } from "@/lib/format"; import { listBenchmarks } from "@/lib/benchmarks"; import { targetName } from "@/lib/benchmark-view"; import { modelFamilies } from "@/lib/hub/metadata"; import { listModelJobs } from "@/lib/jobs"; import { getModelByRepo, relatedModels } from "@/lib/library"; import { fileRole } from "@/lib/file-roles"; import { quantGroup } from "@/lib/selection"; import { modelTagList } from "@/lib/tags"; import { getWorkerStatus } from "@/lib/worker-status"; import { DownloadCard } from "./download-card"; import { FilesTab } from "./files-tab"; import { HubCheckButton } from "./hub-check"; import { JobsTab } from "./jobs-tab"; import { LocalModelCardSection, ModelCardSection, ModelCardSkeleton } from "./model-card"; import { DeleteModelButton } from "./delete-model-button"; import { TagEditor } from "./tag-editor"; import { RequestedByBadge } from "@/components/requested-by-badge"; import { UpdateBanner } from "./update-banner"; export const dynamic = "force-dynamic"; const TABS = [ { id: "files", label: "Files", icon: FolderIcon }, { id: "card", label: "Model card", icon: FileTextIcon }, { id: "jobs", label: "Jobs", icon: HistoryIcon }, ] as const; type TabId = (typeof TABS)[number]["id"]; const FORMATS: Record = { gguf: "GGUF", safetensors: "Safetensors", transformers: "Transformers", pytorch: "PyTorch", onnx: "ONNX", mlx: "MLX", }; const RELATION_LABEL: Record = { 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 { 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 // A local model has no Hub repo: no commit, Hub checks or model tree; its README is the model card. const local = model.source === "local"; const tab: TabId = TABS.some((t) => t.id === sp.tab) ? (sp.tab as TabId) : "files"; const [author, name] = model.repoId.split("/"); const hub = `https://huggingface.co/${model.repoId}`; const baseModels = model.baseModels ?? []; const hubTags = model.hubTags ?? []; const hubMissing = model.hubState === "repo_missing" || model.hubState === "commit_missing"; // The model card (a Hub request) isn't awaited here: it streams in behind its Suspense boundary. const [tags, related, worker, recentJobs, runs] = await Promise.all([ modelTagList(model.id), relatedModels(model.id, baseModels), getWorkerStatus(), listModelJobs(model.id, 1), listBenchmarks({ modelId: model.id }, { limit: 5 }), // the sidebar shows 5 and links to all ]); const update = !hubMissing && model.updateDiff && model.updateDiff.sha === model.remoteSha && model.remoteSha !== model.pinnedSha ? model.updateDiff : null; 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.filter((f) => fileRole(f.path) === "model").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); const tabHref = (id: TabId) => (id === "files" ? `/${model.repoId}` : `/${model.repoId}?tab=${id}`); return ( {author} / {name} {!local && ( 🤗 )} {local && ( local )} {update && ( update available )} } extra={
{model.pipelineTag && ( {titleCase(model.pipelineTag)} )} {formats.map((f) => ( {f} ))} {model.architecture && {model.architecture}} {languages.length > 0 && {languages.join(", ")}} {model.license && License: {model.license}} {extraTags.map((t) => ( {t} ))}
Your tags
} > {hubMissing && (

{model.hubState === "repo_missing" ? "This repo is no longer on Hugging Face" : "The pinned commit is no longer on Hugging Face"}

{model.hubState === "repo_missing" ? "It was deleted, renamed or made private. " : "The repo's history was rewritten. "} Your local copy is kept and stays usable; downloading more files or repairing isn't possible. {model.hubMissingSince && ( <> {" "} Missing since . )}

)} {update && ( )}
{/* Content card with the tabs as a segmented control in its header */}
0} />
{tab === "card" && (
{local ? ( ) : ( }> )}
)} {tab === "files" && ( )} {tab === "jobs" && (
)}
); } function Avatar({ url, name }: { url: string | null; name: string }) { if (url) { // eslint-disable-next-line @next/next/no-img-element return ; } return ( {name.slice(0, 1)} ); } function Pill({ icon: Icon, accent, muted, children, }: { icon?: React.ComponentType<{ className?: string }>; accent?: boolean; muted?: boolean; children: React.ReactNode; }) { return ( {Icon && } {children} ); } /** Card surface shared by header, content and sidebar. */ function Panel({ className, children }: { className?: string; children: React.ReactNode }) { return
{children}
; } function SideCard({ title, icon: Icon, children, }: { title?: string; icon?: React.ComponentType<{ className?: string }>; children: React.ReactNode; }) { return ( {title && (

{Icon && } {title}

)} {children}
); } function ModelTree({ repoId, baseModels, relation, families, }: { repoId: string; baseModels: string[]; relation: string | null; families: string[]; }) { if (baseModels.length === 0) { return

Original model, family {families.join(", ")}.

; } return (
    {baseModels.map((b) => (
  1. {b}
  2. ))}
  3. {relation ? (RELATION_LABEL[relation] ?? titleCase(relation)) : "Derived"}
  4. {repoId}
); }