From ce42e49910cb4b2e9196c7b14c1dcdca05aba381 Mon Sep 17 00:00:00 2001 From: Vladimir Mandic Date: Wed, 3 Apr 2024 10:08:56 -0400 Subject: [PATCH] special case handle for prompt parser --- CHANGELOG.md | 2 +- extensions-builtin/stable-diffusion-webui-rembg | 2 +- modules/generation_parameters_copypaste.py | 7 +++++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 495026709..ab2fafc0b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,7 @@ - Control API scripts compatibility -## Update for 2024-04-02 +## Update for 2024-04-03 - **Features**: - **Gallery**: list, preview, search through all your images and videos! diff --git a/extensions-builtin/stable-diffusion-webui-rembg b/extensions-builtin/stable-diffusion-webui-rembg index 8985722e3..74f0a886c 160000 --- a/extensions-builtin/stable-diffusion-webui-rembg +++ b/extensions-builtin/stable-diffusion-webui-rembg @@ -1 +1 @@ -Subproject commit 8985722e34377a7c966fd3b5e02751922e777e44 +Subproject commit 74f0a886c3cb8b9d89b367cd18783e0c90560422 diff --git a/modules/generation_parameters_copypaste.py b/modules/generation_parameters_copypaste.py index 4cd5cda69..16318e1ae 100644 --- a/modules/generation_parameters_copypaste.py +++ b/modules/generation_parameters_copypaste.py @@ -195,7 +195,9 @@ def parse_generation_parameters(infotext, no_prompt=False): re_size = re.compile(r"^(\d+)x(\d+)$") # int x int basic_params = ['steps:', 'seed:', 'width:', 'height:', 'sampler:', 'size:', 'cfg scale:'] # first param is one of those - sanitized = infotext.replace('prompt:', 'Prompt:').replace('negative prompt:', 'Negative prompt:').replace('Negative Prompt', 'Negative prompt') # cleanup everything in brackets so re_params can work + infotext = infotext.replace('prompt:', 'Prompt:').replace('negative prompt:', 'Negative prompt:').replace('Negative Prompt', 'Negative prompt') # cleanup everything in brackets so re_params can work + infotext = infotext.replace(' Steps: ', ', Steps: ').replace('\nSteps: ', ', Steps: ') # fix cases where there is no delimiter between prompt and steps + sanitized = infotext sanitized = re.sub(r'<[^>]*>', lambda match: ' ' * len(match.group()), sanitized) sanitized = re.sub(r'\([^)]*\)', lambda match: ' ' * len(match.group()), sanitized) sanitized = re.sub(r'\{[^}]*\}', lambda match: ' ' * len(match.group()), sanitized) @@ -208,7 +210,7 @@ def parse_generation_parameters(infotext, no_prompt=False): else: try: first_param, first_param_idx = next((s, i) for i, s in enumerate(params) if any(x in s.lower() for x in basic_params)) - except Exception: + except Exception as e: first_param, first_param_idx = next(iter(params)), 0 if first_param_idx > 0: for _i in range(first_param_idx): @@ -218,6 +220,7 @@ def parse_generation_parameters(infotext, no_prompt=False): prompt = infotext[:params_idx] if negative_idx == -1 else infotext[:negative_idx] # prompt can be with or without negative prompt negative = infotext[negative_idx:params_idx] if negative_idx >= 0 else '' + negative = negative.strip().strip(',') for k, v in params.copy().items(): # avoid dict-has-changed if len(v) > 0 and v[0] == '"' and v[-1] == '"':