Split normal/HR steps into two LatentImage/KSampler prompt entries
This commit is contained in:
@@ -39,17 +39,16 @@ const GroupKSampler = z.object({
|
|||||||
sampler_name: z.string(),
|
sampler_name: z.string(),
|
||||||
scheduler: z.string(),
|
scheduler: z.string(),
|
||||||
denoise: z.number().default(1.0)
|
denoise: z.number().default(1.0)
|
||||||
|
type: z.enum(["empty", "image", "upscale"]).optional()
|
||||||
})
|
})
|
||||||
export type ComfyBoxStdGroupKSampler = z.infer<typeof GroupKSampler>
|
export type ComfyBoxStdGroupKSampler = z.infer<typeof GroupKSampler>
|
||||||
|
|
||||||
const GroupLatentImage = z.object({
|
const GroupLatentImage = z.object({
|
||||||
width: z.number(),
|
width: z.number(),
|
||||||
height: 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_method: z.string().optional(),
|
||||||
upscale_by: z.number().optional(),
|
upscale_by: z.number().optional(),
|
||||||
upscale_width: z.number().optional(),
|
|
||||||
upscale_height: z.number().optional(),
|
|
||||||
crop: z.string().optional(),
|
crop: z.string().optional(),
|
||||||
mask_blur: z.number().optional(),
|
mask_blur: z.number().optional(),
|
||||||
batch_count: z.number().default(1).optional(),
|
batch_count: z.number().default(1).optional(),
|
||||||
|
|||||||
@@ -35,7 +35,9 @@ export default function convertA1111ToStdPrompt(infotext: A1111ParsedInfotext):
|
|||||||
|
|
||||||
const hrUp = popOpt("hires upscale");
|
const hrUp = popOpt("hires upscale");
|
||||||
const hrSz = popOpt("hires resize");
|
const hrSz = popOpt("hires resize");
|
||||||
|
let hrScaleBy = hrUp ? parseFloat(hrUp) : undefined;
|
||||||
let hrMethod = popOpt("hires upscaler");
|
let hrMethod = popOpt("hires upscaler");
|
||||||
|
let hrSteps = popOpt("hires steps");
|
||||||
let hrWidth = undefined
|
let hrWidth = undefined
|
||||||
let hrHeight = undefined
|
let hrHeight = undefined
|
||||||
if (hrSz) {
|
if (hrSz) {
|
||||||
@@ -51,10 +53,7 @@ export default function convertA1111ToStdPrompt(infotext: A1111ParsedInfotext):
|
|||||||
const latent_image: ComfyBoxStdGroupLatentImage = {
|
const latent_image: ComfyBoxStdGroupLatentImage = {
|
||||||
width: infotext.width,
|
width: infotext.width,
|
||||||
height: infotext.height,
|
height: infotext.height,
|
||||||
upscale_method: hrMethod,
|
// type: "empty", // detect txt2img???
|
||||||
upscale_by: hrUp ? parseFloat(hrUp) : undefined,
|
|
||||||
upscale_width: hrWidth,
|
|
||||||
upscale_height: hrHeight,
|
|
||||||
batch_count: infotext.batchSize,
|
batch_count: infotext.batchSize,
|
||||||
batch_pos: infotext.batchPos,
|
batch_pos: infotext.batchPos,
|
||||||
}
|
}
|
||||||
@@ -65,18 +64,54 @@ export default function convertA1111ToStdPrompt(infotext: A1111ParsedInfotext):
|
|||||||
|
|
||||||
parameters.latent_image = [latent_image];
|
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 [sampler_name, scheduler] = getSamplerAndScheduler(infotext.sampler)
|
||||||
|
|
||||||
const k_sampler: ComfyBoxStdGroupKSampler = {
|
const k_sampler: ComfyBoxStdGroupKSampler = {
|
||||||
steps: infotext.steps,
|
steps: infotext.steps,
|
||||||
seed: infotext.seed,
|
seed: infotext.seed,
|
||||||
cfg_scale: infotext.cfgScale,
|
cfg_scale: infotext.cfgScale,
|
||||||
denoise: infotext.denoise || 1.0,
|
denoise: hrMethod != null ? 1.0 : infotext.denoise || 1.0, // detect img2img???
|
||||||
sampler_name,
|
sampler_name,
|
||||||
scheduler,
|
scheduler,
|
||||||
}
|
}
|
||||||
parameters.k_sampler = [k_sampler];
|
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) {
|
if (infotext.modelHash || infotext.modelName) {
|
||||||
const checkpoint: ComfyBoxStdGroupCheckpoint = {
|
const checkpoint: ComfyBoxStdGroupCheckpoint = {
|
||||||
model_name: infotext.modelName,
|
model_name: infotext.modelName,
|
||||||
|
|||||||
@@ -124,15 +124,27 @@ export default class convertA1111ToStdPromptTests extends UnitTest {
|
|||||||
}],
|
}],
|
||||||
k_sampler: [{
|
k_sampler: [{
|
||||||
cfg_scale: 12,
|
cfg_scale: 12,
|
||||||
denoise: 0.55,
|
denoise: 1,
|
||||||
sampler_name: "dpmpp_2m",
|
sampler_name: "dpmpp_2m",
|
||||||
scheduler: "karras",
|
scheduler: "karras",
|
||||||
seed: 2416682767,
|
seed: 2416682767,
|
||||||
steps: 40
|
steps: 40
|
||||||
|
}, {
|
||||||
|
type: "upscale",
|
||||||
|
cfg_scale: 12,
|
||||||
|
denoise: 0.55,
|
||||||
|
sampler_name: "dpmpp_2m",
|
||||||
|
scheduler: "karras",
|
||||||
|
seed: 2416682767,
|
||||||
|
steps: 20
|
||||||
}],
|
}],
|
||||||
latent_image: [{
|
latent_image: [{
|
||||||
width: 640,
|
width: 640,
|
||||||
height: 512,
|
height: 512,
|
||||||
|
}, {
|
||||||
|
type: "upscale",
|
||||||
|
width: 1280,
|
||||||
|
height: 1024,
|
||||||
upscale_by: 2,
|
upscale_by: 2,
|
||||||
upscale_method: "Latent"
|
upscale_method: "Latent"
|
||||||
}]
|
}]
|
||||||
|
|||||||
Reference in New Issue
Block a user