Skip to content

Commit

Permalink
Merge pull request #2 from w-e-w/fix-a-inconsequential-but-potential-…
Browse files Browse the repository at this point in the history
…issue

swap quotes instead of replace
  • Loading branch information
scraed authored Jan 5, 2024
2 parents a0ead4a + 3376b03 commit 312c8f8
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions scripts/CHGextension.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@
from modules.sd_samplers_cfg_denoiser import CFGDenoiser, catenate_conds, subscript_cond, pad_cond
from modules import script_callbacks

quote_swap = str.maketrans('\'"', '"\'')


def pares_infotext(infotext, params):
# parse infotext decode json string
try:
params['CHG'] = json.loads(params['CHG'].replace("'", '"'))
params['CHG'] = json.loads(params['CHG'].translate(quote_swap))
except Exception:
pass

Expand Down Expand Up @@ -667,7 +669,7 @@ def process(self, p, reg_ini, reg_range, ite, noise_base, chara_decay, res, lr,
checkbox, **kwargs):
if checkbox:
# info text will have to be written hear otherwise params.txt will not have the infotext of CHG
# write parameters to extra_generation_params["CHG"] as json dict with double quotes replaced by single quotes
# write parameters to extra_generation_params["CHG"] as json dict with double and single quotes swapped
parameters = {
'RegS': reg_ini,
'RegR': reg_range,
Expand All @@ -680,7 +682,7 @@ def process(self, p, reg_ini, reg_range, ite, noise_base, chara_decay, res, lr,
'AStrength': reg_w,
'AADim': aa_dim
}
p.extra_generation_params["CHG"] = json.dumps(parameters).replace('"', "'")
p.extra_generation_params["CHG"] = json.dumps(parameters).translate(quote_swap)

# Extension main process
# Type: (StableDiffusionProcessing, List<UI>) -> (Processed)
Expand Down

0 comments on commit 312c8f8

Please sign in to comment.