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
This commit is contained in:
AUTOMATIC
2023-05-18 20:16:09 +03:00
parent 5ec2c294ee
commit ff0e17174f
5 changed files with 188 additions and 133 deletions

View File

@@ -1,5 +1,6 @@
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