diff --git a/frontend/src/common/util/parameterTranslation.ts b/frontend/src/common/util/parameterTranslation.ts index a9acded1e5..a28836baa3 100644 --- a/frontend/src/common/util/parameterTranslation.ts +++ b/frontend/src/common/util/parameterTranslation.ts @@ -66,7 +66,8 @@ export const frontendToBackendParameters = ( const generationParameters: { [k: string]: any } = { prompt, - iterations, + iterations: + shouldRandomizeSeed || shouldGenerateVariations ? iterations : 1, steps, cfg_scale: cfgScale, threshold, @@ -76,7 +77,7 @@ export const frontendToBackendParameters = ( sampler_name: sampler, seed, progress_images: shouldDisplayInProgressType === 'full-res', - progress_latents: shouldDisplayInProgressType === 'latents' + progress_latents: shouldDisplayInProgressType === 'latents', }; generationParameters.seed = shouldRandomizeSeed diff --git a/frontend/src/features/options/MainOptions/MainIterations.tsx b/frontend/src/features/options/MainOptions/MainIterations.tsx index 86889e4b5e..e244e02f05 100644 --- a/frontend/src/features/options/MainOptions/MainIterations.tsx +++ b/frontend/src/features/options/MainOptions/MainIterations.tsx @@ -1,13 +1,33 @@ +import { createSelector } from '@reduxjs/toolkit'; +import _ from 'lodash'; import React from 'react'; import { RootState, useAppDispatch, useAppSelector } from '../../../app/store'; import IAINumberInput from '../../../common/components/IAINumberInput'; -import { setIterations } from '../optionsSlice'; +import { mayGenerateMultipleImagesSelector } from '../optionsSelectors'; +import { OptionsState, setIterations } from '../optionsSlice'; import { fontSize, inputWidth } from './MainOptions'; +const mainIterationsSelector = createSelector( + [(state: RootState) => state.options, mayGenerateMultipleImagesSelector], + (options: OptionsState, mayGenerateMultipleImages) => { + const { iterations } = options; + + return { + iterations, + mayGenerateMultipleImages, + }; + }, + { + memoizeOptions: { + resultEqualityCheck: _.isEqual, + }, + } +); + export default function MainIterations() { const dispatch = useAppDispatch(); - const iterations = useAppSelector( - (state: RootState) => state.options.iterations + const { iterations, mayGenerateMultipleImages } = useAppSelector( + mainIterationsSelector ); const handleChangeIterations = (v: number) => dispatch(setIterations(v)); @@ -18,6 +38,7 @@ export default function MainIterations() { step={1} min={1} max={9999} + isDisabled={!mayGenerateMultipleImages} onChange={handleChangeIterations} value={iterations} width={inputWidth} diff --git a/frontend/src/features/options/optionsSelectors.ts b/frontend/src/features/options/optionsSelectors.ts index 0ea38fb2af..6a1f31c850 100644 --- a/frontend/src/features/options/optionsSelectors.ts +++ b/frontend/src/features/options/optionsSelectors.ts @@ -13,3 +13,17 @@ export const activeTabNameSelector = createSelector( }, } ); + +export const mayGenerateMultipleImagesSelector = createSelector( + (state: RootState) => state.options, + (options: OptionsState) => { + const { shouldRandomizeSeed, shouldGenerateVariations } = options; + + return shouldRandomizeSeed || shouldGenerateVariations; + }, + { + memoizeOptions: { + resultEqualityCheck: _.isEqual, + }, + } +);