Add Image Iterate: nested multi-prompt still families.
Iterate runs a series of prompts as generate (no still), edit (still A), or compose (A+B), saves each output under one library collection like video extensions, and defaults to iterating from the original still.
This commit is contained in:
@@ -11,6 +11,7 @@ import { comfyJobPrefix } from '~/utils/outputNames'
|
||||
import { restorePromptParts, wrappedPromptForComfy } from '~/utils/promptParts'
|
||||
import { isXaigenStudio } from '~/utils/videoModels'
|
||||
import {
|
||||
imageV2GraphMode,
|
||||
imageV2StackSpecials,
|
||||
mergeLegacyImageV2Loras,
|
||||
parseImageV2Engine,
|
||||
@@ -52,20 +53,24 @@ export type EditV2RunParams = {
|
||||
export async function runEditV2(job: Job, params: EditV2RunParams) {
|
||||
const library = job.library
|
||||
if (!library) throw new Error('Edit job is missing library metadata')
|
||||
if (params.mode === 'refine' && !params.mask) {
|
||||
const graphMode = imageV2GraphMode(params.mode, {
|
||||
hasImage: Boolean(params.image),
|
||||
hasReference: Boolean(params.reference)
|
||||
})
|
||||
if (graphMode === 'refine' && !params.mask) {
|
||||
throw new Error('Refine requires a mask. Refusing to fall back to Edit.')
|
||||
}
|
||||
if (params.mode === 'compose' && !params.reference) {
|
||||
if (graphMode === 'compose' && !params.reference) {
|
||||
throw new Error('Compose requires image B. Refusing to fall back to one-image generation.')
|
||||
}
|
||||
if (params.mode === 'edit' && params.reference) {
|
||||
if (graphMode === 'edit' && params.reference && params.mode !== 'iterate') {
|
||||
throw new Error('Edit mode takes one image. Use Compose for two stills.')
|
||||
}
|
||||
if (params.mode !== 'generate' && !params.image) {
|
||||
if (graphMode !== 'generate' && !params.image) {
|
||||
throw new Error('This v2 mode requires still A.')
|
||||
}
|
||||
|
||||
const canChain = params.mode === 'edit' || params.mode === 'compose'
|
||||
const canChain = params.mode === 'iterate' || params.mode === 'edit' || params.mode === 'compose'
|
||||
const extraPasses = canChain
|
||||
? (params.passes || []).map(item => ({ prompt: String(item.prompt || '').trim() })).filter(item => item.prompt)
|
||||
: []
|
||||
@@ -78,8 +83,9 @@ export async function runEditV2(job: Job, params: EditV2RunParams) {
|
||||
...extraPasses.map(item => item.prompt)
|
||||
]
|
||||
const chainTotal = prompts.length
|
||||
const batch = params.passMode !== 'chain'
|
||||
const unit = batch ? 'Batch' : 'Pass'
|
||||
// Text-only iterate is always independent generations. With a still, honor batch vs chain.
|
||||
const batch = graphMode === 'generate' || params.passMode !== 'chain'
|
||||
const unit = params.mode === 'iterate' ? 'Iteration' : (batch ? 'Batch' : 'Pass')
|
||||
library.chainTotal = chainTotal
|
||||
library.familyId = chainTotal > 1 ? (library.familyId || crypto.randomUUID()) : library.familyId
|
||||
|
||||
@@ -96,7 +102,7 @@ export async function runEditV2(job: Job, params: EditV2RunParams) {
|
||||
job.imageComfyHost = getComfyHost()
|
||||
|
||||
await withImageComfyHost(job.imageComfyHost, async () => {
|
||||
const generate = params.mode === 'generate'
|
||||
const generate = graphMode === 'generate'
|
||||
const engine = parseImageV2Engine(params.engine, 'flux')
|
||||
const engineLabel = engine === 'krea' ? 'Krea' : 'Flux'
|
||||
const { applyImageFill } = await import('~/server/utils/imagePad')
|
||||
@@ -113,7 +119,7 @@ export async function runEditV2(job: Job, params: EditV2RunParams) {
|
||||
const krea = engine === 'krea' ? await resolveKreaGenerateAssets() : null
|
||||
const appliedStack = mergeLegacyImageV2Loras(params.loraStack?.length ? params.loraStack : library.loraStack, {
|
||||
engine,
|
||||
mode: params.mode,
|
||||
mode: graphMode,
|
||||
xaigen: isXaigenStudio(),
|
||||
snofsModel: params.snofsModel,
|
||||
snofsClip: params.snofsClip,
|
||||
@@ -127,7 +133,7 @@ export async function runEditV2(job: Job, params: EditV2RunParams) {
|
||||
const consistencyModel = appliedSpecials.consistency?.strengthModel ?? params.consistencyModel
|
||||
const consistencyClip = appliedSpecials.consistency?.strengthClip ?? params.consistencyClip
|
||||
|
||||
if (!generate && params.mode === 'compose' && params.reference) {
|
||||
if (!generate && graphMode === 'compose' && params.reference) {
|
||||
uploadedRef = await uploadImage({
|
||||
...params.reference,
|
||||
filename: `ref_${params.reference.filename || 'image_b.png'}`
|
||||
@@ -163,17 +169,17 @@ export async function runEditV2(job: Job, params: EditV2RunParams) {
|
||||
emitChainJob(job, {
|
||||
type: 'status',
|
||||
message: generate
|
||||
? `Queueing ${engineLabel} generate on Beast...`
|
||||
: params.mode === 'refine'
|
||||
? `Queueing ${engineLabel} iterate generate on Beast...`
|
||||
: graphMode === 'refine'
|
||||
? 'Uploading canvas and mask to Beast...'
|
||||
: params.mode === 'compose' ? 'Uploading stills A and B to Beast...' : 'Uploading still A to Beast...',
|
||||
: graphMode === 'compose' ? 'Uploading stills A and B to Beast...' : 'Uploading still A to Beast...',
|
||||
progress: generate ? 12 : 8
|
||||
})
|
||||
|
||||
if (index === 0 && !generate && image) {
|
||||
const filled = await applyImageFill({
|
||||
image,
|
||||
mask: params.mode === 'refine' ? mask : null,
|
||||
mask: graphMode === 'refine' ? mask : null,
|
||||
aspect: params.aspect || 'auto'
|
||||
})
|
||||
image = filled.image
|
||||
@@ -199,7 +205,7 @@ export async function runEditV2(job: Job, params: EditV2RunParams) {
|
||||
prompt = composeFillPrompt(prompt, true)
|
||||
}
|
||||
|
||||
if (index === 0 && params.mode === 'refine' && mask && !uploadedMask) {
|
||||
if (index === 0 && graphMode === 'refine' && mask && !uploadedMask) {
|
||||
uploadedMask = await uploadImage({
|
||||
...mask,
|
||||
filename: `mask_${mask.filename || 'refine-mask.png'}`
|
||||
@@ -212,19 +218,21 @@ export async function runEditV2(job: Job, params: EditV2RunParams) {
|
||||
if (!generate) {
|
||||
emitChainJob(job, {
|
||||
type: 'status',
|
||||
message: params.mode === 'refine'
|
||||
? `Queueing ${engineLabel} v2 refine on Beast...`
|
||||
: params.mode === 'compose'
|
||||
? `Queueing ${engineLabel} v2 compose (${params.task}) on Beast...`
|
||||
: `Queueing ${engineLabel} v2 edit on Beast...`,
|
||||
message: params.mode === 'iterate'
|
||||
? `Queueing ${engineLabel} iterate (${graphMode}) on Beast...`
|
||||
: graphMode === 'refine'
|
||||
? `Queueing ${engineLabel} v2 refine on Beast...`
|
||||
: graphMode === 'compose'
|
||||
? `Queueing ${engineLabel} v2 compose (${params.task}) on Beast...`
|
||||
: `Queueing ${engineLabel} v2 edit on Beast...`,
|
||||
progress: 12
|
||||
})
|
||||
}
|
||||
|
||||
const built = buildImageV2Workflow({
|
||||
mode: params.mode,
|
||||
mode: graphMode,
|
||||
engine,
|
||||
task: params.task,
|
||||
task: generate ? 't2i' : params.task,
|
||||
prompt: wrappedPromptForComfy(library, prompt, index === 0 ? params.prompt : prompt),
|
||||
negative: params.negative,
|
||||
imageAName: uploaded?.name,
|
||||
@@ -305,7 +313,7 @@ export async function runEditV2(job: Job, params: EditV2RunParams) {
|
||||
kind: 'imagev2',
|
||||
mode: params.mode,
|
||||
engine,
|
||||
task: params.task,
|
||||
task: generate ? 't2i' : params.task,
|
||||
negative: params.negative,
|
||||
snofsModel,
|
||||
snofsClip,
|
||||
@@ -313,12 +321,12 @@ export async function runEditV2(job: Job, params: EditV2RunParams) {
|
||||
consistencyClip,
|
||||
steps: params.steps,
|
||||
cfg: params.cfg,
|
||||
megapixels: params.mode === 'generate' || !(params.megapixels > 0) ? undefined : params.megapixels,
|
||||
scaleToTotalPixels: params.mode === 'generate' ? undefined : params.megapixels > 0,
|
||||
megapixels: generate || !(params.megapixels > 0) ? undefined : params.megapixels,
|
||||
scaleToTotalPixels: generate ? undefined : params.megapixels > 0,
|
||||
turbo: params.turbo === true,
|
||||
strength: params.mode === 'generate' ? undefined : params.strength,
|
||||
width: params.mode === 'generate' ? params.width : undefined,
|
||||
height: params.mode === 'generate' ? params.height : undefined,
|
||||
strength: generate ? undefined : params.strength,
|
||||
width: generate ? params.width : undefined,
|
||||
height: generate ? params.height : undefined,
|
||||
aspect: params.aspect || 'auto',
|
||||
seed,
|
||||
sourceStillId: params.sourceStillId || library.stillId,
|
||||
@@ -362,7 +370,7 @@ export async function runEditV2(job: Job, params: EditV2RunParams) {
|
||||
emitChainJob(job, {
|
||||
type: 'complete',
|
||||
message: chainTotal > 1
|
||||
? `${engineLabel} v2 ${batch ? 'batch' : 'chain'} finished on Beast`
|
||||
? `${engineLabel} ${params.mode === 'iterate' ? 'iterate' : `v2 ${batch ? 'batch' : 'chain'}`} finished on Beast`
|
||||
: `${engineLabel} v2 finished on Beast`,
|
||||
progress: 100,
|
||||
stillId: still?.id,
|
||||
|
||||
Reference in New Issue
Block a user