From 2508f4f245a60e617e429df81b866fee98819673 Mon Sep 17 00:00:00 2001 From: Vladimir Mandic Date: Sun, 17 Mar 2024 09:32:41 -0400 Subject: [PATCH] add prompt comments using /* and */ --- CHANGELOG.md | 2 ++ modules/images.py | 1 - modules/processing.py | 1 + modules/styles.py | 9 +++++++++ wiki | 2 +- 5 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 54cf478e2..8988d9b12 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -140,6 +140,8 @@ Further details: - default theme updates and additional built-in theme *black-gray* - support models with their own YAML model config files - support models with their own JSON per-component config files, for example: `playground-v2.5_vae.config` + - prompt can have comments enclosed with `/*` and `*/` + comments are extracted from prompt and added to image metadata - **ROCm** - add **ROCm** 6.0 nightly option to installer, thanks @jicka - add *flash attention* support for rdna3, thanks @Disty0 diff --git a/modules/images.py b/modules/images.py index 41a3fa122..4e88f7477 100644 --- a/modules/images.py +++ b/modules/images.py @@ -294,7 +294,6 @@ def resize_image(resize_mode, im, width, height, upscaler_name=None, output_type from modules import masking res = fill(im, color=0) res, _mask = masking.outpaint(res) - res.save('/tmp/edge.png') if output_type == 'np': return np.array(res) return res diff --git a/modules/processing.py b/modules/processing.py index f0a458340..04cc81d7d 100644 --- a/modules/processing.py +++ b/modules/processing.py @@ -159,6 +159,7 @@ def process_images(p: StableDiffusionProcessing) -> Processed: sd_vae.reload_vae_weights() shared.prompt_styles.apply_styles_to_extra(p) + shared.prompt_styles.extract_comments(p) if not shared.opts.cuda_compile: sd_models.apply_token_merging(p.sd_model, p.get_token_merging_ratio()) sd_hijack_freeu.apply_freeu(p, shared.backend == shared.Backend.ORIGINAL) diff --git a/modules/styles.py b/modules/styles.py index 1f0ece4cf..44e3bb8e9 100644 --- a/modules/styles.py +++ b/modules/styles.py @@ -225,6 +225,15 @@ class StyleDatabase: s = self.find_style(style) apply_styles_to_extra(p, s) + def extract_comments(self, p): + if not isinstance(p.prompt, str): + return + match = re.search(r'/\*.*?\*/', p.prompt, flags=re.DOTALL) + if match: + comment = match.group() + p.prompt = p.prompt.replace(comment, '') + p.extra_generation_params['Comment'] = comment.replace('/*', '').replace('*/', '') + def save_styles(self, path, verbose=False): for name in list(self.styles): style = { diff --git a/wiki b/wiki index c452d6e07..cce47d042 160000 --- a/wiki +++ b/wiki @@ -1 +1 @@ -Subproject commit c452d6e07bdaec618161d7d5fa2cf30c41f180bb +Subproject commit cce47d0428c61346b43a52d77a581154c3cfa3e8