mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
clean up useIsAllowedToUpscale since its no longer necessary
This commit is contained in:
parent
cb0bffedd5
commit
4017609b91
@ -3,7 +3,6 @@ import { logger } from 'app/logging/logger';
|
|||||||
import type { AppStartListening } from 'app/store/middleware/listenerMiddleware';
|
import type { AppStartListening } from 'app/store/middleware/listenerMiddleware';
|
||||||
import { parseify } from 'common/util/serialize';
|
import { parseify } from 'common/util/serialize';
|
||||||
import { buildAdHocUpscaleGraph } from 'features/nodes/util/graph/buildAdHocUpscaleGraph';
|
import { buildAdHocUpscaleGraph } from 'features/nodes/util/graph/buildAdHocUpscaleGraph';
|
||||||
import { createIsAllowedToUpscaleSelector } from 'features/parameters/hooks/useIsAllowedToUpscale';
|
|
||||||
import { toast } from 'features/toast/toast';
|
import { toast } from 'features/toast/toast';
|
||||||
import { t } from 'i18next';
|
import { t } from 'i18next';
|
||||||
import { queueApi } from 'services/api/endpoints/queue';
|
import { queueApi } from 'services/api/endpoints/queue';
|
||||||
@ -20,22 +19,6 @@ export const addUpscaleRequestedListener = (startAppListening: AppStartListening
|
|||||||
const { imageDTO } = action.payload;
|
const { imageDTO } = action.payload;
|
||||||
const state = getState();
|
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 = {
|
const enqueueBatchArg: BatchConfig = {
|
||||||
prepend: true,
|
prepend: true,
|
||||||
batch: {
|
batch: {
|
||||||
|
@ -9,8 +9,7 @@ import {
|
|||||||
useDisclosure,
|
useDisclosure,
|
||||||
} from '@invoke-ai/ui-library';
|
} from '@invoke-ai/ui-library';
|
||||||
import { upscaleRequested } from 'app/store/middleware/listenerMiddleware/listeners/upscaleRequested';
|
import { upscaleRequested } from 'app/store/middleware/listenerMiddleware/listeners/upscaleRequested';
|
||||||
import { useAppDispatch } from 'app/store/storeHooks';
|
import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
|
||||||
import { useIsAllowedToUpscale } from 'features/parameters/hooks/useIsAllowedToUpscale';
|
|
||||||
import { useIsQueueMutationInProgress } from 'features/queue/hooks/useIsQueueMutationInProgress';
|
import { useIsQueueMutationInProgress } from 'features/queue/hooks/useIsQueueMutationInProgress';
|
||||||
import { UpscaleWarning } from 'features/settingsAccordions/components/UpscaleSettingsAccordion/UpscaleWarning';
|
import { UpscaleWarning } from 'features/settingsAccordions/components/UpscaleSettingsAccordion/UpscaleWarning';
|
||||||
import { memo, useCallback } from 'react';
|
import { memo, useCallback } from 'react';
|
||||||
@ -25,18 +24,18 @@ type Props = { imageDTO?: ImageDTO };
|
|||||||
const ParamUpscalePopover = (props: Props) => {
|
const ParamUpscalePopover = (props: Props) => {
|
||||||
const { imageDTO } = props;
|
const { imageDTO } = props;
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
|
const { simpleUpscaleModel } = useAppSelector((s) => s.upscale);
|
||||||
const inProgress = useIsQueueMutationInProgress();
|
const inProgress = useIsQueueMutationInProgress();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { isOpen, onOpen, onClose } = useDisclosure();
|
const { isOpen, onOpen, onClose } = useDisclosure();
|
||||||
const { isAllowedToUpscale, detail } = useIsAllowedToUpscale(imageDTO);
|
|
||||||
|
|
||||||
const handleClickUpscale = useCallback(() => {
|
const handleClickUpscale = useCallback(() => {
|
||||||
onClose();
|
onClose();
|
||||||
if (!imageDTO || !isAllowedToUpscale) {
|
if (!imageDTO) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
dispatch(upscaleRequested({ imageDTO }));
|
dispatch(upscaleRequested({ imageDTO }));
|
||||||
}, [dispatch, imageDTO, isAllowedToUpscale, onClose]);
|
}, [dispatch, imageDTO, onClose]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Popover isOpen={isOpen} onClose={onClose} isLazy>
|
<Popover isOpen={isOpen} onClose={onClose} isLazy>
|
||||||
@ -54,9 +53,8 @@ const ParamUpscalePopover = (props: Props) => {
|
|||||||
<ParamSpandrelModel isMultidiffusion={false} />
|
<ParamSpandrelModel isMultidiffusion={false} />
|
||||||
<UpscaleWarning usesTile={false} />
|
<UpscaleWarning usesTile={false} />
|
||||||
<Button
|
<Button
|
||||||
tooltip={detail}
|
|
||||||
size="sm"
|
size="sm"
|
||||||
isDisabled={!imageDTO || inProgress || !isAllowedToUpscale}
|
isDisabled={!imageDTO || inProgress || !simpleUpscaleModel}
|
||||||
onClick={handleClickUpscale}
|
onClick={handleClickUpscale}
|
||||||
>
|
>
|
||||||
{t('parameters.upscaleImage')}
|
{t('parameters.upscaleImage')}
|
||||||
|
@ -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<typeof getUpscaledPixels>, 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<typeof getIsAllowedToUpscale>, 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,
|
|
||||||
};
|
|
||||||
};
|
|
Loading…
Reference in New Issue
Block a user