fix(ui): do not re-process if processor config hasn't changed

This commit is contained in:
psychedelicious 2024-05-02 08:27:16 +10:00 committed by Kent Keirsey
parent 47ee08db91
commit ca1c3c0873
2 changed files with 22 additions and 18 deletions

View File

@ -14,6 +14,7 @@ import { CONTROLNET_PROCESSORS } from 'features/controlLayers/util/controlAdapte
import { isImageOutput } from 'features/nodes/types/common'; import { isImageOutput } from 'features/nodes/types/common';
import { addToast } from 'features/system/store/systemSlice'; import { addToast } from 'features/system/store/systemSlice';
import { t } from 'i18next'; import { t } from 'i18next';
import { isEqual } from 'lodash-es';
import { imagesApi } from 'services/api/endpoints/images'; import { imagesApi } from 'services/api/endpoints/images';
import { queueApi } from 'services/api/endpoints/queue'; import { queueApi } from 'services/api/endpoints/queue';
import type { BatchConfig, ImageDTO } from 'services/api/types'; import type { BatchConfig, ImageDTO } from 'services/api/types';
@ -27,8 +28,11 @@ const log = logger('session');
export const addControlAdapterPreprocessor = (startAppListening: AppStartListening) => { export const addControlAdapterPreprocessor = (startAppListening: AppStartListening) => {
startAppListening({ startAppListening({
matcher, matcher,
effect: async (action, { dispatch, getState, cancelActiveListeners, delay, take }) => { effect: async (action, { dispatch, getState, getOriginalState, cancelActiveListeners, delay, take }) => {
const { layerId } = action.payload; const { layerId } = action.payload;
const precheckLayerOriginal = getOriginalState()
.controlLayers.present.layers.filter(isControlAdapterLayer)
.find((l) => l.id === layerId);
const precheckLayer = getState() const precheckLayer = getState()
.controlLayers.present.layers.filter(isControlAdapterLayer) .controlLayers.present.layers.filter(isControlAdapterLayer)
.find((l) => l.id === layerId); .find((l) => l.id === layerId);
@ -42,7 +46,9 @@ export const addControlAdapterPreprocessor = (startAppListening: AppStartListeni
// Layer doesn't have a processor config // Layer doesn't have a processor config
!precheckLayer.controlAdapter.processorConfig || !precheckLayer.controlAdapter.processorConfig ||
// Layer is already processing an image // Layer is already processing an image
precheckLayer.controlAdapter.isProcessingImage precheckLayer.controlAdapter.isProcessingImage ||
// Processor config is the same
isEqual(precheckLayerOriginal?.controlAdapter.processorConfig, precheckLayer.controlAdapter.processorConfig)
) { ) {
return; return;
} }

View File

@ -26,7 +26,6 @@ import type {
T2IAdapterModelConfig, T2IAdapterModelConfig,
ZoeDepthImageProcessorInvocation, ZoeDepthImageProcessorInvocation,
} from 'services/api/types'; } from 'services/api/types';
import { v4 as uuidv4 } from 'uuid';
import { z } from 'zod'; import { z } from 'zod';
const zDepthAnythingModelSize = z.enum(['large', 'base', 'small']); const zDepthAnythingModelSize = z.enum(['large', 'base', 'small']);
@ -164,7 +163,6 @@ type ProcessorData<T extends ProcessorType> = {
}; };
const minDim = (image: ImageWithDims): number => Math.min(image.width, image.height); const minDim = (image: ImageWithDims): number => Math.min(image.width, image.height);
const getId = (type: ProcessorType): string => `${type}_${uuidv4()}`;
type CAProcessorsData = { type CAProcessorsData = {
[key in ProcessorType]: ProcessorData<key>; [key in ProcessorType]: ProcessorData<key>;
@ -184,7 +182,7 @@ export const CONTROLNET_PROCESSORS: CAProcessorsData = {
labelTKey: 'controlnet.canny', labelTKey: 'controlnet.canny',
descriptionTKey: 'controlnet.cannyDescription', descriptionTKey: 'controlnet.cannyDescription',
buildDefaults: () => ({ buildDefaults: () => ({
id: getId('canny_image_processor'), id: 'canny_image_processor',
type: 'canny_image_processor', type: 'canny_image_processor',
low_threshold: 100, low_threshold: 100,
high_threshold: 200, high_threshold: 200,
@ -202,7 +200,7 @@ export const CONTROLNET_PROCESSORS: CAProcessorsData = {
labelTKey: 'controlnet.colorMap', labelTKey: 'controlnet.colorMap',
descriptionTKey: 'controlnet.colorMapDescription', descriptionTKey: 'controlnet.colorMapDescription',
buildDefaults: () => ({ buildDefaults: () => ({
id: getId('color_map_image_processor'), id: 'color_map_image_processor',
type: 'color_map_image_processor', type: 'color_map_image_processor',
color_map_tile_size: 64, color_map_tile_size: 64,
}), }),
@ -217,7 +215,7 @@ export const CONTROLNET_PROCESSORS: CAProcessorsData = {
labelTKey: 'controlnet.contentShuffle', labelTKey: 'controlnet.contentShuffle',
descriptionTKey: 'controlnet.contentShuffleDescription', descriptionTKey: 'controlnet.contentShuffleDescription',
buildDefaults: (baseModel) => ({ buildDefaults: (baseModel) => ({
id: getId('content_shuffle_image_processor'), id: 'content_shuffle_image_processor',
type: 'content_shuffle_image_processor', type: 'content_shuffle_image_processor',
h: baseModel === 'sdxl' ? 1024 : 512, h: baseModel === 'sdxl' ? 1024 : 512,
w: baseModel === 'sdxl' ? 1024 : 512, w: baseModel === 'sdxl' ? 1024 : 512,
@ -235,7 +233,7 @@ export const CONTROLNET_PROCESSORS: CAProcessorsData = {
labelTKey: 'controlnet.depthAnything', labelTKey: 'controlnet.depthAnything',
descriptionTKey: 'controlnet.depthAnythingDescription', descriptionTKey: 'controlnet.depthAnythingDescription',
buildDefaults: () => ({ buildDefaults: () => ({
id: getId('depth_anything_image_processor'), id: 'depth_anything_image_processor',
type: 'depth_anything_image_processor', type: 'depth_anything_image_processor',
model_size: 'small', model_size: 'small',
}), }),
@ -250,7 +248,7 @@ export const CONTROLNET_PROCESSORS: CAProcessorsData = {
labelTKey: 'controlnet.hed', labelTKey: 'controlnet.hed',
descriptionTKey: 'controlnet.hedDescription', descriptionTKey: 'controlnet.hedDescription',
buildDefaults: () => ({ buildDefaults: () => ({
id: getId('hed_image_processor'), id: 'hed_image_processor',
type: 'hed_image_processor', type: 'hed_image_processor',
scribble: false, scribble: false,
}), }),
@ -266,7 +264,7 @@ export const CONTROLNET_PROCESSORS: CAProcessorsData = {
labelTKey: 'controlnet.lineartAnime', labelTKey: 'controlnet.lineartAnime',
descriptionTKey: 'controlnet.lineartAnimeDescription', descriptionTKey: 'controlnet.lineartAnimeDescription',
buildDefaults: () => ({ buildDefaults: () => ({
id: getId('lineart_anime_image_processor'), id: 'lineart_anime_image_processor',
type: 'lineart_anime_image_processor', type: 'lineart_anime_image_processor',
}), }),
buildNode: (image, config) => ({ buildNode: (image, config) => ({
@ -281,7 +279,7 @@ export const CONTROLNET_PROCESSORS: CAProcessorsData = {
labelTKey: 'controlnet.lineart', labelTKey: 'controlnet.lineart',
descriptionTKey: 'controlnet.lineartDescription', descriptionTKey: 'controlnet.lineartDescription',
buildDefaults: () => ({ buildDefaults: () => ({
id: getId('lineart_image_processor'), id: 'lineart_image_processor',
type: 'lineart_image_processor', type: 'lineart_image_processor',
coarse: false, coarse: false,
}), }),
@ -297,7 +295,7 @@ export const CONTROLNET_PROCESSORS: CAProcessorsData = {
labelTKey: 'controlnet.mediapipeFace', labelTKey: 'controlnet.mediapipeFace',
descriptionTKey: 'controlnet.mediapipeFaceDescription', descriptionTKey: 'controlnet.mediapipeFaceDescription',
buildDefaults: () => ({ buildDefaults: () => ({
id: getId('mediapipe_face_processor'), id: 'mediapipe_face_processor',
type: 'mediapipe_face_processor', type: 'mediapipe_face_processor',
max_faces: 1, max_faces: 1,
min_confidence: 0.5, min_confidence: 0.5,
@ -314,7 +312,7 @@ export const CONTROLNET_PROCESSORS: CAProcessorsData = {
labelTKey: 'controlnet.depthMidas', labelTKey: 'controlnet.depthMidas',
descriptionTKey: 'controlnet.depthMidasDescription', descriptionTKey: 'controlnet.depthMidasDescription',
buildDefaults: () => ({ buildDefaults: () => ({
id: getId('midas_depth_image_processor'), id: 'midas_depth_image_processor',
type: 'midas_depth_image_processor', type: 'midas_depth_image_processor',
a_mult: 2, a_mult: 2,
bg_th: 0.1, bg_th: 0.1,
@ -331,7 +329,7 @@ export const CONTROLNET_PROCESSORS: CAProcessorsData = {
labelTKey: 'controlnet.mlsd', labelTKey: 'controlnet.mlsd',
descriptionTKey: 'controlnet.mlsdDescription', descriptionTKey: 'controlnet.mlsdDescription',
buildDefaults: () => ({ buildDefaults: () => ({
id: getId('mlsd_image_processor'), id: 'mlsd_image_processor',
type: 'mlsd_image_processor', type: 'mlsd_image_processor',
thr_d: 0.1, thr_d: 0.1,
thr_v: 0.1, thr_v: 0.1,
@ -348,7 +346,7 @@ export const CONTROLNET_PROCESSORS: CAProcessorsData = {
labelTKey: 'controlnet.normalBae', labelTKey: 'controlnet.normalBae',
descriptionTKey: 'controlnet.normalBaeDescription', descriptionTKey: 'controlnet.normalBaeDescription',
buildDefaults: () => ({ buildDefaults: () => ({
id: getId('normalbae_image_processor'), id: 'normalbae_image_processor',
type: 'normalbae_image_processor', type: 'normalbae_image_processor',
}), }),
buildNode: (image, config) => ({ buildNode: (image, config) => ({
@ -363,7 +361,7 @@ export const CONTROLNET_PROCESSORS: CAProcessorsData = {
labelTKey: 'controlnet.dwOpenpose', labelTKey: 'controlnet.dwOpenpose',
descriptionTKey: 'controlnet.dwOpenposeDescription', descriptionTKey: 'controlnet.dwOpenposeDescription',
buildDefaults: () => ({ buildDefaults: () => ({
id: getId('dw_openpose_image_processor'), id: 'dw_openpose_image_processor',
type: 'dw_openpose_image_processor', type: 'dw_openpose_image_processor',
draw_body: true, draw_body: true,
draw_face: false, draw_face: false,
@ -380,7 +378,7 @@ export const CONTROLNET_PROCESSORS: CAProcessorsData = {
labelTKey: 'controlnet.pidi', labelTKey: 'controlnet.pidi',
descriptionTKey: 'controlnet.pidiDescription', descriptionTKey: 'controlnet.pidiDescription',
buildDefaults: () => ({ buildDefaults: () => ({
id: getId('pidi_image_processor'), id: 'pidi_image_processor',
type: 'pidi_image_processor', type: 'pidi_image_processor',
scribble: false, scribble: false,
safe: false, safe: false,
@ -397,7 +395,7 @@ export const CONTROLNET_PROCESSORS: CAProcessorsData = {
labelTKey: 'controlnet.depthZoe', labelTKey: 'controlnet.depthZoe',
descriptionTKey: 'controlnet.depthZoeDescription', descriptionTKey: 'controlnet.depthZoeDescription',
buildDefaults: () => ({ buildDefaults: () => ({
id: getId('zoe_depth_image_processor'), id: 'zoe_depth_image_processor',
type: 'zoe_depth_image_processor', type: 'zoe_depth_image_processor',
}), }),
buildNode: (image, config) => ({ buildNode: (image, config) => ({