Model page: Files tab first with a new file list, colored tags, single Hub link
- Files is the default tab: icon/size/LFS/state per file, on-disk summary, unselected files collapsed - Custom tags color-coded by name (editor, library, filter chips and menu) - Header: only the Hugging Face link (top right); README link moved to the end of the model card - App icon; proxy lets /icon.svg through Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
5fadd64367
commit
6dc9527682
9 files changed
+263
-119
No files matched your search
@@ -0,0 +1,141 @@
|
||||
import {
|
||||
AlertTriangleIcon,
|
||||
BoxIcon,
|
||||
CheckCircle2Icon,
|
||||
ChevronRightIcon,
|
||||
CircleDashedIcon,
|
||||
FileIcon,
|
||||
FileImageIcon,
|
||||
FileJsonIcon,
|
||||
FileTextIcon,
|
||||
ShieldCheckIcon,
|
||||
XCircleIcon,
|
||||
} from "lucide-react";
|
||||
import { Progress } from "@/components/ui/progress";
|
||||
import type { ModelFileState } from "@/lib/db/schema";
|
||||
import { formatBytes, percent, shortSha } from "@/lib/format";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
type FileRow = { id: string; path: string; size: number; lfsSha256: string | null; state: ModelFileState };
|
||||
|
||||
const STATE: Record<ModelFileState, { label: string; icon: React.ReactNode; className: string }> = {
|
||||
pending: { label: "Not downloaded", icon: <CircleDashedIcon className="size-3.5" />, className: "text-muted-foreground" },
|
||||
present: { label: "Downloaded", icon: <CheckCircle2Icon className="size-3.5" />, className: "text-emerald-600 dark:text-emerald-400" },
|
||||
verified: { label: "Verified", icon: <ShieldCheckIcon className="size-3.5" />, className: "text-emerald-600 dark:text-emerald-400" },
|
||||
missing: { label: "Missing", icon: <XCircleIcon className="size-3.5" />, className: "text-destructive" },
|
||||
size_mismatch: { label: "Size mismatch", icon: <AlertTriangleIcon className="size-3.5" />, className: "text-amber-600 dark:text-amber-400" },
|
||||
hash_mismatch: { label: "Hash mismatch", icon: <AlertTriangleIcon className="size-3.5" />, className: "text-amber-600 dark:text-amber-400" },
|
||||
};
|
||||
|
||||
function FileTypeIcon({ path }: { path: string }) {
|
||||
const ext = path.toLowerCase().split(".").pop() ?? "";
|
||||
const cls = "size-4 text-muted-foreground";
|
||||
if (["gguf", "safetensors", "bin", "pt", "onnx"].includes(ext)) return <BoxIcon className={cls} />;
|
||||
if (ext === "json") return <FileJsonIcon className={cls} />;
|
||||
if (["md", "txt"].includes(ext)) return <FileTextIcon className={cls} />;
|
||||
if (["png", "jpg", "jpeg", "gif", "webp", "svg"].includes(ext)) return <FileImageIcon className={cls} />;
|
||||
return <FileIcon className={cls} />;
|
||||
}
|
||||
|
||||
function FileName({ path }: { path: string }) {
|
||||
const slash = path.lastIndexOf("/");
|
||||
return (
|
||||
<span className="min-w-0 truncate font-mono text-[13px]" title={path}>
|
||||
{slash >= 0 && <span className="text-muted-foreground">{path.slice(0, slash + 1)}</span>}
|
||||
{path.slice(slash + 1)}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
function Row({ file, href, muted, showState }: { file: FileRow; href: string; muted?: boolean; showState: boolean }) {
|
||||
const state = STATE[file.state];
|
||||
return (
|
||||
<li>
|
||||
<a
|
||||
href={href}
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
className={cn(
|
||||
// Fixed status column so sizes line up between selected and unselected rows.
|
||||
"grid grid-cols-[1rem_minmax(0,1fr)_auto] items-center gap-x-3 px-5 py-2.5 transition-colors hover:bg-muted/50 sm:grid-cols-[1rem_minmax(0,1fr)_5rem_1rem] md:grid-cols-[1rem_minmax(0,1fr)_5rem_7.5rem]",
|
||||
muted && "text-muted-foreground",
|
||||
)}
|
||||
>
|
||||
<FileTypeIcon path={file.path} />
|
||||
<span className="flex min-w-0 items-center gap-2">
|
||||
<FileName path={file.path} />
|
||||
{file.lfsSha256 && (
|
||||
<span className="shrink-0 rounded border px-1 text-[10px] leading-4 text-muted-foreground">LFS</span>
|
||||
)}
|
||||
</span>
|
||||
<span className="hidden text-right text-sm tabular-nums sm:block">{formatBytes(file.size)}</span>
|
||||
{showState ? (
|
||||
<span className={cn("flex items-center justify-end gap-1.5 text-xs whitespace-nowrap", state.className)}>
|
||||
{state.icon}
|
||||
<span className="hidden md:inline">{state.label}</span>
|
||||
</span>
|
||||
) : (
|
||||
<span className="text-right text-sm tabular-nums sm:hidden">{formatBytes(file.size)}</span>
|
||||
)}
|
||||
</a>
|
||||
</li>
|
||||
);
|
||||
}
|
||||
|
||||
/** "Files and versions"-style list: selected files with their local state, the rest collapsed. */
|
||||
export function FilesTab({
|
||||
repoId,
|
||||
sha,
|
||||
selected,
|
||||
others,
|
||||
}: {
|
||||
repoId: string;
|
||||
sha: string;
|
||||
selected: FileRow[];
|
||||
others: FileRow[];
|
||||
}) {
|
||||
const blob = (path: string) => `https://huggingface.co/${repoId}/blob/${sha}/${path}`;
|
||||
const totalBytes = selected.reduce((s, f) => s + f.size, 0);
|
||||
const local = selected.filter((f) => f.state === "present" || f.state === "verified");
|
||||
const localBytes = local.reduce((s, f) => s + f.size, 0);
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className="flex flex-col gap-2 px-5 py-4">
|
||||
<div className="flex flex-wrap items-baseline justify-between gap-x-4 gap-y-1 text-sm">
|
||||
<span>
|
||||
<span className="font-medium">{selected.length} selected file{selected.length === 1 ? "" : "s"}</span>
|
||||
<span className="text-muted-foreground"> · {formatBytes(totalBytes)} · commit {shortSha(sha)}</span>
|
||||
</span>
|
||||
<span className="text-muted-foreground">
|
||||
{local.length} of {selected.length} on disk · {formatBytes(localBytes)}
|
||||
</span>
|
||||
</div>
|
||||
<Progress value={percent(localBytes, totalBytes)} />
|
||||
</div>
|
||||
|
||||
<ul className="divide-y border-t">
|
||||
{selected.map((f) => (
|
||||
<Row key={f.id} file={f} href={blob(f.path)} showState />
|
||||
))}
|
||||
</ul>
|
||||
|
||||
{others.length > 0 && (
|
||||
<details className="group border-t">
|
||||
<summary className="flex cursor-pointer list-none items-center gap-2 px-5 py-3 text-sm hover:bg-muted/50">
|
||||
<ChevronRightIcon className="size-4 text-muted-foreground transition-transform group-open:rotate-90" />
|
||||
<span className="font-medium">Not selected</span>
|
||||
<span className="text-muted-foreground">
|
||||
{others.length} file{others.length === 1 ? "" : "s"} · {formatBytes(others.reduce((s, f) => s + f.size, 0))}
|
||||
</span>
|
||||
</summary>
|
||||
<ul className="divide-y border-t">
|
||||
{others.map((f) => (
|
||||
<Row key={f.id} file={f} href={blob(f.path)} muted showState={false} />
|
||||
))}
|
||||
</ul>
|
||||
</details>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user