diff --git a/CHANGELOG.md b/CHANGELOG.md index 316697d..7003bdf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,13 +8,17 @@ step 1 (Hugging Face downloader) is released as a minor version. ### Added -- Model pages modeled on Hugging Face: org avatar, `org / name` with copy button, pills for task, - format, architecture, language and license, your tags, buttons to the repo on Hugging Face - (files at the pinned commit, commits, community, base model), and tabs: +- Model pages modeled on Hugging Face, built from cards: a header with org avatar, `org / name` + with copy button, pills for task, format, architecture, language and license, your tags and a + Hugging Face link; a content card with tabs: + - **Files** (default): selected files with type icon, size, LFS marker and local state + (downloaded, missing, size mismatch, …), a "on disk" progress summary, and the unselected repo + files collapsed below; each file links to the Hub at the pinned commit - **Model card**: the repo's README at the pinned commit, rendered (sanitized HTML, relative links/images resolved to the Hub) - - **Files**: selected files with local state and links, plus the other files in the repo - **Jobs**: download history +- Custom tags are color-coded (color derived from the name, the same everywhere). +- App icon (要). - Sidebar with download status/actions, local copy details (commit, path, patterns) and a model tree (base model → quantized/finetuned → this repo) listing other local models of the same base. - Hub metadata now includes the author's avatar and the relation to the base model; existing models diff --git a/src/app/(app)/[org]/[repo]/files-tab.tsx b/src/app/(app)/[org]/[repo]/files-tab.tsx new file mode 100644 index 0000000..259e649 --- /dev/null +++ b/src/app/(app)/[org]/[repo]/files-tab.tsx @@ -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 = { + pending: { label: "Not downloaded", icon: , className: "text-muted-foreground" }, + present: { label: "Downloaded", icon: , className: "text-emerald-600 dark:text-emerald-400" }, + verified: { label: "Verified", icon: , className: "text-emerald-600 dark:text-emerald-400" }, + missing: { label: "Missing", icon: , className: "text-destructive" }, + size_mismatch: { label: "Size mismatch", icon: , className: "text-amber-600 dark:text-amber-400" }, + hash_mismatch: { label: "Hash mismatch", icon: , 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 ; + if (ext === "json") return ; + if (["md", "txt"].includes(ext)) return ; + if (["png", "jpg", "jpeg", "gif", "webp", "svg"].includes(ext)) return ; + return ; +} + +function FileName({ path }: { path: string }) { + const slash = path.lastIndexOf("/"); + return ( + + {slash >= 0 && {path.slice(0, slash + 1)}} + {path.slice(slash + 1)} + + ); +} + +function Row({ file, href, muted, showState }: { file: FileRow; href: string; muted?: boolean; showState: boolean }) { + const state = STATE[file.state]; + return ( +
  • + + + + + {file.lfsSha256 && ( + LFS + )} + + {formatBytes(file.size)} + {showState ? ( + + {state.icon} + {state.label} + + ) : ( + {formatBytes(file.size)} + )} + +
  • + ); +} + +/** "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 ( +
    +
    +
    + + {selected.length} selected file{selected.length === 1 ? "" : "s"} + · {formatBytes(totalBytes)} · commit {shortSha(sha)} + + + {local.length} of {selected.length} on disk · {formatBytes(localBytes)} + +
    + +
    + +
      + {selected.map((f) => ( + + ))} +
    + + {others.length > 0 && ( +
    + + + Not selected + + {others.length} file{others.length === 1 ? "" : "s"} · {formatBytes(others.reduce((s, f) => s + f.size, 0))} + + +
      + {others.map((f) => ( + + ))} +
    +
    + )} +
    + ); +} diff --git a/src/app/(app)/[org]/[repo]/page.tsx b/src/app/(app)/[org]/[repo]/page.tsx index 99ae9df..484ac56 100644 --- a/src/app/(app)/[org]/[repo]/page.tsx +++ b/src/app/(app)/[org]/[repo]/page.tsx @@ -19,7 +19,6 @@ 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"; @@ -28,6 +27,7 @@ import { getModelByRepo, relatedModels } from "@/lib/library"; import { quantGroup } from "@/lib/selection"; import { modelTagList } from "@/lib/tags"; import { DownloadCard } from "./download-card"; +import { FilesTab } from "./files-tab"; import { JobsTab } from "./jobs-tab"; import { ModelCard } from "./model-card"; import { RemoveModelButton } from "./remove-model-button"; @@ -36,8 +36,8 @@ 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: "card", label: "Model card", icon: FileTextIcon }, { id: "jobs", label: "Jobs", icon: HistoryIcon }, ] as const; type TabId = (typeof TABS)[number]["id"]; @@ -83,7 +83,7 @@ export default async function ModelPage({ params, searchParams }: PageProps<"/[o 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 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 ?? []; @@ -105,7 +105,7 @@ export default async function ModelPage({ params, searchParams }: PageProps<"/[o 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 === "card" ? `/${model.repoId}` : `/${model.repoId}?tab=${id}`); + const tabHref = (id: TabId) => (id === "files" ? `/${model.repoId}` : `/${model.repoId}?tab=${id}`); return (
    @@ -120,11 +120,10 @@ export default async function ModelPage({ params, searchParams }: PageProps<"/[o

    {name}

    - {model.status === "pending" && ( -
    - -
    - )} +
    + {model.status === "pending" && } + 🤗 Hugging Face +
    @@ -153,15 +152,6 @@ export default async function ModelPage({ params, searchParams }: PageProps<"/[o
    -
    - 🤗 Hugging Face - Files @ {shortSha(model.pinnedSha)} - Commits - Community - {baseModels[0] && ( - Base: {baseModels[0]} - )} -
    @@ -187,23 +177,25 @@ export default async function ModelPage({ params, searchParams }: PageProps<"/[o ))} - {tab === "card" && card && ( - - README.md @ {shortSha(model.pinnedSha)} - - - )}
    {tab === "card" && (
    {card ? ( - + <> + + + ) : (

    {card === null ? "This repository has no model card." : "The model card could not be loaded."}{" "} @@ -400,81 +392,3 @@ function ModelTree({ ); } - -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 ( -

    -
    - Selected files - - {selected.length} · {formatBytes(selected.reduce((s, f) => s + f.size, 0))} · at {shortSha(sha)} - -
    -
    - - - - File - Size - Local - - - - {selected.map((f) => ( - - - - {f.path} - - {f.lfsSha256 && LFS} - - {formatBytes(f.size)} - {f.state} - - ))} - -
    -
    - - {others.length > 0 && ( -
    - - Other files in the repo - - {others.length} · {formatBytes(others.reduce((s, f) => s + f.size, 0))} · not downloaded - - Show - Hide - -
    - - - {others.map((f) => ( - - - - {f.path} - - - {formatBytes(f.size)} - - ))} - -
    -
    -
    - )} -
    - ); -} diff --git a/src/app/(app)/[org]/[repo]/tag-editor.tsx b/src/app/(app)/[org]/[repo]/tag-editor.tsx index 08c96be..c4d0453 100644 --- a/src/app/(app)/[org]/[repo]/tag-editor.tsx +++ b/src/app/(app)/[org]/[repo]/tag-editor.tsx @@ -4,7 +4,7 @@ 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 { TagBadge } from "@/components/tag-badge"; import { Input } from "@/components/ui/input"; import type { Tag } from "@/lib/tags"; @@ -51,12 +51,11 @@ export function TagEditor({ modelId, tags }: { modelId: string; tags: Tag[] }) { return (
    {tags.map((t) => ( - - {t.name} - - + ))}
    { diff --git a/src/app/(app)/facet-filter.tsx b/src/app/(app)/facet-filter.tsx index e57cac8..c0efebc 100644 --- a/src/app/(app)/facet-filter.tsx +++ b/src/app/(app)/facet-filter.tsx @@ -16,12 +16,15 @@ export function FacetFilter({ selected, onChange, format = (v) => v, + marker, }: { label: string; values: [string, number][]; selected: string[]; onChange: (next: string[]) => void; format?: (value: string) => string; + /** Optional element before each value, e.g. a tag's color dot. */ + marker?: (value: string) => React.ReactNode; }) { const active = selected.length > 0; return ( @@ -41,6 +44,7 @@ export function FacetFilter({ closeOnClick={false} onCheckedChange={(on) => onChange(on ? [...selected, value] : selected.filter((v) => v !== value))} > + {marker?.(value)} {format(value)} {count} diff --git a/src/app/(app)/library-view.tsx b/src/app/(app)/library-view.tsx index 3880ab4..14d48df 100644 --- a/src/app/(app)/library-view.tsx +++ b/src/app/(app)/library-view.tsx @@ -7,6 +7,7 @@ import { useMemo, useState } from "react"; import { JobProgress, JobStateBadge } from "@/components/job-progress"; import { LocalTime } from "@/components/local-time"; import { MODEL_STATUS, ModelStatusBadge } from "@/components/model-status-badge"; +import { TagBadge, TagDot } from "@/components/tag-badge"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { Card, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"; @@ -122,6 +123,7 @@ export function LibraryView({ rows }: { rows: LibraryRow[] }) { selected={filters[facet]} onChange={(v) => updateFilter(facet, v)} format={facet === "status" ? statusLabel : undefined} + marker={facet === "tag" ? (v) => : undefined} /> ))}
    @@ -134,6 +136,7 @@ export function LibraryView({ rows }: { rows: LibraryRow[] }) { {FACETS.flatMap((facet) => filters[facet].map((v) => ( + {facet === "tag" && } {FACET_LABEL[facet]}: {facet === "status" ? statusLabel(v) : v} ))}
    diff --git a/src/app/icon.svg b/src/app/icon.svg new file mode 100644 index 0000000..55b80b5 --- /dev/null +++ b/src/app/icon.svg @@ -0,0 +1,11 @@ + + + + + + + + + 要 + diff --git a/src/components/tag-badge.tsx b/src/components/tag-badge.tsx new file mode 100644 index 0000000..6c6a131 --- /dev/null +++ b/src/components/tag-badge.tsx @@ -0,0 +1,68 @@ +import { cn } from "@/lib/utils"; + +// Fixed palette (full class strings so Tailwind picks them up). A tag's color is derived from its +// name, so the same tag has the same color everywhere without storing anything. +const PALETTE = [ + "border-sky-500/30 bg-sky-500/10 text-sky-700 dark:text-sky-300", + "border-emerald-500/30 bg-emerald-500/10 text-emerald-700 dark:text-emerald-300", + "border-amber-500/30 bg-amber-500/10 text-amber-700 dark:text-amber-300", + "border-rose-500/30 bg-rose-500/10 text-rose-700 dark:text-rose-300", + "border-violet-500/30 bg-violet-500/10 text-violet-700 dark:text-violet-300", + "border-cyan-500/30 bg-cyan-500/10 text-cyan-700 dark:text-cyan-300", + "border-lime-500/30 bg-lime-500/10 text-lime-700 dark:text-lime-300", + "border-orange-500/30 bg-orange-500/10 text-orange-700 dark:text-orange-300", + "border-fuchsia-500/30 bg-fuchsia-500/10 text-fuchsia-700 dark:text-fuchsia-300", + "border-teal-500/30 bg-teal-500/10 text-teal-700 dark:text-teal-300", +]; + +const DOTS = [ + "bg-sky-500", + "bg-emerald-500", + "bg-amber-500", + "bg-rose-500", + "bg-violet-500", + "bg-cyan-500", + "bg-lime-500", + "bg-orange-500", + "bg-fuchsia-500", + "bg-teal-500", +]; + +function colorIndex(name: string): number { + let h = 0; + for (const ch of name.trim().toLowerCase()) h = (h * 31 + ch.codePointAt(0)!) >>> 0; + return h % PALETTE.length; +} + +export function tagColorClass(name: string): string { + return PALETTE[colorIndex(name)]; +} + +/** Small colored dot for a tag (e.g. in filter menus). */ +export function TagDot({ name }: { name: string }) { + return ; +} + +/** A user tag, colored by its name. */ +export function TagBadge({ + name, + className, + children, +}: { + name: string; + className?: string; + children?: React.ReactNode; +}) { + return ( + + {name} + {children} + + ); +} diff --git a/src/proxy.ts b/src/proxy.ts index 78eee87..0c667f3 100644 --- a/src/proxy.ts +++ b/src/proxy.ts @@ -28,5 +28,5 @@ export async function proxy(req: NextRequest, event: NextFetchEvent) { export const config = { // Everything except the Auth.js endpoints, the login page and static assets. // Exact exclusions only: an org like "loginx" must still go through the gate. - matcher: ["/((?!api/auth/|login$|_next/static/|_next/image/|favicon\\.ico$).*)"], + matcher: ["/((?!api/auth/|login$|_next/static/|_next/image/|favicon\\.ico$|icon\\.svg$).*)"], };