From e8023c44b0eef64692af054d7a37e2348c6ebc52 Mon Sep 17 00:00:00 2001 From: psychedelicious <4822129+psychedelicious@users.noreply.github.com> Date: Wed, 8 May 2024 16:01:34 +1000 Subject: [PATCH] chore(ui): lint --- .../controlLayers/util/controlAdapters.ts | 6 - .../graph/addInitialImageToLinearGraph.ts | 133 ------------------ 2 files changed, 139 deletions(-) delete mode 100644 invokeai/frontend/web/src/features/nodes/util/graph/addInitialImageToLinearGraph.ts diff --git a/invokeai/frontend/web/src/features/controlLayers/util/controlAdapters.ts b/invokeai/frontend/web/src/features/controlLayers/util/controlAdapters.ts index b643e4a64d..070ca64b32 100644 --- a/invokeai/frontend/web/src/features/controlLayers/util/controlAdapters.ts +++ b/invokeai/frontend/web/src/features/controlLayers/util/controlAdapters.ts @@ -214,18 +214,12 @@ export const zControlNetConfigV2 = zControlAdapterBase.extend({ }); export type ControlNetConfigV2 = z.infer; -export const isControlNetConfigV2 = (ca: ControlNetConfigV2 | T2IAdapterConfigV2): ca is ControlNetConfigV2 => - zControlNetConfigV2.safeParse(ca).success; - export const zT2IAdapterConfigV2 = zControlAdapterBase.extend({ type: z.literal('t2i_adapter'), model: zModelIdentifierField.nullable(), }); export type T2IAdapterConfigV2 = z.infer; -export const isT2IAdapterConfigV2 = (ca: ControlNetConfigV2 | T2IAdapterConfigV2): ca is T2IAdapterConfigV2 => - zT2IAdapterConfigV2.safeParse(ca).success; - const zCLIPVisionModelV2 = z.enum(['ViT-H', 'ViT-G']); export type CLIPVisionModelV2 = z.infer; export const isCLIPVisionModelV2 = (v: unknown): v is CLIPVisionModelV2 => zCLIPVisionModelV2.safeParse(v).success; diff --git a/invokeai/frontend/web/src/features/nodes/util/graph/addInitialImageToLinearGraph.ts b/invokeai/frontend/web/src/features/nodes/util/graph/addInitialImageToLinearGraph.ts deleted file mode 100644 index 2460b187a4..0000000000 --- a/invokeai/frontend/web/src/features/nodes/util/graph/addInitialImageToLinearGraph.ts +++ /dev/null @@ -1,133 +0,0 @@ -import type { RootState } from 'app/store/store'; -import { isInitialImageLayer } from 'features/controlLayers/store/controlLayersSlice'; -import { upsertMetadata } from 'features/nodes/util/graph/metadata'; -import type { ImageResizeInvocation, ImageToLatentsInvocation, NonNullableGraph } from 'services/api/types'; -import { assert } from 'tsafe'; - -import { IMAGE_TO_LATENTS, NOISE, RESIZE } from './constants'; - -/** - * Returns true if an initial image was added, false if not. - */ -export const addInitialImageToLinearGraph = ( - state: RootState, - graph: NonNullableGraph, - denoiseNodeId: string -): boolean => { - // Remove Existing UNet Connections - const { vaePrecision, model } = state.generation; - const { refinerModel, refinerStart } = state.sdxl; - const { width, height } = state.controlLayers.present.size; - const initialImageLayer = state.controlLayers.present.layers.find(isInitialImageLayer); - const initialImage = initialImageLayer?.isEnabled ? initialImageLayer?.image : null; - - if (!initialImage || !initialImageLayer) { - return false; - } - - const isSDXL = model?.base === 'sdxl'; - const useRefinerStartEnd = isSDXL && Boolean(refinerModel); - - const denoiseNode = graph.nodes[denoiseNodeId]; - assert(denoiseNode?.type === 'denoise_latents', `Missing denoise node or incorrect type: ${denoiseNode?.type}`); - - const { denoisingStrength } = initialImageLayer; - denoiseNode.denoising_start = useRefinerStartEnd - ? Math.min(refinerStart, 1 - denoisingStrength) - : 1 - denoisingStrength; - denoiseNode.denoising_end = useRefinerStartEnd ? refinerStart : 1; - - // We conditionally hook the image in depending on if a resize is needed - const i2lNode: ImageToLatentsInvocation = { - type: 'i2l', - id: IMAGE_TO_LATENTS, - is_intermediate: true, - use_cache: true, - fp32: vaePrecision === 'fp32', - }; - - graph.nodes[i2lNode.id] = i2lNode; - graph.edges.push({ - source: { - node_id: IMAGE_TO_LATENTS, - field: 'latents', - }, - destination: { - node_id: denoiseNode.id, - field: 'latents', - }, - }); - - if (initialImage.width !== width || initialImage.height !== height) { - // The init image needs to be resized to the specified width and height before being passed to `IMAGE_TO_LATENTS` - - // Create a resize node, explicitly setting its image - const resizeNode: ImageResizeInvocation = { - id: RESIZE, - type: 'img_resize', - image: { - image_name: initialImage.name, - }, - is_intermediate: true, - width, - height, - }; - - graph.nodes[RESIZE] = resizeNode; - - // The `RESIZE` node then passes its image to `IMAGE_TO_LATENTS` - graph.edges.push({ - source: { node_id: RESIZE, field: 'image' }, - destination: { - node_id: IMAGE_TO_LATENTS, - field: 'image', - }, - }); - - // The `RESIZE` node also passes its width and height to `NOISE` - graph.edges.push({ - source: { node_id: RESIZE, field: 'width' }, - destination: { - node_id: NOISE, - field: 'width', - }, - }); - - graph.edges.push({ - source: { node_id: RESIZE, field: 'height' }, - destination: { - node_id: NOISE, - field: 'height', - }, - }); - } else { - // We are not resizing, so we need to set the image on the `IMAGE_TO_LATENTS` node explicitly - i2lNode.image = { - image_name: initialImage.name, - }; - - // Pass the image's dimensions to the `NOISE` node - graph.edges.push({ - source: { node_id: IMAGE_TO_LATENTS, field: 'width' }, - destination: { - node_id: NOISE, - field: 'width', - }, - }); - graph.edges.push({ - source: { node_id: IMAGE_TO_LATENTS, field: 'height' }, - destination: { - node_id: NOISE, - field: 'height', - }, - }); - } - - upsertMetadata(graph, { - generation_mode: isSDXL ? 'sdxl_img2img' : 'img2img', - strength: denoisingStrength, - init_image: initialImage.name, - }); - - return true; -};