Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.
TypeScript ai-artartificial-intelligencegenerative-artimage-generationimg2imginpaintinglatent-diffusionlinuxmacosoutpaintingstable-diffusiontxt2imgwindows
fix(ui): stop classifying relative paths as HF repos
joshistoast51c55ce748e8
diff --git a/invokeai/frontend/webv2/src/features/models/ui/add-models/sourceClassifier.test.ts b/invokeai/frontend/webv2/src/features/models/ui/add-models/sourceClassifier.test.tsindex 9ac3e8520e..54b4d35853 100644--- a/invokeai/frontend/webv2/src/features/models/ui/add-models/sourceClassifier.test.ts+++ b/invokeai/frontend/webv2/src/features/models/ui/add-models/sourceClassifier.test.ts@@ -21,6 +21,7 @@ describe('classifySource', () => {'owner/repo:fp16','owner/repo:fp16:path/to/file.safetensors','owner.name/repo-name',+ 'stabilityai/stable-diffusion-2.1',])('classifies %s as a HuggingFace repo', (value) => {expect(classifySource(value)).toMatchObject({isInstallable: true,@@ -47,4 +48,17 @@ describe('classifySource', () => {it.each(['juggernaut', 'flux dev', 'owner/repo with spaces', ''])('treats %j as a search term', (value) => {expect(classifySource(value)).toMatchObject({ isInstallable: false, labelKey: null, localKind: null });});++ // Relative paths satisfy the repo shape but are not installable sources.+ it.each(['models/juggernaut.safetensors', 'checkpoints/model.ckpt', './owner/repo', '../models/foo.gguf'])(+ 'treats the relative path %s as a search term, not a repo',+ (value) => {+ expect(classifySource(value)).toMatchObject({+ isInstallable: false,+ labelKey: null,+ localKind: null,+ looksRepo: false,+ });+ }+ );});diff --git a/invokeai/frontend/webv2/src/features/models/ui/add-models/sourceClassifier.ts b/invokeai/frontend/webv2/src/features/models/ui/add-models/sourceClassifier.tsindex 8d4129b5ec..9450729449 100644--- a/invokeai/frontend/webv2/src/features/models/ui/add-models/sourceClassifier.ts+++ b/invokeai/frontend/webv2/src/features/models/ui/add-models/sourceClassifier.ts@@ -2,6 +2,13 @@const HF_REPO_PATTERN = /^[\w.-]+\/[\w.-]+(:[\w./-]*)*$/;// 12 covers the longest real model extension, ".safetensors" (11 letters).const FILE_EXTENSION_PATTERN = /\.[A-Za-z0-9]{1,12}$/;+/**+ * Extensions that mark a relative path as a model file rather than an HF repo+ * id. Deliberately narrower than FILE_EXTENSION_PATTERN: real repo ids end in+ * dot-suffixes too ("stabilityai/stable-diffusion-2.1").+ */+const MODEL_FILE_EXTENSION_PATTERN = /\.(safetensors|ckpt|pt|pth|bin|gguf|onnx|pkl)$/i;+const RELATIVE_PATH_PATTERN = /^\.{1,2}[\\/]/;export interface SourceKind {looksLocal: boolean;@@ -27,7 +34,13 @@ const classifyLocalPath = (value: string): 'file' | 'folder' => {export const classifySource = (value: string): SourceKind => {const looksLocal = value.startsWith('/') || /^[A-Za-z]:[\\/]/.test(value);const looksUrl = /^https?:\/\//i.test(value);- const looksRepo = !looksLocal && !looksUrl && HF_REPO_PATTERN.test(value);+ // "models/foo.safetensors" and "./repo" satisfy the HF repo shape but are+ // clearly path-like; they fall through to search, since a relative path is+ // not an installable source. The extension check runs on the pre-colon+ // portion so "owner/repo:fp16:path/file.safetensors" stays a repo.+ const looksRelativePath =+ RELATIVE_PATH_PATTERN.test(value) || MODEL_FILE_EXTENSION_PATTERN.test(value.split(':', 1)[0] ?? '');+ const looksRepo = !looksLocal && !looksUrl && !looksRelativePath && HF_REPO_PATTERN.test(value);const isInstallable = looksLocal || looksUrl || looksRepo;const localKind = looksLocal ? classifyLocalPath(value) : null;