mirror of
https://github.com/invoke-ai/InvokeAI.git
synced 2026-04-23 03:00:31 -04:00
tidy(ui): revert changes to old CA implementation
These changes were left over from the previous attempt to handle control adapters in control layers with the same logic. Control Layers are now handled totally separately, so these changes may be reverted.
This commit is contained in:
committed by
Kent Keirsey
parent
33a9f9a4dc
commit
b1d8f3a3f9
@@ -7,7 +7,7 @@ import { buildControlAdapter } from 'features/controlAdapters/util/buildControlA
|
||||
import { buildControlAdapterProcessor } from 'features/controlAdapters/util/buildControlAdapterProcessor';
|
||||
import { zModelIdentifierField } from 'features/nodes/types/common';
|
||||
import { merge, uniq } from 'lodash-es';
|
||||
import type { ControlNetModelConfig, ImageDTO, IPAdapterModelConfig, T2IAdapterModelConfig } from 'services/api/types';
|
||||
import type { ControlNetModelConfig, IPAdapterModelConfig, T2IAdapterModelConfig } from 'services/api/types';
|
||||
import { socketInvocationError } from 'services/events/actions';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
|
||||
@@ -134,46 +134,23 @@ export const controlAdaptersSlice = createSlice({
|
||||
const { id, isEnabled } = action.payload;
|
||||
caAdapter.updateOne(state, { id, changes: { isEnabled } });
|
||||
},
|
||||
controlAdapterImageChanged: (state, action: PayloadAction<{ id: string; controlImage: ImageDTO | null }>) => {
|
||||
controlAdapterImageChanged: (
|
||||
state,
|
||||
action: PayloadAction<{
|
||||
id: string;
|
||||
controlImage: string | null;
|
||||
}>
|
||||
) => {
|
||||
const { id, controlImage } = action.payload;
|
||||
const ca = selectControlAdapterById(state, id);
|
||||
if (!ca) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isControlNetOrT2IAdapter(ca)) {
|
||||
if (controlImage) {
|
||||
const { image_name, width, height } = controlImage;
|
||||
const processorNode = deepClone(ca.processorNode);
|
||||
const minDim = Math.min(controlImage.width, controlImage.height);
|
||||
if ('detect_resolution' in processorNode) {
|
||||
processorNode.detect_resolution = minDim;
|
||||
}
|
||||
if ('image_resolution' in processorNode) {
|
||||
processorNode.image_resolution = minDim;
|
||||
}
|
||||
if ('resolution' in processorNode) {
|
||||
processorNode.resolution = minDim;
|
||||
}
|
||||
caAdapter.updateOne(state, {
|
||||
id,
|
||||
changes: {
|
||||
processorNode,
|
||||
controlImage: image_name,
|
||||
controlImageDimensions: { width, height },
|
||||
processedControlImage: null,
|
||||
},
|
||||
});
|
||||
} else {
|
||||
caAdapter.updateOne(state, {
|
||||
id,
|
||||
changes: { controlImage: null, controlImageDimensions: null, processedControlImage: null },
|
||||
});
|
||||
}
|
||||
} else {
|
||||
// ip adapter
|
||||
caAdapter.updateOne(state, { id, changes: { controlImage: controlImage?.image_name ?? null } });
|
||||
}
|
||||
caAdapter.updateOne(state, {
|
||||
id,
|
||||
changes: { controlImage, processedControlImage: null },
|
||||
});
|
||||
|
||||
if (controlImage !== null && isControlNetOrT2IAdapter(ca) && ca.processorType !== 'none') {
|
||||
state.pendingControlImages.push(id);
|
||||
@@ -183,7 +160,7 @@ export const controlAdaptersSlice = createSlice({
|
||||
state,
|
||||
action: PayloadAction<{
|
||||
id: string;
|
||||
processedControlImage: ImageDTO | null;
|
||||
processedControlImage: string | null;
|
||||
}>
|
||||
) => {
|
||||
const { id, processedControlImage } = action.payload;
|
||||
@@ -196,24 +173,12 @@ export const controlAdaptersSlice = createSlice({
|
||||
return;
|
||||
}
|
||||
|
||||
if (processedControlImage) {
|
||||
const { image_name, width, height } = processedControlImage;
|
||||
caAdapter.updateOne(state, {
|
||||
id,
|
||||
changes: {
|
||||
processedControlImage: image_name,
|
||||
processedControlImageDimensions: { width, height },
|
||||
},
|
||||
});
|
||||
} else {
|
||||
caAdapter.updateOne(state, {
|
||||
id,
|
||||
changes: {
|
||||
processedControlImage: null,
|
||||
processedControlImageDimensions: null,
|
||||
},
|
||||
});
|
||||
}
|
||||
caAdapter.updateOne(state, {
|
||||
id,
|
||||
changes: {
|
||||
processedControlImage,
|
||||
},
|
||||
});
|
||||
|
||||
state.pendingControlImages = state.pendingControlImages.filter((pendingId) => pendingId !== id);
|
||||
},
|
||||
@@ -227,7 +192,7 @@ export const controlAdaptersSlice = createSlice({
|
||||
state,
|
||||
action: PayloadAction<{
|
||||
id: string;
|
||||
modelConfig: ControlNetModelConfig | T2IAdapterModelConfig | IPAdapterModelConfig | null;
|
||||
modelConfig: ControlNetModelConfig | T2IAdapterModelConfig | IPAdapterModelConfig;
|
||||
}>
|
||||
) => {
|
||||
const { id, modelConfig } = action.payload;
|
||||
@@ -236,11 +201,6 @@ export const controlAdaptersSlice = createSlice({
|
||||
return;
|
||||
}
|
||||
|
||||
if (modelConfig === null) {
|
||||
caAdapter.updateOne(state, { id, changes: { model: null } });
|
||||
return;
|
||||
}
|
||||
|
||||
const model = zModelIdentifierField.parse(modelConfig);
|
||||
|
||||
if (!isControlNetOrT2IAdapter(cn)) {
|
||||
@@ -248,36 +208,22 @@ export const controlAdaptersSlice = createSlice({
|
||||
return;
|
||||
}
|
||||
|
||||
const update: Update<ControlNetConfig | T2IAdapterConfig, string> = {
|
||||
id,
|
||||
changes: { model, shouldAutoConfig: true },
|
||||
};
|
||||
|
||||
update.changes.processedControlImage = null;
|
||||
|
||||
if (modelConfig.type === 'ip_adapter') {
|
||||
// should never happen...
|
||||
return;
|
||||
}
|
||||
|
||||
// We always update the model
|
||||
const update: Update<ControlNetConfig | T2IAdapterConfig, string> = { id, changes: { model } };
|
||||
|
||||
// Build the default processor for this model
|
||||
const processor = buildControlAdapterProcessor(modelConfig);
|
||||
if (processor.processorType !== cn.processorNode.type) {
|
||||
// If the processor type has changed, update the processor node
|
||||
update.changes.shouldAutoConfig = true;
|
||||
update.changes.processedControlImage = null;
|
||||
update.changes.processorType = processor.processorType;
|
||||
update.changes.processorNode = processor.processorNode;
|
||||
update.changes.processorType = processor.processorType;
|
||||
update.changes.processorNode = processor.processorNode;
|
||||
|
||||
if (cn.controlImageDimensions) {
|
||||
const minDim = Math.min(cn.controlImageDimensions.width, cn.controlImageDimensions.height);
|
||||
if ('detect_resolution' in update.changes.processorNode) {
|
||||
update.changes.processorNode.detect_resolution = minDim;
|
||||
}
|
||||
if ('image_resolution' in update.changes.processorNode) {
|
||||
update.changes.processorNode.image_resolution = minDim;
|
||||
}
|
||||
if ('resolution' in update.changes.processorNode) {
|
||||
update.changes.processorNode.resolution = minDim;
|
||||
}
|
||||
}
|
||||
}
|
||||
caAdapter.updateOne(state, update);
|
||||
},
|
||||
controlAdapterWeightChanged: (state, action: PayloadAction<{ id: string; weight: number }>) => {
|
||||
@@ -394,23 +340,8 @@ export const controlAdaptersSlice = createSlice({
|
||||
|
||||
if (update.changes.shouldAutoConfig && modelConfig) {
|
||||
const processor = buildControlAdapterProcessor(modelConfig);
|
||||
if (processor.processorType !== cn.processorNode.type) {
|
||||
update.changes.processorType = processor.processorType;
|
||||
update.changes.processorNode = processor.processorNode;
|
||||
// Copy image resolution settings, urgh
|
||||
if (cn.controlImageDimensions) {
|
||||
const minDim = Math.min(cn.controlImageDimensions.width, cn.controlImageDimensions.height);
|
||||
if ('detect_resolution' in update.changes.processorNode) {
|
||||
update.changes.processorNode.detect_resolution = minDim;
|
||||
}
|
||||
if ('image_resolution' in update.changes.processorNode) {
|
||||
update.changes.processorNode.image_resolution = minDim;
|
||||
}
|
||||
if ('resolution' in update.changes.processorNode) {
|
||||
update.changes.processorNode.resolution = minDim;
|
||||
}
|
||||
}
|
||||
}
|
||||
update.changes.processorType = processor.processorType;
|
||||
update.changes.processorNode = processor.processorNode;
|
||||
}
|
||||
|
||||
caAdapter.updateOne(state, update);
|
||||
|
||||
@@ -225,9 +225,7 @@ export type ControlNetConfig = {
|
||||
controlMode: ControlMode;
|
||||
resizeMode: ResizeMode;
|
||||
controlImage: string | null;
|
||||
controlImageDimensions: { width: number; height: number } | null;
|
||||
processedControlImage: string | null;
|
||||
processedControlImageDimensions: { width: number; height: number } | null;
|
||||
processorType: ControlAdapterProcessorType;
|
||||
processorNode: RequiredControlAdapterProcessorNode;
|
||||
shouldAutoConfig: boolean;
|
||||
@@ -243,9 +241,7 @@ export type T2IAdapterConfig = {
|
||||
endStepPct: number;
|
||||
resizeMode: ResizeMode;
|
||||
controlImage: string | null;
|
||||
controlImageDimensions: { width: number; height: number } | null;
|
||||
processedControlImage: string | null;
|
||||
processedControlImageDimensions: { width: number; height: number } | null;
|
||||
processorType: ControlAdapterProcessorType;
|
||||
processorNode: RequiredControlAdapterProcessorNode;
|
||||
shouldAutoConfig: boolean;
|
||||
|
||||
Reference in New Issue
Block a user