From 90d1812decee63f46a510c403f5ad0572da37bae Mon Sep 17 00:00:00 2001 From: Sean Sube Date: Wed, 20 Sep 2023 19:27:37 -0500 Subject: [PATCH] fix(gui): use new grid seeds for every generation --- gui/src/client/utils.ts | 29 +++++++++++++++++-- .../components/control/VariableControl.tsx | 15 +--------- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/gui/src/client/utils.ts b/gui/src/client/utils.ts index 2bc02aad..a8e2a112 100644 --- a/gui/src/client/utils.ts +++ b/gui/src/client/utils.ts @@ -39,6 +39,28 @@ export function replacePromptTokens(grid: PipelineGrid, params: Txt2ImgParams, c return result; } +export const MAX_SEED_SIZE = 32; +export const MAX_SEED = (2**MAX_SEED_SIZE) - 1; + +export function newSeed(): number { + return Math.floor(Math.random() * MAX_SEED); +} + +export function replaceRandomSeeds(key: string, values: Array): Array { + if (key !== 'seed') { + return values; + } + + return values.map((it) => { + // eslint-disable-next-line @typescript-eslint/no-magic-numbers + if (it === '-1' || it === -1) { + return newSeed(); + } + + return it; + }); +} + // eslint-disable-next-line max-params export function makeTxt2ImgGridPipeline(grid: PipelineGrid, model: ModelParams, params: Txt2ImgParams, upscale?: UpscaleParams, highres?: HighresParams): ChainPipeline { const pipeline: ChainPipeline = { @@ -53,10 +75,13 @@ export function makeTxt2ImgGridPipeline(grid: PipelineGrid, model: ModelParams, tiles: 8192, }; + const rows = replaceRandomSeeds(grid.rows.parameter, grid.rows.values); + const columns = replaceRandomSeeds(grid.columns.parameter, grid.columns.values); + let i = 0; - for (const row of grid.rows.values) { - for (const column of grid.columns.values) { + for (const row of rows) { + for (const column of columns) { const prompt = replacePromptTokens(grid, params, column, row); pipeline.stages.push({ diff --git a/gui/src/components/control/VariableControl.tsx b/gui/src/components/control/VariableControl.tsx index 09340b08..9a14cb3b 100644 --- a/gui/src/components/control/VariableControl.tsx +++ b/gui/src/components/control/VariableControl.tsx @@ -99,14 +99,8 @@ export const EXPR_NUMBER_RANGE = /^(\d+)-(\d+)$/; export function expandRanges(range: string): Array { if (EXPR_STRICT_NUMBER.test(range)) { - // entirely numeric, return without parsing + // entirely numeric, return after parsing const val = parseInt(range, 10); - - // eslint-disable-next-line @typescript-eslint/no-magic-numbers - if (val === -1) { - return [newSeed()]; - } - return [val]; } @@ -124,13 +118,6 @@ export function expandRanges(range: string): Array { return []; } -export const MAX_SEED_SIZE = 32; -export const MAX_SEED = (2**MAX_SEED_SIZE) - 1; - -export function newSeed(): number { - return Math.floor(Math.random() * MAX_SEED); -} - export const VARIABLE_PARAMETERS = ['prompt', 'negativePrompt', 'seed', 'steps', 'cfg', 'scheduler', 'eta', 'token']; export const STRING_PARAMETERS = ['prompt', 'negativePrompt', 'scheduler', 'token'];