mirror of
https://github.com/lllyasviel/stable-diffusion-webui-forge.git
synced 2026-02-08 00:49:56 +00:00
Fix for comments in prompts with styles (#1948)
(#1862) a fix for the 0.01% who use comments in prompts. Before this, styles could be considered part of a comment. strips comments from prompts first, then from each applied style before merge same process for extracting styles from prompts updated tooltips for toolbuttons to apply styles removed code made redundant by this change, from modules.processing_scripts.comments
This commit is contained in:
@@ -1,49 +1,13 @@
|
||||
from modules import scripts, shared, script_callbacks
|
||||
from modules import 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
|
||||
if shared.opts.enable_prompt_comments:
|
||||
text = re.sub('(^|\n)#[^\n]*(\n|$)', '\n', text) # whole 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)
|
||||
|
||||
if getattr(p, 'enable_hr', False):
|
||||
p.all_hr_prompts = [strip_comments(x) for x in p.all_hr_prompts]
|
||||
p.all_hr_negative_prompts = [strip_comments(x) for x in p.all_hr_negative_prompts]
|
||||
|
||||
p.hr_prompt = strip_comments(p.hr_prompt)
|
||||
p.hr_negative_prompt = strip_comments(p.hr_negative_prompt)
|
||||
|
||||
|
||||
def before_token_counter(params: script_callbacks.BeforeTokenCounterParams):
|
||||
if not shared.opts.enable_prompt_comments:
|
||||
return
|
||||
|
||||
params.prompt = strip_comments(params.prompt)
|
||||
|
||||
|
||||
script_callbacks.on_before_token_counter(before_token_counter)
|
||||
|
||||
|
||||
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."),
|
||||
}))
|
||||
|
||||
Reference in New Issue
Block a user