refactor(ui): update components & logic to use new unified slice

This commit is contained in:
psychedelicious
2024-06-16 00:08:00 +10:00
parent b1b41a9b0c
commit 8d7de1543b
100 changed files with 176 additions and 727 deletions

View File

@@ -9,7 +9,7 @@ import { getHasMetadata, removeMetadata } from './canvas/metadata';
import { CANVAS_COHERENCE_NOISE, METADATA, NOISE, POSITIVE_CONDITIONING } from './constants';
export const prepareLinearUIBatch = (state: RootState, graph: NonNullableGraph, prepend: boolean): BatchConfig => {
const { iterations, model, shouldRandomizeSeed, seed } = state.generation;
const { iterations, model, shouldRandomizeSeed, seed } = state.canvasV2.params;
const { shouldConcatPrompts } = state.canvasV2;
const { prompts, seedBehaviour } = state.dynamicPrompts;

View File

@@ -17,7 +17,7 @@ export const addControlNetToLinearGraph = async (
const controlNets = selectValidControlNets(state.controlAdapters).filter(
({ model, processedControlImage, processorType, controlImage, isEnabled }) => {
const hasModel = Boolean(model);
const doesBaseMatch = model?.base === state.generation.model?.base;
const doesBaseMatch = model?.base === state.canvasV2.params.model?.base;
const hasControlImage = (processedControlImage && processorType !== 'none') || controlImage;
return isEnabled && hasModel && doesBaseMatch && hasControlImage;

View File

@@ -19,7 +19,7 @@ export const addIPAdapterToLinearGraph = async (
const ipAdapters = selectValidIPAdapters(state.controlAdapters).filter(({ model, controlImage, isEnabled }) => {
const hasModel = Boolean(model);
const doesBaseMatch = model?.base === state.generation.model?.base;
const doesBaseMatch = model?.base === state.canvasV2.params.model?.base;
const hasControlImage = controlImage;
return isEnabled && hasModel && doesBaseMatch && hasControlImage;
});

View File

@@ -34,13 +34,13 @@ export const addSDXLRefinerToGraph = async (
refinerScheduler,
refinerCFGScale,
refinerStart,
} = state.sdxl;
} = state.canvasV2.params;
if (!refinerModel) {
return;
}
const { seamlessXAxis, seamlessYAxis } = state.generation;
const { seamlessXAxis, seamlessYAxis } = state.canvasV2.params;
const { boundingBoxScaleMethod } = state.canvas;
const isUsingScaledDimensions = ['auto', 'manual'].includes(boundingBoxScaleMethod);

View File

@@ -19,7 +19,7 @@ export const addSeamlessToLinearGraph = (
modelLoaderNodeId: string
): void => {
// Remove Existing UNet Connections
const { seamlessXAxis, seamlessYAxis, vae } = state.generation;
const { seamlessXAxis, seamlessYAxis, vae } = state.canvasV2.params;
const isAutoVae = !vae;
graph.nodes[SEAMLESS] = {

View File

@@ -20,7 +20,7 @@ export const addT2IAdaptersToLinearGraph = async (
const t2iAdapters = selectValidT2IAdapters(state.controlAdapters).filter(
({ model, processedControlImage, processorType, controlImage, isEnabled }) => {
const hasModel = Boolean(model);
const doesBaseMatch = model?.base === state.generation.model?.base;
const doesBaseMatch = model?.base === state.canvasV2.params.model?.base;
const hasControlImage = (processedControlImage && processorType !== 'none') || controlImage;
return isEnabled && hasModel && doesBaseMatch && hasControlImage;

View File

@@ -28,9 +28,9 @@ export const addVAEToGraph = async (
graph: NonNullableGraph,
modelLoaderNodeId: string = MAIN_MODEL_LOADER
): Promise<void> => {
const { vae, seamlessXAxis, seamlessYAxis } = state.generation;
const { vae, seamlessXAxis, seamlessYAxis } = state.canvasV2.params;
const { boundingBoxScaleMethod } = state.canvas;
const { refinerModel } = state.sdxl;
const { refinerModel } = state.canvasV2.params;
const isUsingScaledDimensions = ['auto', 'manual'].includes(boundingBoxScaleMethod);

View File

@@ -19,7 +19,7 @@ export const buildCanvasGraph = async (
let graph: NonNullableGraph;
if (generationMode === 'txt2img') {
if (state.generation.model && state.generation.model.base === 'sdxl') {
if (state.canvasV2.params.model && state.canvasV2.params.model.base === 'sdxl') {
graph = await buildCanvasSDXLTextToImageGraph(state);
} else {
graph = await buildCanvasTextToImageGraph(state);
@@ -28,7 +28,7 @@ export const buildCanvasGraph = async (
if (!canvasInitImage) {
throw new Error('Missing canvas init image');
}
if (state.generation.model && state.generation.model.base === 'sdxl') {
if (state.canvasV2.params.model && state.canvasV2.params.model.base === 'sdxl') {
graph = await buildCanvasSDXLImageToImageGraph(state, canvasInitImage);
} else {
graph = await buildCanvasImageToImageGraph(state, canvasInitImage);
@@ -37,7 +37,7 @@ export const buildCanvasGraph = async (
if (!canvasInitImage || !canvasMaskImage) {
throw new Error('Missing canvas init and mask images');
}
if (state.generation.model && state.generation.model.base === 'sdxl') {
if (state.canvasV2.params.model && state.canvasV2.params.model.base === 'sdxl') {
graph = await buildCanvasSDXLInpaintGraph(state, canvasInitImage, canvasMaskImage);
} else {
graph = await buildCanvasInpaintGraph(state, canvasInitImage, canvasMaskImage);
@@ -46,7 +46,7 @@ export const buildCanvasGraph = async (
if (!canvasInitImage) {
throw new Error('Missing canvas init image');
}
if (state.generation.model && state.generation.model.base === 'sdxl') {
if (state.canvasV2.params.model && state.canvasV2.params.model.base === 'sdxl') {
graph = await buildCanvasSDXLOutpaintGraph(state, canvasInitImage, canvasMaskImage);
} else {
graph = await buildCanvasOutpaintGraph(state, canvasInitImage, canvasMaskImage);

View File

@@ -54,7 +54,7 @@ export const buildCanvasImageToImageGraph = async (
shouldUseCpuNoise,
seamlessXAxis,
seamlessYAxis,
} = state.generation;
} = state.canvasV2.params;
// The bounding box determines width and height, not the width and height params
const { width, height } = state.canvas.boundingBoxDimensions;

View File

@@ -61,7 +61,7 @@ export const buildCanvasInpaintGraph = async (
canvasCoherenceMinDenoise,
canvasCoherenceEdgeSize,
maskBlur,
} = state.generation;
} = state.canvasV2.params;
if (!model) {
log.error('No model found in state');

View File

@@ -73,7 +73,7 @@ export const buildCanvasOutpaintGraph = async (
canvasCoherenceMinDenoise,
canvasCoherenceEdgeSize,
maskBlur,
} = state.generation;
} = state.canvasV2.params;
if (!model) {
log.error('No model found in state');

View File

@@ -54,9 +54,9 @@ export const buildCanvasSDXLImageToImageGraph = async (
seamlessXAxis,
seamlessYAxis,
img2imgStrength: strength,
} = state.generation;
} = state.canvasV2.params;
const { refinerModel, refinerStart } = state.sdxl;
const { refinerModel, refinerStart } = state.canvasV2.params;
// The bounding box determines width and height, not the width and height params
const { width, height } = state.canvas.boundingBoxDimensions;

View File

@@ -61,9 +61,9 @@ export const buildCanvasSDXLInpaintGraph = async (
canvasCoherenceMinDenoise,
canvasCoherenceEdgeSize,
maskBlur,
} = state.generation;
} = state.canvasV2.params;
const { refinerModel, refinerStart } = state.sdxl;
const { refinerModel, refinerStart } = state.canvasV2.params;
if (!model) {
log.error('No model found in state');

View File

@@ -73,9 +73,9 @@ export const buildCanvasSDXLOutpaintGraph = async (
canvasCoherenceMinDenoise,
canvasCoherenceEdgeSize,
maskBlur,
} = state.generation;
} = state.canvasV2.params;
const { refinerModel, refinerStart } = state.sdxl;
const { refinerModel, refinerStart } = state.canvasV2.params;
if (!model) {
log.error('No model found in state');

View File

@@ -47,7 +47,7 @@ export const buildCanvasSDXLTextToImageGraph = async (state: RootState): Promise
shouldUseCpuNoise,
seamlessXAxis,
seamlessYAxis,
} = state.generation;
} = state.canvasV2.params;
// The bounding box determines width and height, not the width and height params
const { width, height } = state.canvas.boundingBoxDimensions;
@@ -58,7 +58,7 @@ export const buildCanvasSDXLTextToImageGraph = async (state: RootState): Promise
const is_intermediate = true;
const isUsingScaledDimensions = ['auto', 'manual'].includes(boundingBoxScaleMethod);
const { refinerModel, refinerStart } = state.sdxl;
const { refinerModel, refinerStart } = state.canvasV2.params;
if (!model) {
log.error('No model found in state');

View File

@@ -47,7 +47,7 @@ export const buildCanvasTextToImageGraph = async (state: RootState): Promise<Non
shouldUseCpuNoise,
seamlessXAxis,
seamlessYAxis,
} = state.generation;
} = state.canvasV2.params;
// The bounding box determines width and height, not the width and height params
const { width, height } = state.canvas.boundingBoxDimensions;

View File

@@ -419,8 +419,8 @@ const addInitialImageLayerToGraph = (
| Invocation<'sdxl_model_loader'>,
layer: InitialImageLayer
) => {
const { vaePrecision } = state.generation;
const { refinerModel, refinerStart } = state.sdxl;
const { vaePrecision } = state.canvasV2.params;
const { refinerModel, refinerStart } = state.canvasV2.params;
const { width, height } = state.canvasV2.document;
assert(layer.isEnabled, 'Initial image layer is not enabled');
assert(layer.image, 'Initial image layer has no image');

View File

@@ -12,7 +12,7 @@ import {
} from 'features/nodes/util/graph/constants';
import type { Graph } from 'features/nodes/util/graph/generation/Graph';
import { getBoardField } from 'features/nodes/util/graph/graphBuilderUtils';
import { selectOptimalDimension } from 'features/parameters/store/generationSlice';
import { selectOptimalDimension } from 'features/controlLayers/store/selectors';
import type { Invocation } from 'services/api/types';
/**

View File

@@ -30,7 +30,7 @@ export const addSDXLRefiner = async (
refinerScheduler,
refinerCFGScale,
refinerStart,
} = state.sdxl;
} = state.canvasV2.params;
assert(refinerModel, 'No refiner model found in state');

View File

@@ -21,7 +21,7 @@ export const addSeamless = (
modelLoader: Invocation<'main_model_loader'> | Invocation<'sdxl_model_loader'>,
vaeLoader: Invocation<'vae_loader'> | null
): Invocation<'seamless'> | null => {
const { seamlessXAxis: seamless_x, seamlessYAxis: seamless_y } = state.generation;
const { seamlessXAxis: seamless_x, seamlessYAxis: seamless_y } = state.canvasV2.params;
if (!seamless_x && !seamless_y) {
return null;

View File

@@ -39,7 +39,7 @@ export const buildGenerationTabGraph = async (state: RootState): Promise<GraphTy
vaePrecision,
seed,
vae,
} = state.generation;
} = state.canvasV2.params;
const { width, height } = state.canvasV2.document;
assert(model, 'No model found in state');

View File

@@ -35,10 +35,10 @@ export const buildGenerationTabSDXLGraph = async (state: RootState): Promise<Non
shouldUseCpuNoise,
vaePrecision,
vae,
} = state.generation;
} = state.canvasV2.params;
const { width, height } = state.canvasV2.document;
const { refinerModel, refinerStart } = state.sdxl;
const { refinerModel, refinerStart } = state.canvasV2.params;
assert(model, 'No model found in state');