Split normal/HR steps into two LatentImage/KSampler prompt entries

This commit is contained in:
space-nuko
2023-05-18 20:02:59 -05:00
parent 54bcc04d88
commit 6aeaa91f79
3 changed files with 55 additions and 9 deletions

View File

@@ -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<typeof GroupKSampler>
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(),

View File

@@ -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,

View File

@@ -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"
}]