diff --git a/src/lib/ComfyBoxStdPrompt.ts b/src/lib/ComfyBoxStdPrompt.ts index de0c66a..af04ed3 100644 --- a/src/lib/ComfyBoxStdPrompt.ts +++ b/src/lib/ComfyBoxStdPrompt.ts @@ -39,17 +39,16 @@ const GroupKSampler = z.object({ sampler_name: z.string(), scheduler: z.string(), denoise: z.number().default(1.0) + type: z.enum(["empty", "image", "upscale"]).optional() }) export type ComfyBoxStdGroupKSampler = z.infer const GroupLatentImage = z.object({ width: z.number(), height: z.number(), - type: z.enum(["empty", "image", "image_upscale"]).optional(), + type: z.enum(["empty", "image", "upscale"]).optional(), upscale_method: z.string().optional(), upscale_by: z.number().optional(), - upscale_width: z.number().optional(), - upscale_height: z.number().optional(), crop: z.string().optional(), mask_blur: z.number().optional(), batch_count: z.number().default(1).optional(), diff --git a/src/lib/convertA1111ToStdPrompt.ts b/src/lib/convertA1111ToStdPrompt.ts index 8726a5e..82bc03a 100644 --- a/src/lib/convertA1111ToStdPrompt.ts +++ b/src/lib/convertA1111ToStdPrompt.ts @@ -35,7 +35,9 @@ export default function convertA1111ToStdPrompt(infotext: A1111ParsedInfotext): const hrUp = popOpt("hires upscale"); const hrSz = popOpt("hires resize"); + let hrScaleBy = hrUp ? parseFloat(hrUp) : undefined; let hrMethod = popOpt("hires upscaler"); + let hrSteps = popOpt("hires steps"); let hrWidth = undefined let hrHeight = undefined if (hrSz) { @@ -51,10 +53,7 @@ export default function convertA1111ToStdPrompt(infotext: A1111ParsedInfotext): const latent_image: ComfyBoxStdGroupLatentImage = { width: infotext.width, height: infotext.height, - upscale_method: hrMethod, - upscale_by: hrUp ? parseFloat(hrUp) : undefined, - upscale_width: hrWidth, - upscale_height: hrHeight, + // type: "empty", // detect txt2img??? batch_count: infotext.batchSize, batch_pos: infotext.batchPos, } @@ -65,18 +64,54 @@ export default function convertA1111ToStdPrompt(infotext: A1111ParsedInfotext): parameters.latent_image = [latent_image]; + if (hrMethod != null) { + let uw, uh; + if (hrScaleBy) { + uw = infotext.width * hrScaleBy; + uh = infotext.height * hrScaleBy; + } else { + if (hrWidth == null || hrHeight == null) + throw new Error("Highres prompt didn't have width/height!") + uw = +hrWidth; + uh = +hrHeight; + } + const hr_image: ComfyBoxStdGroupLatentImage = { + type: "upscale", + width: uw, + height: uh, + upscale_by: hrScaleBy, + batch_count: infotext.batchSize, + batch_pos: infotext.batchPos, + upscale_method: hrMethod + } + parameters.latent_image.push(hr_image) + } + const [sampler_name, scheduler] = getSamplerAndScheduler(infotext.sampler) const k_sampler: ComfyBoxStdGroupKSampler = { steps: infotext.steps, seed: infotext.seed, cfg_scale: infotext.cfgScale, - denoise: infotext.denoise || 1.0, + denoise: hrMethod != null ? 1.0 : infotext.denoise || 1.0, // detect img2img??? sampler_name, scheduler, } parameters.k_sampler = [k_sampler]; + if (hrMethod != null) { + const k_sampler_hr: ComfyBoxStdGroupKSampler = { + type: "upscale", + steps: hrSteps != null ? parseInt(hrSteps) : infotext.steps, + seed: infotext.seed, + cfg_scale: infotext.cfgScale, + denoise: infotext.denoise || 1.0, + sampler_name, + scheduler, + } + parameters.k_sampler.push(k_sampler_hr) + } + if (infotext.modelHash || infotext.modelName) { const checkpoint: ComfyBoxStdGroupCheckpoint = { model_name: infotext.modelName, diff --git a/src/tests/convertA1111ToStdPromptTests.ts b/src/tests/convertA1111ToStdPromptTests.ts index 23e691a..5ef0b9a 100644 --- a/src/tests/convertA1111ToStdPromptTests.ts +++ b/src/tests/convertA1111ToStdPromptTests.ts @@ -124,15 +124,27 @@ export default class convertA1111ToStdPromptTests extends UnitTest { }], k_sampler: [{ cfg_scale: 12, - denoise: 0.55, + denoise: 1, sampler_name: "dpmpp_2m", scheduler: "karras", seed: 2416682767, steps: 40 + }, { + type: "upscale", + cfg_scale: 12, + denoise: 0.55, + sampler_name: "dpmpp_2m", + scheduler: "karras", + seed: 2416682767, + steps: 20 }], latent_image: [{ width: 640, height: 512, + }, { + type: "upscale", + width: 1280, + height: 1024, upscale_by: 2, upscale_method: "Latent" }]