mirror of
https://github.com/AUTOMATIC1111/stable-diffusion-webui.git
synced 2024-06-07 21:20:49 +00:00
Merge pull request #7371 from hoblin/master
[Prompt Matrix] Support for negative prompt + delimiter selector
This commit is contained in:
commit
fa4fe45403
@ -45,15 +45,39 @@ class Script(scripts.Script):
|
|||||||
return "Prompt matrix"
|
return "Prompt matrix"
|
||||||
|
|
||||||
def ui(self, is_img2img):
|
def ui(self, is_img2img):
|
||||||
put_at_start = gr.Checkbox(label='Put variable parts at start of prompt', value=False, elem_id=self.elem_id("put_at_start"))
|
gr.HTML('<br />')
|
||||||
different_seeds = gr.Checkbox(label='Use different seed for each picture', value=False, elem_id=self.elem_id("different_seeds"))
|
with gr.Row():
|
||||||
|
with gr.Column():
|
||||||
|
put_at_start = gr.Checkbox(label='Put variable parts at start of prompt',
|
||||||
|
value=False, elem_id=self.elem_id("put_at_start"))
|
||||||
|
with gr.Column():
|
||||||
|
# Radio buttons for selecting the prompt between positive and negative
|
||||||
|
prompt_type = gr.Radio(["positive", "negative"], label="Select prompt",
|
||||||
|
elem_id=self.elem_id("prompt_type"), value="positive")
|
||||||
|
with gr.Row():
|
||||||
|
with gr.Column():
|
||||||
|
different_seeds = gr.Checkbox(
|
||||||
|
label='Use different seed for each picture', value=False, elem_id=self.elem_id("different_seeds"))
|
||||||
|
with gr.Column():
|
||||||
|
# Radio buttons for selecting the delimiter to use in the resulting prompt
|
||||||
|
variations_delimiter = gr.Radio(["comma", "space"], label="Select delimiter", elem_id=self.elem_id(
|
||||||
|
"variations_delimiter"), value="comma")
|
||||||
|
return [put_at_start, different_seeds, prompt_type, variations_delimiter]
|
||||||
|
|
||||||
return [put_at_start, different_seeds]
|
def run(self, p, put_at_start, different_seeds, prompt_type, variations_delimiter):
|
||||||
|
|
||||||
def run(self, p, put_at_start, different_seeds):
|
|
||||||
modules.processing.fix_seed(p)
|
modules.processing.fix_seed(p)
|
||||||
|
# Raise error if promp type is not positive or negative
|
||||||
|
if prompt_type not in ["positive", "negative"]:
|
||||||
|
raise ValueError(f"Unknown prompt type {prompt_type}")
|
||||||
|
# Raise error if variations delimiter is not comma or space
|
||||||
|
if variations_delimiter not in ["comma", "space"]:
|
||||||
|
raise ValueError(f"Unknown variations delimiter {variations_delimiter}")
|
||||||
|
|
||||||
original_prompt = p.prompt[0] if type(p.prompt) == list else p.prompt
|
prompt = p.prompt if prompt_type == "positive" else p.negative_prompt
|
||||||
|
original_prompt = prompt[0] if type(prompt) == list else prompt
|
||||||
|
positive_prompt = p.prompt[0] if type(p.prompt) == list else p.prompt
|
||||||
|
|
||||||
|
delimiter = ", " if variations_delimiter == "comma" else " "
|
||||||
|
|
||||||
all_prompts = []
|
all_prompts = []
|
||||||
prompt_matrix_parts = original_prompt.split("|")
|
prompt_matrix_parts = original_prompt.split("|")
|
||||||
@ -66,16 +90,19 @@ class Script(scripts.Script):
|
|||||||
else:
|
else:
|
||||||
selected_prompts = [prompt_matrix_parts[0]] + selected_prompts
|
selected_prompts = [prompt_matrix_parts[0]] + selected_prompts
|
||||||
|
|
||||||
all_prompts.append(", ".join(selected_prompts))
|
all_prompts.append(delimiter.join(selected_prompts))
|
||||||
|
|
||||||
p.n_iter = math.ceil(len(all_prompts) / p.batch_size)
|
p.n_iter = math.ceil(len(all_prompts) / p.batch_size)
|
||||||
p.do_not_save_grid = True
|
p.do_not_save_grid = True
|
||||||
|
|
||||||
print(f"Prompt matrix will create {len(all_prompts)} images using a total of {p.n_iter} batches.")
|
print(f"Prompt matrix will create {len(all_prompts)} images using a total of {p.n_iter} batches.")
|
||||||
|
|
||||||
|
if prompt_type == "positive":
|
||||||
p.prompt = all_prompts
|
p.prompt = all_prompts
|
||||||
|
else:
|
||||||
|
p.negative_prompt = all_prompts
|
||||||
p.seed = [p.seed + (i if different_seeds else 0) for i in range(len(all_prompts))]
|
p.seed = [p.seed + (i if different_seeds else 0) for i in range(len(all_prompts))]
|
||||||
p.prompt_for_display = original_prompt
|
p.prompt_for_display = positive_prompt
|
||||||
processed = process_images(p)
|
processed = process_images(p)
|
||||||
|
|
||||||
grid = images.image_grid(processed.images, p.batch_size, rows=1 << ((len(prompt_matrix_parts) - 1) // 2))
|
grid = images.image_grid(processed.images, p.batch_size, rows=1 << ((len(prompt_matrix_parts) - 1) // 2))
|
||||||
|
Loading…
Reference in New Issue
Block a user