From f52b233205122f352353c4250bf4cd36dbc5fb84 Mon Sep 17 00:00:00 2001 From: blessedcoolant <54517381+blessedcoolant@users.noreply.github.com> Date: Tue, 7 Feb 2023 07:13:34 +1300 Subject: [PATCH 1/2] Add Hi Res Strength Slider --- .../public/locales/options/en-US.json | 1 + .../frontend/public/locales/options/en.json | 1 + .../src/common/util/parameterTranslation.ts | 3 ++ .../AdvancedOptions/Output/HiresOptions.tsx | 48 ++++++++++++++++++- .../features/options/store/optionsSlice.ts | 6 +++ 5 files changed, 57 insertions(+), 2 deletions(-) diff --git a/invokeai/frontend/public/locales/options/en-US.json b/invokeai/frontend/public/locales/options/en-US.json index f3c46bb97f..f8d65c859c 100644 --- a/invokeai/frontend/public/locales/options/en-US.json +++ b/invokeai/frontend/public/locales/options/en-US.json @@ -24,6 +24,7 @@ "otherOptions": "Other Options", "seamlessTiling": "Seamless Tiling", "hiresOptim": "High Res Optimization", + "hiresStrength": "High Res Strength", "imageFit": "Fit Initial Image To Output Size", "codeformerFidelity": "Fidelity", "seamSize": "Seam Size", diff --git a/invokeai/frontend/public/locales/options/en.json b/invokeai/frontend/public/locales/options/en.json index 32cadf1998..5bca8b0950 100644 --- a/invokeai/frontend/public/locales/options/en.json +++ b/invokeai/frontend/public/locales/options/en.json @@ -24,6 +24,7 @@ "otherOptions": "Other Options", "seamlessTiling": "Seamless Tiling", "hiresOptim": "High Res Optimization", + "hiresStrength": "High Res Strength", "imageFit": "Fit Initial Image To Output Size", "codeformerFidelity": "Fidelity", "seamSize": "Seam Size", diff --git a/invokeai/frontend/src/common/util/parameterTranslation.ts b/invokeai/frontend/src/common/util/parameterTranslation.ts index 2853b21b1d..130231640e 100644 --- a/invokeai/frontend/src/common/util/parameterTranslation.ts +++ b/invokeai/frontend/src/common/util/parameterTranslation.ts @@ -100,6 +100,7 @@ export const frontendToBackendParameters = ( facetoolType, height, hiresFix, + hiresStrength, img2imgStrength, infillMethod, initialImage, @@ -169,6 +170,8 @@ export const frontendToBackendParameters = ( generationParameters.seamless = seamless; generationParameters.hires_fix = hiresFix; + if (hiresFix) generationParameters.strength = hiresStrength; + if (shouldRunESRGAN) { esrganParameters = { level: upscalingLevel, diff --git a/invokeai/frontend/src/features/options/components/AdvancedOptions/Output/HiresOptions.tsx b/invokeai/frontend/src/features/options/components/AdvancedOptions/Output/HiresOptions.tsx index 738d8cb5a8..208a4682e5 100644 --- a/invokeai/frontend/src/features/options/components/AdvancedOptions/Output/HiresOptions.tsx +++ b/invokeai/frontend/src/features/options/components/AdvancedOptions/Output/HiresOptions.tsx @@ -1,10 +1,53 @@ import { Flex } from '@chakra-ui/react'; import { ChangeEvent } from 'react'; -import { RootState } from 'app/store'; +import type { RootState } from 'app/store'; import { useAppDispatch, useAppSelector } from 'app/storeHooks'; import IAISwitch from 'common/components/IAISwitch'; -import { setHiresFix } from 'features/options/store/optionsSlice'; +import { + setHiresFix, + setHiresStrength, +} from 'features/options/store/optionsSlice'; import { useTranslation } from 'react-i18next'; +import IAISlider from 'common/components/IAISlider'; + +function HighResStrength() { + const hiresFix = useAppSelector((state: RootState) => state.options.hiresFix); + const hiresStrength = useAppSelector( + (state: RootState) => state.options.hiresStrength + ); + + const dispatch = useAppDispatch(); + + const { t } = useTranslation(); + + const handleHiresStrength = (v: number) => { + dispatch(setHiresStrength(v)); + }; + + const handleHiResStrengthReset = () => { + dispatch(setHiresStrength(0.75)); + }; + + return ( + + ); +} /** * Hires Fix Toggle @@ -27,6 +70,7 @@ const HiresOptions = () => { isChecked={hiresFix} onChange={handleChangeHiresFix} /> + ); }; diff --git a/invokeai/frontend/src/features/options/store/optionsSlice.ts b/invokeai/frontend/src/features/options/store/optionsSlice.ts index b26f650695..effc9dcc99 100644 --- a/invokeai/frontend/src/features/options/store/optionsSlice.ts +++ b/invokeai/frontend/src/features/options/store/optionsSlice.ts @@ -20,6 +20,7 @@ export interface OptionsState { facetoolType: FacetoolType; height: number; hiresFix: boolean; + hiresStrength: number; img2imgStrength: number; infillMethod: string; initialImage?: InvokeAI.Image | string; // can be an Image or url @@ -71,6 +72,7 @@ const initialOptionsState: OptionsState = { facetoolType: 'gfpgan', height: 512, hiresFix: false, + hiresStrength: 0.75, img2imgStrength: 0.75, infillMethod: 'patchmatch', isLightBoxOpen: false, @@ -189,6 +191,9 @@ export const optionsSlice = createSlice({ setHiresFix: (state, action: PayloadAction) => { state.hiresFix = action.payload; }, + setHiresStrength: (state, action: PayloadAction) => { + state.hiresStrength = action.payload; + }, setShouldFitToWidthHeight: (state, action: PayloadAction) => { state.shouldFitToWidthHeight = action.payload; }, @@ -459,6 +464,7 @@ export const { setFacetoolType, setHeight, setHiresFix, + setHiresStrength, setImg2imgStrength, setInfillMethod, setInitialImage, From ac23a321b0e5151d279bd21e9f848e229b60e295 Mon Sep 17 00:00:00 2001 From: blessedcoolant <54517381+blessedcoolant@users.noreply.github.com> Date: Tue, 7 Feb 2023 07:15:42 +1300 Subject: [PATCH 2/2] build (hires-strength-slider) --- ...y-a33ada34.js => index-legacy-7649c4ae.js} | 8 +- .../{index.9310184f.js => index.b7daf15c.js} | 94 +++++++++---------- invokeai/frontend/dist/index.html | 4 +- .../frontend/dist/locales/options/en-US.json | 1 + .../frontend/dist/locales/options/en.json | 1 + 5 files changed, 55 insertions(+), 53 deletions(-) rename invokeai/frontend/dist/assets/{index-legacy-a33ada34.js => index-legacy-7649c4ae.js} (65%) rename invokeai/frontend/dist/assets/{index.9310184f.js => index.b7daf15c.js} (69%) diff --git a/invokeai/frontend/dist/assets/index-legacy-a33ada34.js b/invokeai/frontend/dist/assets/index-legacy-7649c4ae.js similarity index 65% rename from invokeai/frontend/dist/assets/index-legacy-a33ada34.js rename to invokeai/frontend/dist/assets/index-legacy-7649c4ae.js index b2afa9fed7..66ea3a7bb9 100644 --- a/invokeai/frontend/dist/assets/index-legacy-a33ada34.js +++ b/invokeai/frontend/dist/assets/index-legacy-7649c4ae.js @@ -18,7 +18,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ -var Y=a.exports,Z=G.exports;function X(e){for(var t="https://reactjs.org/docs/error-decoder.html?invariant="+e,n=1;n