Skip to content

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.

fix(ui): recognize .safetensors paths as files

Josh Corbett93202d6742a9
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.ts
new file mode 100644
index 0000000000..0794b3ef71
--- /dev/null
+++ b/invokeai/frontend/webv2/src/features/models/ui/add-models/sourceClassifier.test.ts
@@ -0,0 +1,36 @@
+import { describe, expect, it } from 'vitest';
+
+import { classifySource } from './sourceClassifier';
+
+describe('classifySource', () => {
+ it.each([
+ ['https://example.com/model.safetensors', 'URL'],
+ ['HTTP://EXAMPLE.COM/model', 'URL'],
+ ['http://civitai.com/api/download/models/12345', 'URL'],
+ ])('classifies %s as a URL', (value, label) => {
+ expect(classifySource(value)).toMatchObject({ isInstallable: true, label, localKind: null, looksUrl: true });
+ });
+
+ it.each([
+ 'black-forest-labs/FLUX.1-dev',
+ 'owner/repo:fp16',
+ 'owner/repo:fp16:path/to/file.safetensors',
+ 'owner.name/repo-name',
+ ])('classifies %s as a HuggingFace repo', (value) => {
+ expect(classifySource(value)).toMatchObject({ isInstallable: true, label: 'Hugging Face repo', looksRepo: true });
+ });
+
+ it.each([
+ ['/models/sdxl.safetensors', 'file'],
+ ['C:\\models\\sdxl.safetensors', 'file'],
+ ['/models/checkpoints/', 'folder'],
+ ['C:/models/checkpoints', 'folder'],
+ ['/models/no-extension', 'folder'],
+ ])('classifies %s as a local %s', (value, localKind) => {
+ expect(classifySource(value)).toMatchObject({ isInstallable: true, localKind, looksLocal: true });
+ });
+
+ it.each(['juggernaut', 'flux dev', 'owner/repo with spaces', ''])('treats %j as a search term', (value) => {
+ expect(classifySource(value)).toMatchObject({ isInstallable: false, label: null, localKind: null });
+ });
+});
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.ts
index 523f52ab00..3c7f2fce8f 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
@@ -1,6 +1,7 @@
/** owner/repo with optional :variant[:path] qualifiers - the HF repo shape. */
const HF_REPO_PATTERN = /^[\w.-]+\/[\w.-]+(:[\w./-]*)*$/;
-const FILE_EXTENSION_PATTERN = /\.[A-Za-z0-9]{1,10}$/;
+// 12 covers the longest real model extension, ".safetensors" (11 letters).
+const FILE_EXTENSION_PATTERN = /\.[A-Za-z0-9]{1,12}$/;
export interface SourceKind {
looksLocal: boolean;