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,98 @@
|
||||
"use client";
|
||||
|
||||
import Link from "next/link";
|
||||
import { useState } from "react";
|
||||
import { cancelJob, startDownload } from "@/components/job-actions";
|
||||
import { JobProgress, JobStateBadge } from "@/components/job-progress";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Progress } from "@/components/ui/progress";
|
||||
import { useLive } from "@/hooks/use-live";
|
||||
import type { ModelStatus } from "@/lib/db/schema";
|
||||
import { formatBytes, percent } from "@/lib/format";
|
||||
|
||||
const OPEN = ["queued", "downloading", "verifying"];
|
||||
|
||||
/** Sidebar card: current download state, actions and (while running) per-file progress. */
|
||||
export function DownloadCard({ modelId, status }: { modelId: string; status: ModelStatus }) {
|
||||
const { snapshot } = useLive({ model: modelId });
|
||||
const [busy, setBusy] = useState(false);
|
||||
const latest = snapshot?.jobs[0];
|
||||
const open = latest && OPEN.includes(latest.state) ? latest : undefined;
|
||||
const files = open ? (snapshot?.files ?? []) : [];
|
||||
|
||||
async function run(fn: () => Promise<void>) {
|
||||
setBusy(true);
|
||||
try {
|
||||
await fn();
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
let hint = "Downloads the selected files at the pinned commit.";
|
||||
if (open?.state === "queued") hint = snapshot?.worker.online ? "Waiting for a free download slot." : "Queued, but the worker is offline.";
|
||||
else if (open) hint = "Runs in the background; you can close this page.";
|
||||
else if (status === "ready") hint = "All selected files are present.";
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-3">
|
||||
<div className="flex items-center justify-between gap-2">
|
||||
<h3 className="text-sm font-semibold">Download</h3>
|
||||
{latest && <JobStateBadge job={latest} />}
|
||||
</div>
|
||||
<p className="text-xs text-muted-foreground">{hint}</p>
|
||||
|
||||
{latest && !(latest.state === "completed" && status === "ready") && <JobProgress job={latest} compact />}
|
||||
|
||||
{latest?.state === "failed" && latest.errorMessage && (
|
||||
<pre className="max-h-40 overflow-auto rounded-md bg-destructive/10 px-2.5 py-2 text-xs whitespace-pre-wrap text-destructive">
|
||||
{latest.errorMessage}
|
||||
</pre>
|
||||
)}
|
||||
|
||||
{files.length > 0 && (
|
||||
<ul className="flex flex-col gap-1.5">
|
||||
{files.map((f) => (
|
||||
<li key={f.modelFileId} className="flex flex-col gap-1">
|
||||
<div className="flex justify-between gap-2 text-xs">
|
||||
<span className="truncate font-mono" title={f.path}>
|
||||
{f.path}
|
||||
</span>
|
||||
<span className="shrink-0 text-muted-foreground tabular-nums">{formatBytes(f.expectedBytes)}</span>
|
||||
</div>
|
||||
<Progress value={percent(f.doneBytes, f.expectedBytes)} />
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{open ? (
|
||||
<Button
|
||||
variant="destructive"
|
||||
size="sm"
|
||||
disabled={busy || open.cancelRequested}
|
||||
onClick={() => run(() => cancelJob(open.id))}
|
||||
>
|
||||
{open.cancelRequested ? "Cancelling…" : "Cancel"}
|
||||
</Button>
|
||||
) : (
|
||||
status !== "ready" &&
|
||||
snapshot && (
|
||||
<Button size="sm" disabled={busy} onClick={() => run(() => startDownload(modelId))}>
|
||||
{latest ? "Download again" : "Download"}
|
||||
</Button>
|
||||
)
|
||||
)}
|
||||
{latest && (
|
||||
<Link
|
||||
href={`/jobs/${latest.id}`}
|
||||
className="inline-flex h-7 items-center rounded-md px-2.5 text-[0.8rem] hover:bg-muted"
|
||||
>
|
||||
View log
|
||||
</Link>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
"use client";
|
||||
|
||||
import Link from "next/link";
|
||||
import { JobStateBadge } from "@/components/job-progress";
|
||||
import { LocalTime } from "@/components/local-time";
|
||||
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table";
|
||||
import { useLive } from "@/hooks/use-live";
|
||||
import { formatBytes } from "@/lib/format";
|
||||
|
||||
/** Job history of one model (live). */
|
||||
export function JobsTab({ modelId }: { modelId: string }) {
|
||||
const { snapshot } = useLive({ model: modelId });
|
||||
const jobs = snapshot?.jobs ?? [];
|
||||
|
||||
if (snapshot && jobs.length === 0) {
|
||||
return <p className="py-6 text-sm text-muted-foreground">No jobs yet.</p>;
|
||||
}
|
||||
return (
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead>Started</TableHead>
|
||||
<TableHead>Kind</TableHead>
|
||||
<TableHead>State</TableHead>
|
||||
<TableHead className="text-right">Size</TableHead>
|
||||
<TableHead className="hidden sm:table-cell">Finished</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{jobs.map((j) => (
|
||||
<TableRow key={j.id}>
|
||||
<TableCell>
|
||||
<Link href={`/jobs/${j.id}`} className="hover:underline">
|
||||
<LocalTime value={j.startedAt ?? j.createdAt} />
|
||||
</Link>
|
||||
</TableCell>
|
||||
<TableCell className="text-sm">
|
||||
{j.kind}
|
||||
{j.purpose && j.purpose !== "initial" ? ` (${j.purpose})` : ""}
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<JobStateBadge job={j} />
|
||||
</TableCell>
|
||||
<TableCell className="text-right text-sm tabular-nums">{formatBytes(j.totalBytes)}</TableCell>
|
||||
<TableCell className="hidden text-sm text-muted-foreground sm:table-cell">
|
||||
<LocalTime value={j.finishedAt} />
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
import ReactMarkdown, { defaultUrlTransform } from "react-markdown";
|
||||
import rehypeRaw from "rehype-raw";
|
||||
import rehypeSanitize, { defaultSchema } from "rehype-sanitize";
|
||||
import remarkGfm from "remark-gfm";
|
||||
|
||||
// Model cards mix Markdown and raw HTML. Parse the HTML (rehype-raw), then sanitize it: no scripts,
|
||||
// styles or event handlers, only the tags/attributes GitHub-style READMEs normally use.
|
||||
const schema = {
|
||||
...defaultSchema,
|
||||
attributes: {
|
||||
...defaultSchema.attributes,
|
||||
img: [...(defaultSchema.attributes?.img ?? []), "width", "height", "align", "loading"],
|
||||
div: [...(defaultSchema.attributes?.div ?? []), "align"],
|
||||
p: [...(defaultSchema.attributes?.p ?? []), "align"],
|
||||
td: [...(defaultSchema.attributes?.td ?? []), "align"],
|
||||
th: [...(defaultSchema.attributes?.th ?? []), "align"],
|
||||
},
|
||||
};
|
||||
|
||||
/** Renders a repo's README like the Hub: relative links/images point at the pinned commit. */
|
||||
export function ModelCard({ markdown, repoId, sha }: { markdown: string; repoId: string; sha: string }) {
|
||||
const base = `https://huggingface.co/${repoId}`;
|
||||
return (
|
||||
<article className="prose prose-sm max-w-none dark:prose-invert prose-headings:scroll-mt-20 prose-img:inline-block prose-img:my-1 prose-pre:bg-muted prose-pre:text-foreground prose-table:text-xs">
|
||||
<ReactMarkdown
|
||||
remarkPlugins={[remarkGfm]}
|
||||
rehypePlugins={[rehypeRaw, [rehypeSanitize, schema]]}
|
||||
urlTransform={(url, key) => {
|
||||
const safe = defaultUrlTransform(url);
|
||||
if (!safe || safe.startsWith("#") || /^[a-z][a-z0-9+.-]*:|^\/\//i.test(safe)) return safe;
|
||||
// Relative path inside the repo: images from /resolve, links to /blob, both at the pinned SHA.
|
||||
const path = safe.replace(/^\.?\//, "");
|
||||
return key === "src" ? `${base}/resolve/${sha}/${path}` : `${base}/blob/${sha}/${path}`;
|
||||
}}
|
||||
components={{
|
||||
a: ({ href, children, ...props }) => (
|
||||
<a href={href} {...props} target={href?.startsWith("#") ? undefined : "_blank"} rel="noreferrer">
|
||||
{children}
|
||||
</a>
|
||||
),
|
||||
// eslint-disable-next-line @next/next/no-img-element
|
||||
img: ({ alt, ...props }) => <img alt={alt ?? ""} loading="lazy" referrerPolicy="no-referrer" {...props} />,
|
||||
}}
|
||||
>
|
||||
{markdown}
|
||||
</ReactMarkdown>
|
||||
</article>
|
||||
);
|
||||
}
|
||||
@@ -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>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
"use client";
|
||||
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import { toast } from "sonner";
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
AlertDialogCancel,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
AlertDialogTrigger,
|
||||
} from "@/components/ui/alert-dialog";
|
||||
import { Button } from "@/components/ui/button";
|
||||
|
||||
/** Removes a not-yet-downloaded model from the library (DB only, no files exist yet). */
|
||||
export function RemoveModelButton({ id }: { id: string }) {
|
||||
const router = useRouter();
|
||||
const [busy, setBusy] = useState(false);
|
||||
|
||||
async function remove() {
|
||||
setBusy(true);
|
||||
const res = await fetch(`/api/models/${id}`, { method: "DELETE" });
|
||||
if (res.ok) {
|
||||
toast.success("Removed from library");
|
||||
router.push("/");
|
||||
router.refresh();
|
||||
} else {
|
||||
const body = await res.json().catch(() => ({}));
|
||||
toast.error(body.error?.message ?? `Remove failed (${res.status})`);
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<AlertDialog>
|
||||
<AlertDialogTrigger render={<Button variant="destructive" size="sm" />}>Remove</AlertDialogTrigger>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>Remove from library?</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
Nothing has been downloaded yet, so this only removes the entry.
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>Cancel</AlertDialogCancel>
|
||||
<AlertDialogAction variant="destructive" onClick={remove} disabled={busy}>
|
||||
Remove
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
"use client";
|
||||
|
||||
import { XIcon } from "lucide-react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useEffect, useId, useState } from "react";
|
||||
import { toast } from "sonner";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import type { Tag } from "@/lib/tags";
|
||||
|
||||
/** Add/remove user tags on a model; suggests existing tags. */
|
||||
export function TagEditor({ modelId, tags }: { modelId: string; tags: Tag[] }) {
|
||||
const router = useRouter();
|
||||
const listId = useId();
|
||||
const [value, setValue] = useState("");
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [suggestions, setSuggestions] = useState<string[]>([]);
|
||||
|
||||
useEffect(() => {
|
||||
fetch("/api/tags")
|
||||
.then((r) => (r.ok ? r.json() : []))
|
||||
.then((all: Tag[]) => setSuggestions(all.map((t) => t.name)))
|
||||
.catch(() => {});
|
||||
}, [tags]);
|
||||
|
||||
async function add(name: string) {
|
||||
if (!name.trim()) return;
|
||||
setBusy(true);
|
||||
const res = await fetch(`/api/models/${modelId}/tags`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ name }),
|
||||
});
|
||||
setBusy(false);
|
||||
if (!res.ok) {
|
||||
const body = await res.json().catch(() => ({}));
|
||||
toast.error(body.error?.message ?? `Could not add tag (${res.status})`);
|
||||
return;
|
||||
}
|
||||
setValue("");
|
||||
router.refresh();
|
||||
}
|
||||
|
||||
async function remove(tag: Tag) {
|
||||
const res = await fetch(`/api/models/${modelId}/tags/${tag.id}`, { method: "DELETE" });
|
||||
if (!res.ok) toast.error(`Could not remove tag (${res.status})`);
|
||||
router.refresh();
|
||||
}
|
||||
|
||||
const current = new Set(tags.map((t) => t.name.toLowerCase()));
|
||||
return (
|
||||
<div className="flex flex-wrap items-center gap-1.5">
|
||||
{tags.map((t) => (
|
||||
<Badge key={t.id} variant="secondary" className="gap-1">
|
||||
{t.name}
|
||||
<button type="button" aria-label={`Remove tag ${t.name}`} onClick={() => remove(t)}>
|
||||
<XIcon className="size-3" />
|
||||
</button>
|
||||
</Badge>
|
||||
))}
|
||||
<form
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
void add(value);
|
||||
}}
|
||||
>
|
||||
<Input
|
||||
value={value}
|
||||
onChange={(e) => setValue(e.target.value)}
|
||||
list={listId}
|
||||
placeholder="Add tag…"
|
||||
disabled={busy}
|
||||
maxLength={40}
|
||||
className="h-6 w-36 text-xs"
|
||||
aria-label="Add tag"
|
||||
/>
|
||||
<datalist id={listId}>
|
||||
{suggestions
|
||||
.filter((s) => !current.has(s.toLowerCase()))
|
||||
.map((s) => (
|
||||
<option key={s} value={s} />
|
||||
))}
|
||||
</datalist>
|
||||
</form>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user