1
0
Fork 0

feat: make enabling highres a parameter of its own

This commit is contained in:
Sean Sube 2023-07-02 19:07:59 -05:00
parent 3edf5e6c4d
commit 99c91a301c
Signed by: ssube
GPG Key ID: 3EED7B957D362AF1
7 changed files with 79 additions and 56 deletions

View File

@ -22,10 +22,15 @@ def stage_highres(
if chain is None: if chain is None:
chain = ChainPipeline() chain = ChainPipeline()
if not highres.enabled:
logger.debug("highres not enabled, skipping")
return chain
if highres.iterations < 1: if highres.iterations < 1:
logger.debug("no highres iterations, skipping") logger.debug("no highres iterations, skipping")
return chain return chain
for _i in range(highres.iterations):
if highres.method == "upscale": if highres.method == "upscale":
logger.debug("using upscaling pipeline for highres") logger.debug("using upscaling pipeline for highres")
stage_upscale_correction( stage_upscale_correction(

View File

@ -62,7 +62,6 @@ def run_txt2img_pipeline(
) )
# apply highres # apply highres
for _i in range(highres.iterations):
stage_highres( stage_highres(
stage, stage,
params, params,
@ -152,7 +151,6 @@ def run_img2img_pipeline(
) )
# highres, if selected # highres, if selected
for _i in range(highres.iterations):
stage_highres( stage_highres(
stage, stage,
params, params,
@ -234,8 +232,17 @@ def run_inpaint_pipeline(
noise_source=noise_source, noise_source=noise_source,
) )
# apply upscaling and correction, before highres
first_upscale, after_upscale = split_upscale(upscale)
if first_upscale:
stage_upscale_correction(
stage,
params,
upscale=first_upscale,
chain=chain,
)
# apply highres # apply highres
for _i in range(highres.iterations):
stage_highres( stage_highres(
stage, stage,
params, params,
@ -248,7 +255,7 @@ def run_inpaint_pipeline(
stage_upscale_correction( stage_upscale_correction(
stage, stage,
params, params,
upscale=upscale, upscale=after_upscale,
chain=chain, chain=chain,
) )
@ -303,7 +310,6 @@ def run_upscale_pipeline(
) )
# apply highres # apply highres
for _i in range(highres.iterations):
stage_highres( stage_highres(
stage, stage,
params, params,

View File

@ -421,12 +421,14 @@ class UpscaleParams:
class HighresParams: class HighresParams:
def __init__( def __init__(
self, self,
enabled: bool,
scale: int, scale: int,
steps: int, steps: int,
strength: float, strength: float,
method: Literal["bilinear", "lanczos", "upscale"] = "lanczos", method: Literal["bilinear", "lanczos", "upscale"] = "lanczos",
iterations: int = 1, iterations: int = 1,
): ):
self.enabled = enabled
self.scale = scale self.scale = scale
self.steps = steps self.steps = steps
self.strength = strength self.strength = strength
@ -441,6 +443,7 @@ class HighresParams:
def tojson(self): def tojson(self):
return { return {
"enabled": self.enabled,
"iterations": self.iterations, "iterations": self.iterations,
"method": self.method, "method": self.method,
"scale": self.scale, "scale": self.scale,

View File

@ -283,6 +283,7 @@ def upscale_from_request() -> UpscaleParams:
def highres_from_request() -> HighresParams: def highres_from_request() -> HighresParams:
enabled = get_boolean(request.args, "highres", get_config_value("highres"))
iterations = get_and_clamp_int( iterations = get_and_clamp_int(
request.args, request.args,
"highresIterations", "highresIterations",
@ -313,6 +314,7 @@ def highres_from_request() -> HighresParams:
get_config_value("highresStrength", "min"), get_config_value("highresStrength", "min"),
) )
return HighresParams( return HighresParams(
enabled,
scale, scale,
steps, steps,
strength, strength,

View File

@ -64,6 +64,9 @@
"max": 8192, "max": 8192,
"step": 8 "step": 8
}, },
"highres": {
"default": false
},
"highresIterations": { "highresIterations": {
"default": 1, "default": 1,
"min": 1, "min": 1,

View File

@ -123,6 +123,7 @@ export function appendUpscaleToURL(url: URL, upscale: UpscaleParams) {
export function appendHighresToURL(url: URL, highres: HighresParams) { export function appendHighresToURL(url: URL, highres: HighresParams) {
if (highres.enabled) { if (highres.enabled) {
url.searchParams.append('highres', String(highres.enabled));
url.searchParams.append('highresIterations', highres.highresIterations.toFixed(FIXED_INTEGER)); url.searchParams.append('highresIterations', highres.highresIterations.toFixed(FIXED_INTEGER));
url.searchParams.append('highresMethod', highres.highresMethod); url.searchParams.append('highresMethod', highres.highresMethod);
url.searchParams.append('highresScale', highres.highresScale.toFixed(FIXED_INTEGER)); url.searchParams.append('highresScale', highres.highresScale.toFixed(FIXED_INTEGER));

View File

@ -68,6 +68,9 @@
"max": 8192, "max": 8192,
"step": 8 "step": 8
}, },
"highres": {
"default": false
},
"highresMethod": { "highresMethod": {
"default": "lanczos", "default": "lanczos",
"keys": [ "keys": [