|
|
|
@ -10,7 +10,6 @@ from modules import images
|
|
|
|
from modules.processing import process_images, Processed
|
|
|
|
from modules.processing import process_images, Processed
|
|
|
|
from modules.shared import opts, cmd_opts, state
|
|
|
|
from modules.shared import opts, cmd_opts, state
|
|
|
|
import modules.sd_samplers
|
|
|
|
import modules.sd_samplers
|
|
|
|
from pprint import pprint
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def draw_xy_grid(xs, ys, x_label, y_label, cell):
|
|
|
|
def draw_xy_grid(xs, ys, x_label, y_label, cell):
|
|
|
|
@ -34,8 +33,7 @@ def draw_xy_grid(xs, ys, x_label, y_label, cell):
|
|
|
|
res.append(processed.images[0])
|
|
|
|
res.append(processed.images[0])
|
|
|
|
|
|
|
|
|
|
|
|
grid = images.image_grid(res, rows=len(ys))
|
|
|
|
grid = images.image_grid(res, rows=len(ys))
|
|
|
|
grid = images.draw_grid_annotations(
|
|
|
|
grid = images.draw_grid_annotations(grid, res[0].width, res[0].height, hor_texts, ver_texts)
|
|
|
|
grid, res[0].width, res[0].height, hor_texts, ver_texts)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
first_processed.images = [grid]
|
|
|
|
first_processed.images = [grid]
|
|
|
|
|
|
|
|
|
|
|
|
@ -73,8 +71,7 @@ class Script(scripts.Script):
|
|
|
|
raise ValueError(f"Unknown prompt type {prompt_type}")
|
|
|
|
raise ValueError(f"Unknown prompt type {prompt_type}")
|
|
|
|
# Raise error if variations delimiter is not comma or space
|
|
|
|
# Raise error if variations delimiter is not comma or space
|
|
|
|
if variations_delimiter not in ["comma", "space"]:
|
|
|
|
if variations_delimiter not in ["comma", "space"]:
|
|
|
|
raise ValueError(
|
|
|
|
raise ValueError(f"Unknown variations delimiter {variations_delimiter}")
|
|
|
|
f"Unknown variations delimiter {variations_delimiter}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
prompt = p.prompt if prompt_type == "positive" else p.negative_prompt
|
|
|
|
prompt = p.prompt if prompt_type == "positive" else p.negative_prompt
|
|
|
|
original_prompt = prompt[0] if type(prompt) == list else prompt
|
|
|
|
original_prompt = prompt[0] if type(prompt) == list else prompt
|
|
|
|
@ -86,8 +83,7 @@ class Script(scripts.Script):
|
|
|
|
prompt_matrix_parts = original_prompt.split("|")
|
|
|
|
prompt_matrix_parts = original_prompt.split("|")
|
|
|
|
combination_count = 2 ** (len(prompt_matrix_parts) - 1)
|
|
|
|
combination_count = 2 ** (len(prompt_matrix_parts) - 1)
|
|
|
|
for combination_num in range(combination_count):
|
|
|
|
for combination_num in range(combination_count):
|
|
|
|
selected_prompts = [text.strip().strip(',') for n, text in enumerate(
|
|
|
|
selected_prompts = [text.strip().strip(',') for n, text in enumerate(prompt_matrix_parts[1:]) if combination_num & (1 << n)]
|
|
|
|
prompt_matrix_parts[1:]) if combination_num & (1 << n)]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if put_at_start:
|
|
|
|
if put_at_start:
|
|
|
|
selected_prompts = selected_prompts + [prompt_matrix_parts[0]]
|
|
|
|
selected_prompts = selected_prompts + [prompt_matrix_parts[0]]
|
|
|
|
@ -99,28 +95,23 @@ class Script(scripts.Script):
|
|
|
|
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(
|
|
|
|
print(f"Prompt matrix will create {len(all_prompts)} images using a total of {p.n_iter} batches.")
|
|
|
|
f"Prompt matrix will create {len(all_prompts)} images using a total of {p.n_iter} batches.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if prompt_type == "positive":
|
|
|
|
if prompt_type == "positive":
|
|
|
|
p.prompt = all_prompts
|
|
|
|
p.prompt = all_prompts
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
p.negative_prompt = all_prompts
|
|
|
|
p.negative_prompt = all_prompts
|
|
|
|
p.seed = [p.seed + (i if different_seeds else 0)
|
|
|
|
p.seed = [p.seed + (i if different_seeds else 0) for i in range(len(all_prompts))]
|
|
|
|
for i in range(len(all_prompts))]
|
|
|
|
|
|
|
|
p.prompt_for_display = positive_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 << (
|
|
|
|
grid = images.image_grid(processed.images, p.batch_size, rows=1 << ((len(prompt_matrix_parts) - 1) // 2))
|
|
|
|
(len(prompt_matrix_parts) - 1) // 2))
|
|
|
|
grid = images.draw_prompt_matrix(grid, p.width, p.height, prompt_matrix_parts)
|
|
|
|
grid = images.draw_prompt_matrix(
|
|
|
|
|
|
|
|
grid, p.width, p.height, prompt_matrix_parts)
|
|
|
|
|
|
|
|
processed.images.insert(0, grid)
|
|
|
|
processed.images.insert(0, grid)
|
|
|
|
processed.index_of_first_image = 1
|
|
|
|
processed.index_of_first_image = 1
|
|
|
|
processed.infotexts.insert(0, processed.infotexts[0])
|
|
|
|
processed.infotexts.insert(0, processed.infotexts[0])
|
|
|
|
|
|
|
|
|
|
|
|
if opts.grid_save:
|
|
|
|
if opts.grid_save:
|
|
|
|
images.save_image(processed.images[0], p.outpath_grids, "prompt_matrix",
|
|
|
|
images.save_image(processed.images[0], p.outpath_grids, "prompt_matrix", extension=opts.grid_format, prompt=original_prompt, seed=processed.seed, grid=True, p=p)
|
|
|
|
extension=opts.grid_format, prompt=original_prompt, seed=processed.seed, grid=True, p=p)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return processed
|
|
|
|
return processed
|
|
|
|
|