From ff0e17174f8d93a71fdd5a4a80a4629bbf97f822 Mon Sep 17 00:00:00 2001 From: AUTOMATIC <16777216c@gmail.com> Date: Thu, 18 May 2023 20:16:09 +0300 Subject: 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 --- modules/generation_parameters_copypaste.py | 36 +++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 11 deletions(-) (limited to 'modules/generation_parameters_copypaste.py') diff --git a/modules/generation_parameters_copypaste.py b/modules/generation_parameters_copypaste.py index b34046a0..d5f0a49b 100644 --- a/modules/generation_parameters_copypaste.py +++ b/modules/generation_parameters_copypaste.py @@ -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 -- cgit v1.2.3