mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
feat(ui): half-baked use all parameters
until we have a better system for metadata, this will remain half-baked
This commit is contained in:
parent
3d1470399c
commit
fe8b5193de
@ -61,6 +61,7 @@ import { initialImageSelected } from 'features/parameters/store/actions';
|
|||||||
import { requestedImageDeletion } from '../store/actions';
|
import { requestedImageDeletion } from '../store/actions';
|
||||||
import FaceRestoreSettings from 'features/parameters/components/Parameters/FaceRestore/FaceRestoreSettings';
|
import FaceRestoreSettings from 'features/parameters/components/Parameters/FaceRestore/FaceRestoreSettings';
|
||||||
import UpscaleSettings from 'features/parameters/components/Parameters/Upscale/UpscaleSettings';
|
import UpscaleSettings from 'features/parameters/components/Parameters/Upscale/UpscaleSettings';
|
||||||
|
import { allParametersSet } from 'features/parameters/store/generationSlice';
|
||||||
|
|
||||||
const currentImageButtonsSelector = createSelector(
|
const currentImageButtonsSelector = createSelector(
|
||||||
[
|
[
|
||||||
@ -157,7 +158,7 @@ const CurrentImageButtons = (props: CurrentImageButtonsProps) => {
|
|||||||
const toast = useToast();
|
const toast = useToast();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
const { recallPrompt, recallSeed } = useParameters();
|
const { recallPrompt, recallSeed, recallAllParameters } = useParameters();
|
||||||
|
|
||||||
// const handleCopyImage = useCallback(async () => {
|
// const handleCopyImage = useCallback(async () => {
|
||||||
// if (!image?.url) {
|
// if (!image?.url) {
|
||||||
@ -228,39 +229,15 @@ const CurrentImageButtons = (props: CurrentImageButtonsProps) => {
|
|||||||
}, [dispatch, shouldHidePreview]);
|
}, [dispatch, shouldHidePreview]);
|
||||||
|
|
||||||
const handleClickUseAllParameters = useCallback(() => {
|
const handleClickUseAllParameters = useCallback(() => {
|
||||||
if (!image) return;
|
recallAllParameters(image);
|
||||||
// selectedImage.metadata &&
|
}, [image, recallAllParameters]);
|
||||||
// dispatch(setAllParameters(selectedImage.metadata));
|
|
||||||
// if (selectedImage.metadata?.image.type === 'img2img') {
|
|
||||||
// dispatch(setActiveTab('img2img'));
|
|
||||||
// } else if (selectedImage.metadata?.image.type === 'txt2img') {
|
|
||||||
// dispatch(setActiveTab('txt2img'));
|
|
||||||
// }
|
|
||||||
}, [image]);
|
|
||||||
|
|
||||||
useHotkeys(
|
useHotkeys(
|
||||||
'a',
|
'a',
|
||||||
() => {
|
() => {
|
||||||
const type = image?.metadata?.invokeai?.node?.types;
|
handleClickUseAllParameters;
|
||||||
if (isString(type) && ['txt2img', 'img2img'].includes(type)) {
|
|
||||||
handleClickUseAllParameters();
|
|
||||||
toast({
|
|
||||||
title: t('toast.parametersSet'),
|
|
||||||
status: 'success',
|
|
||||||
duration: 2500,
|
|
||||||
isClosable: true,
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
toast({
|
|
||||||
title: t('toast.parametersNotSet'),
|
|
||||||
description: t('toast.parametersNotSetDesc'),
|
|
||||||
status: 'error',
|
|
||||||
duration: 2500,
|
|
||||||
isClosable: true,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
[image]
|
[image, recallAllParameters]
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleUseSeed = useCallback(() => {
|
const handleUseSeed = useCallback(() => {
|
||||||
@ -530,8 +507,8 @@ const CurrentImageButtons = (props: CurrentImageButtonsProps) => {
|
|||||||
tooltip={`${t('parameters.useAll')} (A)`}
|
tooltip={`${t('parameters.useAll')} (A)`}
|
||||||
aria-label={`${t('parameters.useAll')} (A)`}
|
aria-label={`${t('parameters.useAll')} (A)`}
|
||||||
isDisabled={
|
isDisabled={
|
||||||
!['txt2img', 'img2img'].includes(
|
!['txt2img', 'img2img', 'inpaint'].includes(
|
||||||
image?.metadata?.sd_metadata?.type
|
String(image?.metadata?.invokeai?.node?.type)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
onClick={handleClickUseAllParameters}
|
onClick={handleClickUseAllParameters}
|
||||||
|
@ -105,7 +105,8 @@ const HoverableImage = memo((props: HoverableImageProps) => {
|
|||||||
|
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { isFeatureEnabled: isLightboxEnabled } = useFeatureStatus('lightbox');
|
const { isFeatureEnabled: isLightboxEnabled } = useFeatureStatus('lightbox');
|
||||||
const { recallSeed, recallPrompt, recallInitialImage } = useParameters();
|
const { recallSeed, recallPrompt, recallInitialImage, recallAllParameters } =
|
||||||
|
useParameters();
|
||||||
|
|
||||||
const handleMouseOver = () => setIsHovered(true);
|
const handleMouseOver = () => setIsHovered(true);
|
||||||
const handleMouseOut = () => setIsHovered(false);
|
const handleMouseOut = () => setIsHovered(false);
|
||||||
@ -176,16 +177,9 @@ const HoverableImage = memo((props: HoverableImageProps) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleUseAllParameters = () => {
|
const handleUseAllParameters = useCallback(() => {
|
||||||
// metadata.invokeai?.node &&
|
recallAllParameters(image);
|
||||||
// dispatch(setAllParameters(metadata.invokeai?.node));
|
}, [image, recallAllParameters]);
|
||||||
// toast({
|
|
||||||
// title: t('toast.parametersSet'),
|
|
||||||
// status: 'success',
|
|
||||||
// duration: 2500,
|
|
||||||
// isClosable: true,
|
|
||||||
// });
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleLightBox = () => {
|
const handleLightBox = () => {
|
||||||
// dispatch(setCurrentImage(image));
|
// dispatch(setCurrentImage(image));
|
||||||
@ -239,7 +233,7 @@ const HoverableImage = memo((props: HoverableImageProps) => {
|
|||||||
icon={<IoArrowUndoCircleOutline />}
|
icon={<IoArrowUndoCircleOutline />}
|
||||||
onClickCapture={handleUseAllParameters}
|
onClickCapture={handleUseAllParameters}
|
||||||
isDisabled={
|
isDisabled={
|
||||||
!['txt2img', 'img2img'].includes(
|
!['txt2img', 'img2img', 'inpaint'].includes(
|
||||||
String(image?.metadata?.invokeai?.node?.type)
|
String(image?.metadata?.invokeai?.node?.type)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -4,11 +4,12 @@ import { isFinite, isString } from 'lodash-es';
|
|||||||
import { useCallback } from 'react';
|
import { useCallback } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import useSetBothPrompts from './usePrompt';
|
import useSetBothPrompts from './usePrompt';
|
||||||
import { setSeed } from '../store/generationSlice';
|
import { allParametersSet, setSeed } from '../store/generationSlice';
|
||||||
import { isImageField } from 'services/types/guards';
|
import { isImageField } from 'services/types/guards';
|
||||||
import { NUMPY_RAND_MAX } from 'app/constants';
|
import { NUMPY_RAND_MAX } from 'app/constants';
|
||||||
import { initialImageSelected } from '../store/actions';
|
import { initialImageSelected } from '../store/actions';
|
||||||
import { Image } from 'app/types/invokeai';
|
import { Image } from 'app/types/invokeai';
|
||||||
|
import { setActiveTab } from 'features/ui/store/uiSlice';
|
||||||
|
|
||||||
export const useParameters = () => {
|
export const useParameters = () => {
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
@ -110,5 +111,42 @@ export const useParameters = () => {
|
|||||||
[dispatch]
|
[dispatch]
|
||||||
);
|
);
|
||||||
|
|
||||||
return { recallPrompt, recallSeed, recallInitialImage, sendToImageToImage };
|
const recallAllParameters = useCallback(
|
||||||
|
(image: Image | undefined) => {
|
||||||
|
const type = image?.metadata?.invokeai?.node?.type;
|
||||||
|
if (['txt2img', 'img2img', 'inpaint'].includes(String(type))) {
|
||||||
|
dispatch(allParametersSet(image));
|
||||||
|
|
||||||
|
if (image?.metadata?.invokeai?.node?.type === 'img2img') {
|
||||||
|
dispatch(setActiveTab('img2img'));
|
||||||
|
} else if (image?.metadata?.invokeai?.node?.type === 'txt2img') {
|
||||||
|
dispatch(setActiveTab('txt2img'));
|
||||||
|
}
|
||||||
|
|
||||||
|
toast({
|
||||||
|
title: t('toast.parametersSet'),
|
||||||
|
status: 'success',
|
||||||
|
duration: 2500,
|
||||||
|
isClosable: true,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
toast({
|
||||||
|
title: t('toast.parametersNotSet'),
|
||||||
|
description: t('toast.parametersNotSetDesc'),
|
||||||
|
status: 'error',
|
||||||
|
duration: 2500,
|
||||||
|
isClosable: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[t, toast, dispatch]
|
||||||
|
);
|
||||||
|
|
||||||
|
return {
|
||||||
|
recallPrompt,
|
||||||
|
recallSeed,
|
||||||
|
recallInitialImage,
|
||||||
|
sendToImageToImage,
|
||||||
|
recallAllParameters,
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
@ -3,6 +3,7 @@ import { createSlice } from '@reduxjs/toolkit';
|
|||||||
import * as InvokeAI from 'app/types/invokeai';
|
import * as InvokeAI from 'app/types/invokeai';
|
||||||
import promptToString from 'common/util/promptToString';
|
import promptToString from 'common/util/promptToString';
|
||||||
import { clamp } from 'lodash-es';
|
import { clamp } from 'lodash-es';
|
||||||
|
import { setAllParametersReducer } from './setAllParametersReducer';
|
||||||
|
|
||||||
export interface GenerationState {
|
export interface GenerationState {
|
||||||
cfgScale: number;
|
cfgScale: number;
|
||||||
@ -187,131 +188,7 @@ export const generationSlice = createSlice({
|
|||||||
state.shouldGenerateVariations = true;
|
state.shouldGenerateVariations = true;
|
||||||
state.variationAmount = 0;
|
state.variationAmount = 0;
|
||||||
},
|
},
|
||||||
setAllTextToImageParameters: (
|
allParametersSet: setAllParametersReducer,
|
||||||
state,
|
|
||||||
action: PayloadAction<InvokeAI.Metadata>
|
|
||||||
) => {
|
|
||||||
// const {
|
|
||||||
// sampler,
|
|
||||||
// prompt,
|
|
||||||
// seed,
|
|
||||||
// variations,
|
|
||||||
// steps,
|
|
||||||
// cfg_scale,
|
|
||||||
// threshold,
|
|
||||||
// perlin,
|
|
||||||
// seamless,
|
|
||||||
// _hires_fix,
|
|
||||||
// width,
|
|
||||||
// height,
|
|
||||||
// } = action.payload.image;
|
|
||||||
// if (variations && variations.length > 0) {
|
|
||||||
// state.seedWeights = seedWeightsToString(variations);
|
|
||||||
// state.shouldGenerateVariations = true;
|
|
||||||
// state.variationAmount = 0;
|
|
||||||
// } else {
|
|
||||||
// state.shouldGenerateVariations = false;
|
|
||||||
// }
|
|
||||||
// if (seed) {
|
|
||||||
// state.seed = seed;
|
|
||||||
// state.shouldRandomizeSeed = false;
|
|
||||||
// }
|
|
||||||
// if (prompt) state.prompt = promptToString(prompt);
|
|
||||||
// if (sampler) state.sampler = sampler;
|
|
||||||
// if (steps) state.steps = steps;
|
|
||||||
// if (cfg_scale) state.cfgScale = cfg_scale;
|
|
||||||
// if (typeof threshold === 'undefined') {
|
|
||||||
// state.threshold = 0;
|
|
||||||
// } else {
|
|
||||||
// state.threshold = threshold;
|
|
||||||
// }
|
|
||||||
// if (typeof perlin === 'undefined') {
|
|
||||||
// state.perlin = 0;
|
|
||||||
// } else {
|
|
||||||
// state.perlin = perlin;
|
|
||||||
// }
|
|
||||||
// if (typeof seamless === 'boolean') state.seamless = seamless;
|
|
||||||
// // if (typeof hires_fix === 'boolean') state.hiresFix = hires_fix; // TODO: Needs to be fixed after reorg
|
|
||||||
// if (width) state.width = width;
|
|
||||||
// if (height) state.height = height;
|
|
||||||
},
|
|
||||||
setAllImageToImageParameters: (
|
|
||||||
state,
|
|
||||||
action: PayloadAction<InvokeAI.Metadata>
|
|
||||||
) => {
|
|
||||||
// const { type, strength, fit, init_image_path, mask_image_path } =
|
|
||||||
// action.payload.image;
|
|
||||||
// if (type === 'img2img') {
|
|
||||||
// if (init_image_path) state.initialImage = init_image_path;
|
|
||||||
// if (mask_image_path) state.maskPath = mask_image_path;
|
|
||||||
// if (strength) state.img2imgStrength = strength;
|
|
||||||
// if (typeof fit === 'boolean') state.shouldFitToWidthHeight = fit;
|
|
||||||
// }
|
|
||||||
},
|
|
||||||
setAllParameters: (state, action: PayloadAction<InvokeAI.Metadata>) => {
|
|
||||||
// const {
|
|
||||||
// type,
|
|
||||||
// sampler,
|
|
||||||
// prompt,
|
|
||||||
// seed,
|
|
||||||
// variations,
|
|
||||||
// steps,
|
|
||||||
// cfg_scale,
|
|
||||||
// threshold,
|
|
||||||
// perlin,
|
|
||||||
// seamless,
|
|
||||||
// _hires_fix,
|
|
||||||
// width,
|
|
||||||
// height,
|
|
||||||
// strength,
|
|
||||||
// fit,
|
|
||||||
// init_image_path,
|
|
||||||
// mask_image_path,
|
|
||||||
// } = action.payload.image;
|
|
||||||
// if (type === 'img2img') {
|
|
||||||
// if (init_image_path) state.initialImage = init_image_path;
|
|
||||||
// if (mask_image_path) state.maskPath = mask_image_path;
|
|
||||||
// if (strength) state.img2imgStrength = strength;
|
|
||||||
// if (typeof fit === 'boolean') state.shouldFitToWidthHeight = fit;
|
|
||||||
// }
|
|
||||||
// if (variations && variations.length > 0) {
|
|
||||||
// state.seedWeights = seedWeightsToString(variations);
|
|
||||||
// state.shouldGenerateVariations = true;
|
|
||||||
// state.variationAmount = 0;
|
|
||||||
// } else {
|
|
||||||
// state.shouldGenerateVariations = false;
|
|
||||||
// }
|
|
||||||
// if (seed) {
|
|
||||||
// state.seed = seed;
|
|
||||||
// state.shouldRandomizeSeed = false;
|
|
||||||
// }
|
|
||||||
// if (prompt) {
|
|
||||||
// const [promptOnly, negativePrompt] = getPromptAndNegative(prompt);
|
|
||||||
// if (promptOnly) state.prompt = promptOnly;
|
|
||||||
// negativePrompt
|
|
||||||
// ? (state.negativePrompt = negativePrompt)
|
|
||||||
// : (state.negativePrompt = '');
|
|
||||||
// }
|
|
||||||
// if (sampler) state.sampler = sampler;
|
|
||||||
// if (steps) state.steps = steps;
|
|
||||||
// if (cfg_scale) state.cfgScale = cfg_scale;
|
|
||||||
// if (typeof threshold === 'undefined') {
|
|
||||||
// state.threshold = 0;
|
|
||||||
// } else {
|
|
||||||
// state.threshold = threshold;
|
|
||||||
// }
|
|
||||||
// if (typeof perlin === 'undefined') {
|
|
||||||
// state.perlin = 0;
|
|
||||||
// } else {
|
|
||||||
// state.perlin = perlin;
|
|
||||||
// }
|
|
||||||
// if (typeof seamless === 'boolean') state.seamless = seamless;
|
|
||||||
// // if (typeof hires_fix === 'boolean') state.hiresFix = hires_fix; // TODO: Needs to be fixed after reorg
|
|
||||||
// if (width) state.width = width;
|
|
||||||
// if (height) state.height = height;
|
|
||||||
// // state.shouldRunESRGAN = false; // TODO: Needs to be fixed after reorg
|
|
||||||
// // state.shouldRunFacetool = false; // TODO: Needs to be fixed after reorg
|
|
||||||
},
|
|
||||||
resetParametersState: (state) => {
|
resetParametersState: (state) => {
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
@ -321,12 +198,6 @@ export const generationSlice = createSlice({
|
|||||||
setShouldRandomizeSeed: (state, action: PayloadAction<boolean>) => {
|
setShouldRandomizeSeed: (state, action: PayloadAction<boolean>) => {
|
||||||
state.shouldRandomizeSeed = action.payload;
|
state.shouldRandomizeSeed = action.payload;
|
||||||
},
|
},
|
||||||
// setInitialImage: (
|
|
||||||
// state,
|
|
||||||
// action: PayloadAction<InvokeAI._Image | string>
|
|
||||||
// ) => {
|
|
||||||
// state.initialImage = action.payload;
|
|
||||||
// },
|
|
||||||
clearInitialImage: (state) => {
|
clearInitialImage: (state) => {
|
||||||
state.initialImage = undefined;
|
state.initialImage = undefined;
|
||||||
},
|
},
|
||||||
@ -417,6 +288,7 @@ export const {
|
|||||||
setSeamless,
|
setSeamless,
|
||||||
setSeamlessXAxis,
|
setSeamlessXAxis,
|
||||||
setSeamlessYAxis,
|
setSeamlessYAxis,
|
||||||
|
allParametersSet,
|
||||||
} = generationSlice.actions;
|
} = generationSlice.actions;
|
||||||
|
|
||||||
export default generationSlice.reducer;
|
export default generationSlice.reducer;
|
||||||
|
@ -0,0 +1,61 @@
|
|||||||
|
import { Draft, PayloadAction } from '@reduxjs/toolkit';
|
||||||
|
import { Image } from 'app/types/invokeai';
|
||||||
|
import { GenerationState } from './generationSlice';
|
||||||
|
import { ImageToImageInvocation } from 'services/api';
|
||||||
|
|
||||||
|
export const setAllParametersReducer = (
|
||||||
|
state: Draft<GenerationState>,
|
||||||
|
action: PayloadAction<Image | undefined>
|
||||||
|
) => {
|
||||||
|
const node = action.payload?.metadata.invokeai?.node;
|
||||||
|
|
||||||
|
if (!node) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
node.type === 'txt2img' ||
|
||||||
|
node.type === 'img2img' ||
|
||||||
|
node.type === 'inpaint'
|
||||||
|
) {
|
||||||
|
const { cfg_scale, height, model, prompt, scheduler, seed, steps, width } =
|
||||||
|
node;
|
||||||
|
|
||||||
|
if (cfg_scale !== undefined) {
|
||||||
|
state.cfgScale = Number(cfg_scale);
|
||||||
|
}
|
||||||
|
if (height !== undefined) {
|
||||||
|
state.height = Number(height);
|
||||||
|
}
|
||||||
|
if (model !== undefined) {
|
||||||
|
state.model = String(model);
|
||||||
|
}
|
||||||
|
if (prompt !== undefined) {
|
||||||
|
state.prompt = String(prompt);
|
||||||
|
}
|
||||||
|
if (scheduler !== undefined) {
|
||||||
|
state.sampler = String(scheduler);
|
||||||
|
}
|
||||||
|
if (seed !== undefined) {
|
||||||
|
state.seed = Number(seed);
|
||||||
|
state.shouldRandomizeSeed = false;
|
||||||
|
}
|
||||||
|
if (steps !== undefined) {
|
||||||
|
state.steps = Number(steps);
|
||||||
|
}
|
||||||
|
if (width !== undefined) {
|
||||||
|
state.width = Number(width);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (node.type === 'img2img') {
|
||||||
|
const { fit, image } = node as ImageToImageInvocation;
|
||||||
|
|
||||||
|
if (fit !== undefined) {
|
||||||
|
state.shouldFitToWidthHeight = Boolean(fit);
|
||||||
|
}
|
||||||
|
// if (image !== undefined) {
|
||||||
|
// state.initialImage = image;
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user