diff options
author | AUTOMATIC1111 <16777216c@gmail.com> | 2024-02-11 09:23:04 +0000 |
---|---|---|
committer | AUTOMATIC1111 <16777216c@gmail.com> | 2024-02-11 09:23:21 +0000 |
commit | b531b0bbef7802f5691b6ffbd389cd83f94ffb12 (patch) | |
tree | dc03fcce95c77c32e16cdb97396c39ca75894e6a /modules | |
parent | e2b19900ec37ef517d8175a7d86c1925ca9f9e91 (diff) | |
download | stable-diffusion-webui-gfx803-b531b0bbef7802f5691b6ffbd389cd83f94ffb12.tar.gz stable-diffusion-webui-gfx803-b531b0bbef7802f5691b6ffbd389cd83f94ffb12.tar.bz2 stable-diffusion-webui-gfx803-b531b0bbef7802f5691b6ffbd389cd83f94ffb12.zip |
add propmpt comments support
Diffstat (limited to 'modules')
-rw-r--r-- | modules/processing_scripts/comments.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/modules/processing_scripts/comments.py b/modules/processing_scripts/comments.py new file mode 100644 index 00000000..316356c7 --- /dev/null +++ b/modules/processing_scripts/comments.py @@ -0,0 +1,32 @@ +from modules import scripts, shared
+import re
+
+
+def strip_comments(text):
+ text = re.sub('(^|\n)#[^\n]*(\n|$)', '\n', text) # while line comment
+ text = re.sub('#[^\n]*(\n|$)', '\n', text) # in the middle of the line comment
+
+ return text
+
+
+class ScriptStripComments(scripts.Script):
+ def title(self):
+ return "Comments"
+
+ def show(self, is_img2img):
+ return scripts.AlwaysVisible
+
+ def process(self, p, *args):
+ if not shared.opts.enable_prompt_comments:
+ return
+
+ p.all_prompts = [strip_comments(x) for x in p.all_prompts]
+ p.all_negative_prompts = [strip_comments(x) for x in p.all_negative_prompts]
+
+ p.main_prompt = strip_comments(p.main_prompt)
+ p.main_negative_prompt = strip_comments(p.main_negative_prompt)
+
+
+shared.options_templates.update(shared.options_section(('sd', "Stable Diffusion", "sd"), {
+ "enable_prompt_comments": shared.OptionInfo(True, "Enable comments").info("Use # anywhere in the prompt to hide the text between # and the end of the line from the generation."),
+}))
|