refactoring
This commit is contained in:
@@ -15,8 +15,6 @@ __all__ = ["SendToNegativeScript"]
|
||||
|
||||
|
||||
class SendToNegativeScript(scripts.Script):
|
||||
NAME = "Send to Negative"
|
||||
VERSION = "0.3"
|
||||
|
||||
def __init__(self):
|
||||
self.logger = logging.getLogger(__name__)
|
||||
@@ -28,7 +26,7 @@ class SendToNegativeScript(scripts.Script):
|
||||
self.callbacks_added = True
|
||||
|
||||
def title(self):
|
||||
return f"{self.NAME} v{self.VERSION}"
|
||||
return f"{SendToNegative.NAME} v{SendToNegative.VERSION}"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
@@ -36,13 +34,13 @@ class SendToNegativeScript(scripts.Script):
|
||||
def process(self, p: StableDiffusionProcessing, *args, **kwargs):
|
||||
stn = SendToNegative(opts=opts, logger=self.logger)
|
||||
for i in range(len(p.all_prompts)):
|
||||
p.all_prompts[i], p.all_negative_prompts[i] = stn.processPrompts(
|
||||
p.all_prompts[i], p.all_negative_prompts[i] = stn.processPrompt(
|
||||
p.all_prompts[i], p.all_negative_prompts[i]
|
||||
)
|
||||
|
||||
|
||||
def on_ui_settings():
|
||||
section = ("send-to-negative", SendToNegativeScript.NAME)
|
||||
section = ("send-to-negative", SendToNegative.NAME)
|
||||
shared.opts.add_option(
|
||||
key="stn_tagstart",
|
||||
info=shared.OptionInfo(
|
||||
|
||||
+11
-5
@@ -3,9 +3,9 @@ import re
|
||||
|
||||
|
||||
class SendToNegative:
|
||||
"""
|
||||
This class contains the code independent of the webui interface
|
||||
"""
|
||||
|
||||
NAME = "Send to Negative"
|
||||
VERSION = "0.3"
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
@@ -20,14 +20,20 @@ class SendToNegative:
|
||||
logger=None,
|
||||
):
|
||||
"""
|
||||
Default format:
|
||||
Default format for the tag:
|
||||
<!content!>
|
||||
|
||||
<!!x!content!>
|
||||
|
||||
with x being:
|
||||
s - content is added at the start of the negative prompt. This is the default if no parameter exists.
|
||||
|
||||
e - content is added at the end of the negative prompt.
|
||||
|
||||
pN - content is added where the insertion point N is in the negative prompt or at the start if it does not exist. N can be 0 to 9.
|
||||
|
||||
iN - marks the position of insertion point N. Used only in the negative prompt and does not accept content. N can be 0 to 9.
|
||||
|
||||
The tags will be removed from the prompt or negative prompt without considering neighboring whitespace or separators.
|
||||
"""
|
||||
if logger is None:
|
||||
@@ -81,7 +87,7 @@ class SendToNegative:
|
||||
re.S,
|
||||
)
|
||||
|
||||
def processPrompts(self, original_prompt, original_negative_prompt):
|
||||
def processPrompt(self, original_prompt, original_negative_prompt):
|
||||
"""
|
||||
Extract from the prompt the marked parts and add them to the negative prompt
|
||||
"""
|
||||
|
||||
+3
-2
@@ -2,7 +2,7 @@ import unittest
|
||||
import sys
|
||||
import os
|
||||
|
||||
sys.path.insert(1, os.path.join(sys.path[0], '..'))
|
||||
sys.path.insert(1, os.path.join(sys.path[0], ".."))
|
||||
|
||||
from sendtonegative import SendToNegative
|
||||
|
||||
@@ -27,7 +27,8 @@ class TestSendToNegative(unittest.TestCase):
|
||||
expected_negative_prompt,
|
||||
stn=None,
|
||||
):
|
||||
result_prompt, result_negative_prompt = (self.defstn if stn is None else stn).processPrompts(
|
||||
theObj = self.defstn if stn is None else stn
|
||||
result_prompt, result_negative_prompt = theObj.processPrompt(
|
||||
prompt, negative_prompt
|
||||
)
|
||||
self.assertEqual(
|
||||
|
||||
Reference in New Issue
Block a user