aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAUTOMATIC1111 <16777216c@gmail.com>2024-02-11 12:23:04 +0300
committerAUTOMATIC1111 <16777216c@gmail.com>2024-02-11 12:23:21 +0300
commitb531b0bbef7802f5691b6ffbd389cd83f94ffb12 (patch)
treedc03fcce95c77c32e16cdb97396c39ca75894e6a
parente2b19900ec37ef517d8175a7d86c1925ca9f9e91 (diff)
add propmpt comments support
-rw-r--r--modules/processing_scripts/comments.py32
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."),
+}))