Commit ff0e1717 authored by AUTOMATIC's avatar AUTOMATIC
Browse files

rework hires prompts/sampler code to among other things support different...

rework hires prompts/sampler code to among other things support different extra networks in first/second pass
rework quoting for infotext items that have commas in them to use json (should be backwards compatible except for cases where it didn't work previously)
add some locals from processing function into the Processing class as fields
parent 5ec2c294
Loading
Loading
Loading
Loading
+25 −11
Original line number Diff line number Diff line
import base64
import io
import json
import os
import re

@@ -34,13 +35,20 @@ def reset():


def quote(text):
    if ',' not in str(text):
    if ',' not in str(text) and '\n' not in str(text):
        return text

    text = str(text)
    text = text.replace('\\', '\\\\')
    text = text.replace('"', '\\"')
    return f'"{text}"'
    return json.dumps(text, ensure_ascii=False)


def unquote(text):
    if len(text) == 0 or text[0] != '"' or text[-1] != '"':
        return text

    try:
        return json.loads(text)
    except Exception:
        return text


def image_from_url_text(filedata):
@@ -261,7 +269,9 @@ Steps: 20, Sampler: Euler a, CFG scale: 7, Seed: 965400086, Size: 512x512, Model
    res["Negative prompt"] = negative_prompt

    for k, v in re_param.findall(lastline):
        v = v[1:-1] if v[0] == '"' and v[-1] == '"' else v
        if v[0] == '"' and v[-1] == '"':
            v = unquote(v)

        m = re_imagesize.match(v)
        if m is not None:
            res[f"{k}-1"] = m.group(1)
@@ -269,11 +279,6 @@ Steps: 20, Sampler: Euler a, CFG scale: 7, Seed: 965400086, Size: 512x512, Model
        else:
            res[k] = v

        if k.startswith("Hires prompt"):
            res["Hires prompt"] = v[1:][:-1].replace(';', ',')
        elif k.startswith("Hires negative prompt"):
            res["Hires negative prompt"] = v[1:][:-1].replace(';', ',')

    # Missing CLIP skip means it was set to 1 (the default)
    if "Clip skip" not in res:
        res["Clip skip"] = "1"
@@ -286,6 +291,15 @@ Steps: 20, Sampler: Euler a, CFG scale: 7, Seed: 965400086, Size: 512x512, Model
        res["Hires resize-1"] = 0
        res["Hires resize-2"] = 0

    if "Hires sampler" not in res:
        res["Hires sampler"] = "Use same sampler"

    if "Hires prompt" not in res:
        res["Hires prompt"] = ""

    if "Hires negative prompt" not in res:
        res["Hires negative prompt"] = ""

    restore_old_hires_fix_params(res)

    # Missing RNG means the default was set, which is GPU RNG
+149 −112

File changed.

Preview size limit exceeded, changes collapsed.

+4 −2

File changed.

Preview size limit exceeded, changes collapsed.

+2 −2
Original line number Diff line number Diff line
@@ -39,7 +39,7 @@ def txt2img(id_task: str, prompt: str, negative_prompt: str, prompt_styles, step
        hr_second_pass_steps=hr_second_pass_steps,
        hr_resize_x=hr_resize_x,
        hr_resize_y=hr_resize_y,
        hr_sampler=sd_samplers.samplers_for_img2img[hr_sampler_index - 1].name if hr_sampler_index != 0 else '---',
        hr_sampler_name=sd_samplers.samplers_for_img2img[hr_sampler_index - 1].name if hr_sampler_index != 0 else None,
        hr_prompt=hr_prompt,
        hr_negative_prompt=hr_negative_prompt,
        override_settings=override_settings,
+8 −6

File changed.

Preview size limit exceeded, changes collapsed.