├── README.md └── improved_prompt_matrix.py /README.md: -------------------------------------------------------------------------------- 1 | # ⚠️ This script has been deprecated ⚠️ 2 | Please use the integrated [XYZ grid](https://github.com/AUTOMATIC1111/stable-diffusion-webui/blob/master/scripts/xyz_grid.py) or the [sd-dynamic-prompts](https://github.com/adieyal/sd-dynamic-prompts) extension instead. 3 | 4 | --- 5 | 6 | ## auto1111-improved-prompt-matrix 7 | 8 | This script is [advanced-prompt-matrix](https://github.com/GRMrGecko/stable-diffusion-webui-automatic/blob/advanced_matrix/scripts/advanced_prompt_matrix.py) modified to support `batch count`. 9 | 10 | ### Usage 11 | 12 | Use `<` `>` to create a group of alternate texts. Separate text options with `|`. Multiple groups and multiple options can be used. For example: 13 | 14 | An input of `a wearing ` 15 | Will output 4 prompts: `a corgi wearing goggles`, `a corgi wearing a hat`, `a cat wearing goggles`, `a cat wearing a hat` 16 | 17 | Each output prompt will be generated for each seed when using a `batch count` > 1. `batch size` is ignored. 18 | -------------------------------------------------------------------------------- /improved_prompt_matrix.py: -------------------------------------------------------------------------------- 1 | import re 2 | import gradio as gr 3 | import modules.shared as shared 4 | import modules.scripts as scripts 5 | import modules.sd_samplers 6 | from modules.processing import process_images, StableDiffusionProcessingTxt2Img 7 | 8 | rex = r'(<(?!lora:)([^>]+)>)' 9 | 10 | class Script(scripts.Script): 11 | def title(self): 12 | return "Improved prompt matrix" 13 | 14 | def ui(self, is_img2img): 15 | dummy = gr.Checkbox(label="Usage: a wearing ") 16 | return [dummy] 17 | 18 | def run(self, p, dummy): 19 | modules.processing.fix_seed(p) 20 | 21 | original_prompt = p.prompt[0] if type(p.prompt) == list else p.prompt 22 | 23 | matrix_count = 0 24 | prompt_matrix_parts = [] 25 | for data in re.finditer(rex, original_prompt): 26 | if data: 27 | matrix_count += 1 28 | span = data.span(1) 29 | items = data.group(2).split("|") 30 | prompt_matrix_parts.extend(items) 31 | 32 | all_prompts = [original_prompt] 33 | while True: 34 | found_matrix = False 35 | for this_prompt in all_prompts: 36 | for data in re.finditer(rex, this_prompt): 37 | if data: 38 | found_matrix = True 39 | # Remove last prompt as it has a found_matrix 40 | all_prompts.remove(this_prompt) 41 | span = data.span(1) 42 | items = data.group(2).split("|") 43 | for item in items: 44 | new_prompt = this_prompt[:span[0]] + item.strip() + this_prompt[span[1]:] 45 | all_prompts.append(new_prompt.strip()) 46 | break 47 | if found_matrix: 48 | break 49 | if not found_matrix: 50 | break 51 | 52 | total_images = len(all_prompts) * p.n_iter 53 | print(f"Prompt matrix will create {total_images} images") 54 | 55 | total_steps = p.steps * total_images 56 | if isinstance(p, StableDiffusionProcessingTxt2Img) and p.enable_hr: 57 | total_steps *= 2 58 | shared.total_tqdm.updateTotal(total_steps) 59 | 60 | p.prompt = all_prompts * p.n_iter 61 | p.seed = [item for item in range(int(p.seed), int(p.seed) + p.n_iter) for _ in range(len(all_prompts))] 62 | p.n_iter = total_images 63 | p.prompt_for_display = original_prompt 64 | 65 | return process_images(p) 66 | --------------------------------------------------------------------------------