diff --git a/invokeai/frontend/web/src/app/store/middleware/listenerMiddleware/listeners/upscaleRequested.ts b/invokeai/frontend/web/src/app/store/middleware/listenerMiddleware/listeners/upscaleRequested.ts index d5fd1ae8caf..d2e40b46641 100644 --- a/invokeai/frontend/web/src/app/store/middleware/listenerMiddleware/listeners/upscaleRequested.ts +++ b/invokeai/frontend/web/src/app/store/middleware/listenerMiddleware/listeners/upscaleRequested.ts @@ -3,7 +3,6 @@ import { logger } from 'app/logging/logger'; import type { AppStartListening } from 'app/store/middleware/listenerMiddleware'; import { parseify } from 'common/util/serialize'; import { buildAdHocUpscaleGraph } from 'features/nodes/util/graph/buildAdHocUpscaleGraph'; -import { createIsAllowedToUpscaleSelector } from 'features/parameters/hooks/useIsAllowedToUpscale'; import { toast } from 'features/toast/toast'; import { t } from 'i18next'; import { queueApi } from 'services/api/endpoints/queue'; @@ -20,22 +19,6 @@ export const addUpscaleRequestedListener = (startAppListening: AppStartListening const { imageDTO } = action.payload; const state = getState(); - const { isAllowedToUpscale, detailTKey } = createIsAllowedToUpscaleSelector(imageDTO)(state); - - // if we can't upscale, show a toast and return - if (!isAllowedToUpscale) { - log.error( - { imageDTO }, - t(detailTKey ?? 'parameters.isAllowedToUpscale.tooLarge') // should never coalesce - ); - toast({ - id: 'NOT_ALLOWED_TO_UPSCALE', - title: t(detailTKey ?? 'parameters.isAllowedToUpscale.tooLarge'), // should never coalesce - status: 'error', - }); - return; - } - const enqueueBatchArg: BatchConfig = { prepend: true, batch: { diff --git a/invokeai/frontend/web/src/features/nodes/util/graph/buildAdHocUpscaleGraph.ts b/invokeai/frontend/web/src/features/nodes/util/graph/buildAdHocUpscaleGraph.ts index 0c6a0803ad6..2ba15692771 100644 --- a/invokeai/frontend/web/src/features/nodes/util/graph/buildAdHocUpscaleGraph.ts +++ b/invokeai/frontend/web/src/features/nodes/util/graph/buildAdHocUpscaleGraph.ts @@ -1,5 +1,6 @@ import type { RootState } from 'app/store/store'; import { fetchModelConfigWithTypeGuard } from 'features/metadata/util/modelFetchingHelpers'; +import { getBoardField } from 'features/nodes/util/graph/graphBuilderUtils'; import { type ImageDTO, type Invocation, @@ -27,6 +28,7 @@ export const buildAdHocUpscaleGraph = async ({ image, state }: Arg): Promise { const { imageDTO } = props; const dispatch = useAppDispatch(); + const { simpleUpscaleModel } = useAppSelector((s) => s.upscale); const inProgress = useIsQueueMutationInProgress(); const { t } = useTranslation(); const { isOpen, onOpen, onClose } = useDisclosure(); - const { isAllowedToUpscale, detail } = useIsAllowedToUpscale(imageDTO); const handleClickUpscale = useCallback(() => { onClose(); - if (!imageDTO || !isAllowedToUpscale) { + if (!imageDTO) { return; } dispatch(upscaleRequested({ imageDTO })); - }, [dispatch, imageDTO, isAllowedToUpscale, onClose]); + }, [dispatch, imageDTO, onClose]); return ( @@ -53,12 +52,7 @@ const ParamUpscalePopover = (props: Props) => { - diff --git a/invokeai/frontend/web/src/features/parameters/hooks/useIsAllowedToUpscale.ts b/invokeai/frontend/web/src/features/parameters/hooks/useIsAllowedToUpscale.ts deleted file mode 100644 index e7d157fcc39..00000000000 --- a/invokeai/frontend/web/src/features/parameters/hooks/useIsAllowedToUpscale.ts +++ /dev/null @@ -1,84 +0,0 @@ -import { createMemoizedSelector } from 'app/store/createMemoizedSelector'; -import { useAppSelector } from 'app/store/storeHooks'; -import { selectUpscalelice } from 'features/parameters/store/upscaleSlice'; -import { selectConfigSlice } from 'features/system/store/configSlice'; -import { useMemo } from 'react'; -import { useTranslation } from 'react-i18next'; -import type { ImageDTO } from 'services/api/types'; - -const getUpscaledPixels = (imageDTO?: ImageDTO, maxUpscalePixels?: number) => { - if (!imageDTO) { - return; - } - if (!maxUpscalePixels) { - return; - } - const { width, height } = imageDTO; - const x4 = height * 4 * width * 4; - const x2 = height * 2 * width * 2; - return { x4, x2 }; -}; - -const getIsAllowedToUpscale = (upscaledPixels?: ReturnType, maxUpscalePixels?: number) => { - if (!upscaledPixels || !maxUpscalePixels) { - return { x4: true, x2: true }; - } - const isAllowedToUpscale = { x4: false, x2: false }; - if (upscaledPixels.x4 <= maxUpscalePixels) { - isAllowedToUpscale.x4 = true; - } - if (upscaledPixels.x2 <= maxUpscalePixels) { - isAllowedToUpscale.x2 = true; - } - - return isAllowedToUpscale; -}; - -const getDetailTKey = (isAllowedToUpscale?: ReturnType, scaleFactor?: number) => { - if (!isAllowedToUpscale || !scaleFactor) { - return; - } - - if (isAllowedToUpscale.x4 && isAllowedToUpscale.x2) { - return; - } - - if (!isAllowedToUpscale.x2 && !isAllowedToUpscale.x4) { - return 'parameters.isAllowedToUpscale.tooLarge'; - } - - if (!isAllowedToUpscale.x4 && isAllowedToUpscale.x2 && scaleFactor === 4) { - return 'parameters.isAllowedToUpscale.useX2Model'; - } - - return; -}; - -export const createIsAllowedToUpscaleSelector = (imageDTO?: ImageDTO) => - createMemoizedSelector(selectUpscalelice, selectConfigSlice, (upscale, config) => { - const { simpleUpscaleModel } = upscale; - const { maxUpscalePixels } = config; - if (!simpleUpscaleModel) { - return { isAllowedToUpscale: false, detailTKey: undefined }; - } - - const upscaledPixels = getUpscaledPixels(imageDTO, maxUpscalePixels); - const isAllowedToUpscale = getIsAllowedToUpscale(upscaledPixels, maxUpscalePixels); - const scaleFactor = simpleUpscaleModel.name.includes('x2') ? 2 : 4; - const detailTKey = getDetailTKey(isAllowedToUpscale, scaleFactor); - return { - isAllowedToUpscale: scaleFactor === 2 ? isAllowedToUpscale.x2 : isAllowedToUpscale.x4, - detailTKey, - }; - }); - -export const useIsAllowedToUpscale = (imageDTO?: ImageDTO) => { - const { t } = useTranslation(); - const selectIsAllowedToUpscale = useMemo(() => createIsAllowedToUpscaleSelector(imageDTO), [imageDTO]); - const { isAllowedToUpscale, detailTKey } = useAppSelector(selectIsAllowedToUpscale); - - return { - isAllowedToUpscale, - detail: detailTKey ? t(detailTKey) : undefined, - }; -}; diff --git a/invokeai/frontend/web/src/features/settingsAccordions/components/UpscaleSettingsAccordion/UpscaleWarning.tsx b/invokeai/frontend/web/src/features/settingsAccordions/components/UpscaleSettingsAccordion/UpscaleWarning.tsx index e20bf3bc5e1..d1873c15ae2 100644 --- a/invokeai/frontend/web/src/features/settingsAccordions/components/UpscaleSettingsAccordion/UpscaleWarning.tsx +++ b/invokeai/frontend/web/src/features/settingsAccordions/components/UpscaleSettingsAccordion/UpscaleWarning.tsx @@ -14,7 +14,7 @@ interface Props { export const UpscaleWarning = ({ usesTile }: Props) => { const { t } = useTranslation(); const model = useAppSelector((s) => s.generation.model); - const { tileControlnetModel, upscaleModel } = useAppSelector((s) => s.upscale); + const { tileControlnetModel, upscaleModel, simpleUpscaleModel } = useAppSelector((s) => s.upscale); const dispatch = useAppDispatch(); const [modelConfigs, { isLoading }] = useControlNetModels(); const disabledTabs = useAppSelector((s) => s.config.disabledTabs); @@ -29,6 +29,12 @@ export const UpscaleWarning = ({ usesTile }: Props) => { const warnings = useMemo(() => { const _warnings: string[] = []; + if (!usesTile) { + if (!simpleUpscaleModel) { + _warnings.push(t('upscaling.upscaleModelDesc')); + } + return _warnings; + } if (!model) { _warnings.push(t('upscaling.mainModelDesc')); } @@ -39,7 +45,7 @@ export const UpscaleWarning = ({ usesTile }: Props) => { _warnings.push(t('upscaling.upscaleModelDesc')); } return _warnings; - }, [model, upscaleModel, tileControlnetModel, usesTile, t]); + }, [model, upscaleModel, tileControlnetModel, usesTile, simpleUpscaleModel, t]); const handleGoToModelManager = useCallback(() => { dispatch(setActiveTab('models'));