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.

feat(models): bulk re-identify from the library selection bar

joshistoastd2f21fa98e25
diff --git a/invokeai/frontend/webv2/public/locales/en.json b/invokeai/frontend/webv2/public/locales/en.json
index 602b22be3b..2acdce91b1 100644
--- a/invokeai/frontend/webv2/public/locales/en.json
+++ b/invokeai/frontend/webv2/public/locales/en.json
@@ -830,6 +830,13 @@
"bulkDeleteConfirm_other": "Delete {{count}} Models",
"bulkDeleteFailed": "Bulk delete failed",
"bulkDeletePartialDescription": "{{deleted}} deleted; {{failed}} failed: {{error}}",
+ "bulkReidentifyBody_one": "Re-probe {{count}} selected model to re-detect its base, type, and format? Custom variants and default settings on it are reset.",
+ "bulkReidentifyBody_other": "Re-probe {{count}} selected models to re-detect their base, type, and format? Custom variants and default settings on them are reset.",
+ "bulkReidentifyConfirm_one": "Re-identify {{count}} Model",
+ "bulkReidentifyConfirm_other": "Re-identify {{count}} Models",
+ "bulkReidentifyFailed": "Bulk re-identify failed",
+ "bulkReidentifyPartialDescription": "{{succeeded}} re-identified; {{failed}} failed: {{error}}",
+ "bulkReidentifyTitle": "Re-identify selected models",
"bundleInstallQueued": "Bundle install queued",
"bundleInstallQueuedDescription_one": "{{name}}: {{count}} install queued.",
"bundleInstallQueuedDescription_other": "{{name}}: {{count}} installs queued.",
@@ -1042,8 +1049,12 @@
"queueActionPartialDescription": "{{failed}} of {{total}} failed: {{error}}",
"refreshFailed": "Failed to refresh models",
"refreshList": "Refresh model list",
+ "reidentified": "Models re-identified",
+ "reidentifiedDescription_one": "{{count}} model re-probed and updated.",
+ "reidentifiedDescription_other": "{{count}} models re-probed and updated.",
"reidentify": "Re-identify model",
"reidentifyFailed": "Re-identify failed",
+ "reidentifySelected": "Re-identify",
"relatedModels": "Related Models",
"relatedModelsHelp": "Link the models that pair well with this one - they are suggested together elsewhere in the app.",
"removeImage": "Remove image",
@@ -1088,6 +1099,7 @@
"selectedCount_one": "{{count}} selected",
"selectedCount_other": "{{count}} selected",
"someCouldNotBeDeleted": "Some models could not be deleted",
+ "someCouldNotBeReidentified": "Some models could not be re-identified",
"sort": {
"base": "Base",
"default": "Default",
diff --git a/invokeai/frontend/webv2/src/features/models/core/types.ts b/invokeai/frontend/webv2/src/features/models/core/types.ts
index 125aad8fd3..9c2269a8e3 100644
--- a/invokeai/frontend/webv2/src/features/models/core/types.ts
+++ b/invokeai/frontend/webv2/src/features/models/core/types.ts
@@ -252,6 +252,11 @@ export interface BulkDeleteModelsResponse {
failed: { key: string; error: string }[];
}
+export interface BulkReidentifyModelsResponse {
+ succeeded: string[];
+ failed: { key: string; error: string }[];
+}
+
export interface DeleteOrphanedModelsResponse {
deleted: string[];
errors: Record<string, string>;
diff --git a/invokeai/frontend/webv2/src/features/models/data/api.test.ts b/invokeai/frontend/webv2/src/features/models/data/api.test.ts
index 95364f9235..7471c32529 100644
--- a/invokeai/frontend/webv2/src/features/models/data/api.test.ts
+++ b/invokeai/frontend/webv2/src/features/models/data/api.test.ts
@@ -111,3 +111,21 @@ describe('account-owned model requests', () => {
);
});
});
+
+describe('bulkReidentifyModels', () => {
+ it('POSTs the key list as JSON and forwards the abort signal', async () => {
+ mocks.apiFetchJson.mockReset().mockResolvedValue({ failed: [], succeeded: ['a', 'b'] });
+ const { bulkReidentifyModels } = await import('./api');
+ const controller = new AbortController();
+
+ const result = await bulkReidentifyModels(['a', 'b'], controller.signal);
+
+ expect(mocks.apiFetchJson).toHaveBeenCalledWith('/api/v2/models/i/bulk_reidentify', {
+ body: JSON.stringify({ keys: ['a', 'b'] }),
+ headers: { 'Content-Type': 'application/json' },
+ method: 'POST',
+ signal: controller.signal,
+ });
+ expect(result).toEqual({ failed: [], succeeded: ['a', 'b'] });
+ });
+});
diff --git a/invokeai/frontend/webv2/src/features/models/data/api.ts b/invokeai/frontend/webv2/src/features/models/data/api.ts
index 886ff19e97..59bf5eeafe 100644
--- a/invokeai/frontend/webv2/src/features/models/data/api.ts
+++ b/invokeai/frontend/webv2/src/features/models/data/api.ts
@@ -1,5 +1,6 @@
import type {
BulkDeleteModelsResponse,
+ BulkReidentifyModelsResponse,
DeleteOrphanedModelsResponse,
FoundModel,
HFTokenStatus,
@@ -58,6 +59,15 @@ export const bulkDeleteModels = (keys: string[], signal?: AbortSignal): Promise<
export const reidentifyModel = (key: string, signal?: AbortSignal): Promise<ModelConfig> =>
requestJson<ModelConfig>(`${MODELS_BASE}/i/${encodeURIComponent(key)}/reidentify`, { method: 'POST', signal });
+/** Re-probe many models; returns keys only, so callers must refresh the library for the new configs. */
+export const bulkReidentifyModels = (keys: string[], signal?: AbortSignal): Promise<BulkReidentifyModelsResponse> =>
+ requestJson<BulkReidentifyModelsResponse>(`${MODELS_BASE}/i/bulk_reidentify`, {
+ body: JSON.stringify({ keys }),
+ headers: { 'Content-Type': 'application/json' },
+ method: 'POST',
+ signal,
+ });
+
export const convertModelToDiffusers = (key: string, signal?: AbortSignal): Promise<ModelConfig> =>
requestJson<ModelConfig>(`${MODELS_BASE}/convert/${encodeURIComponent(key)}`, { method: 'PUT', signal });
diff --git a/invokeai/frontend/webv2/src/features/models/ui/manager/LibraryColumn.tsx b/invokeai/frontend/webv2/src/features/models/ui/manager/LibraryColumn.tsx
index e7fa2cbcfe..49204bafb8 100644
--- a/invokeai/frontend/webv2/src/features/models/ui/manager/LibraryColumn.tsx
+++ b/invokeai/frontend/webv2/src/features/models/ui/manager/LibraryColumn.tsx
@@ -1,7 +1,7 @@
/* eslint-disable react-perf/jsx-no-jsx-as-prop, react-perf/jsx-no-new-array-as-prop, react-perf/jsx-no-new-function-as-prop, react-perf/jsx-no-new-object-as-prop */
import { Box, Flex, HStack, Icon, Separator, Text } from '@chakra-ui/react';
import { collectBases, collectTypes, filterModels } from '@features/models/core/library';
-import { bulkDeleteModels } from '@features/models/data/api';
+import { bulkDeleteModels, bulkReidentifyModels } from '@features/models/data/api';
import { refreshModels, removeModelsFromStore, useModelsSelector } from '@features/models/data/modelsStore';
import { removeModelsFromRelationships } from '@features/models/data/relationshipsStore';
import { refreshStartersIfLoaded } from '@features/models/data/startersStore';
@@ -19,7 +19,7 @@ import {
import { useNotify } from '@features/models/ui/useModelsNotify';
import { assertAccountScopeCurrent } from '@platform/state/accountLifecycle';
import { Button, IconButton, ConfirmDialog } from '@platform/ui';
-import { Trash2Icon, XIcon } from 'lucide-react';
+import { RefreshCcwIcon, Trash2Icon, XIcon } from 'lucide-react';
import { useCallback, useMemo, useState } from 'react';
import { useTranslation } from 'react-i18next';
@@ -44,7 +44,11 @@ export const LibraryColumn = () => {
left.selectedKeys === right.selectedKeys
);
const [isBulkDeleteOpen, setIsBulkDeleteOpen] = useState(false);
+ const [isBulkReidentifyOpen, setIsBulkReidentifyOpen] = useState(false);
+ // Separate instances: run ignores re-entry, so sharing one would let a slow
+ // re-identify swallow a delete.
const { run } = useScopedAction();
+ const { run: runReidentify } = useScopedAction();
const availableTypes = useMemo(() => collectTypes(models), [models]);
const availableBases = useMemo(() => collectBases(models), [models]);
@@ -105,6 +109,40 @@ export const LibraryColumn = () => {
);
};
+ const handleBulkReidentify = async () => {
+ const keys = [...selectedKeys];
+
+ await runReidentify(
+ async (owner) => {
+ const result = await bulkReidentifyModels(keys, owner.signal);
+
+ assertAccountScopeCurrent(owner);
+ // The endpoint returns keys only; the refreshed library carries the
+ // re-detected configs.
+ await refreshModels(owner);
+ assertAccountScopeCurrent(owner);
+ updateModelsUi({ selectedKeys: new Set(result.failed.map((failure) => failure.key)) });
+
+ if (result.failed.length > 0) {
+ notify.error(
+ t('models.someCouldNotBeReidentified'),
+ t('models.bulkReidentifyPartialDescription', {
+ error: result.failed[0]?.error ?? '',
+ failed: result.failed.length,
+ succeeded: result.succeeded.length,
+ })
+ );
+ } else {
+ notify.success(
+ t('models.reidentified'),
+ t('models.reidentifiedDescription', { count: result.succeeded.length })
+ );
+ }
+ },
+ (message) => notify.error(t('models.bulkReidentifyFailed'), message)
+ );
+ };
+
return (
<Flex direction="column" flexShrink={0} h="full" minH="0" position="relative" w={LIBRARY_WIDTH} borderEndWidth={1}>
<HStack align="center" borderBottomWidth={1} flexShrink={0} gap="2" minH={HEADER_MIN_HEIGHT} px="3">
@@ -169,6 +207,10 @@ export const LibraryColumn = () => {
{t('models.selectAllCount', { count: filteredKeys.length })}
</Button>
) : null}
+ <Button size="2xs" variant="outline" onClick={() => setIsBulkReidentifyOpen(true)}>
+ <Icon as={RefreshCcwIcon} boxSize="3" />
+ {t('models.reidentifySelected')}
+ </Button>
<Button colorPalette="red" size="2xs" variant="solid" onClick={() => setIsBulkDeleteOpen(true)}>
<Icon as={Trash2Icon} boxSize="3" />
{t('common.delete')}
@@ -193,6 +235,15 @@ export const LibraryColumn = () => {
onClose={() => setIsBulkDeleteOpen(false)}
onConfirm={handleBulkDelete}
/>
+ <ConfirmDialog
+ body={t('models.bulkReidentifyBody', { count: selectedKeys.size })}
+ confirmLabel={t('models.bulkReidentifyConfirm', { count: selectedKeys.size })}
+ isDestructive={false}
+ isOpen={isBulkReidentifyOpen}
+ title={t('models.bulkReidentifyTitle')}
+ onClose={() => setIsBulkReidentifyOpen(false)}
+ onConfirm={handleBulkReidentify}
+ />
</Flex>
);
};