├── cn3.png ├── en0.jpg ├── en1.jpg ├── en3.png ├── 00000-3545182370-extremely detailed CG,UHD wallpaper, Extreme details,(realistic_1.2),(((best quality))), ((ultra-detailed)), (cute detailed face.png ├── old ├── 00000-3918524003-extremely detailed CG,UHD wallpaper, Extreme details,(realistic_1.2),(((best quality))), ((ultra-detailed)), (cute detailed face.png ├── random_prompt.txt └── improved_prompt_matrix_random.txt ├── README.md └── random_prompt.py /cn3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huiyao8761380/random-prompt/HEAD/cn3.png -------------------------------------------------------------------------------- /en0.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huiyao8761380/random-prompt/HEAD/en0.jpg -------------------------------------------------------------------------------- /en1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huiyao8761380/random-prompt/HEAD/en1.jpg -------------------------------------------------------------------------------- /en3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huiyao8761380/random-prompt/HEAD/en3.png -------------------------------------------------------------------------------- /00000-3545182370-extremely detailed CG,UHD wallpaper, Extreme details,(realistic_1.2),(((best quality))), ((ultra-detailed)), (cute detailed face.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huiyao8761380/random-prompt/HEAD/00000-3545182370-extremely detailed CG,UHD wallpaper, Extreme details,(realistic_1.2),(((best quality))), ((ultra-detailed)), (cute detailed face.png -------------------------------------------------------------------------------- /old/00000-3918524003-extremely detailed CG,UHD wallpaper, Extreme details,(realistic_1.2),(((best quality))), ((ultra-detailed)), (cute detailed face.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huiyao8761380/random-prompt/HEAD/old/00000-3918524003-extremely detailed CG,UHD wallpaper, Extreme details,(realistic_1.2),(((best quality))), ((ultra-detailed)), (cute detailed face.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # random prompt 2 | 3 | it's script for stable diffusion webui 4 | 5 | [advanced-prompt-matrix](https://github.com/GRMrGecko/stable-diffusion-webui-automatic/blob/advanced_matrix/scripts/advanced_prompt_matrix.py) 6 | 7 | [auto1111-improved-prompt-matrix](https://github.com/ArrowM/auto1111-improved-prompt-matrix) 8 | 9 | [stable diffusion webui Custom Scripts](https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Custom-Scripts) 10 | 11 | ## Usage 12 | 13 | Use `【` `】` to create a group of alternate texts. Separate text options with `|`. For example: 14 | 15 | An input of`,【short|long|messy】 hair,` 16 | 17 | Will output random prompts: `,short hair,`,`,long hair,`,`,messy hair,` 18 | 19 | `Batch count`>=1,`Batch size`=1 20 | 21 | 22 | ## 用法 23 | 24 | 用 `【` `】` 创建一组替代文本。用 `|`分隔文本选项. 例如: 25 | 26 | 输入`,【short|long|messy】 hair,` 27 | 28 | 会输出随机提示: `,short hair,`,`,long hair,`,`,messy hair,` 29 | 30 | `Batch count`>=1,`Batch size`=1 31 | 32 | ## Select the script to run;选择脚本则可运行 33 | ![en0](https://github.com/huiyao8761380/auto1111-improved-prompt-matrix-random/blob/main/en0.jpg) 34 | ![en1](https://github.com/huiyao8761380/auto1111-improved-prompt-matrix-random/blob/main/en1.jpg) 35 | 36 | ## setup script: 37 | ![en3](https://github.com/huiyao8761380/auto1111-improved-prompt-matrix-random/blob/main/en3.png) 38 | ![cn3](https://github.com/huiyao8761380/auto1111-improved-prompt-matrix-random/blob/main/cn3.png) 39 | -------------------------------------------------------------------------------- /old/random_prompt.txt: -------------------------------------------------------------------------------- 1 | import re 2 | import random 3 | import gradio as gr 4 | import modules.shared as shared 5 | import modules.scripts as scripts 6 | import modules.sd_samplers 7 | from modules.processing import process_images, StableDiffusionProcessingTxt2Img 8 | 9 | #https://github.com/huiyao8761380/random-prompt 10 | # ,1girl, hair,, 11 | 12 | class Script(scripts.Script): 13 | def title(self): 14 | return "Random prompt v0.6" 15 | 16 | def ui(self, is_img2img): 17 | dummy = gr.Textbox(label="random prompt script has been started",value="Batch count>=1,Batch size=1,random tags are recommended at the end: , hair, ") 18 | sameseed = gr.Checkbox(label="Same seed generated.", value=False) 19 | return [dummy,sameseed] 20 | 21 | def run(self, p, dummy, sameseed): 22 | 23 | original_prompt = p.prompt[0] if type(p.prompt) == list else p.prompt 24 | 25 | all_prompts = [original_prompt] 26 | 27 | 28 | split_str=[''] 29 | right_str=[] 30 | gen_prompt='' 31 | new_prompt='' 32 | 33 | for this_prompt in all_prompts: 34 | for data in re.finditer(r'(<([^>]+)>)', this_prompt): 35 | if data: 36 | span = data.span(1) 37 | new_prompt = this_prompt[:span[0]] 38 | gen_prompt = this_prompt[span[0]:] 39 | this_str=gen_prompt.replace("<",">") 40 | split_str =this_str.split(">") 41 | break 42 | 43 | #print(f"new_prompt:{new_prompt}") 44 | #print(f"gen_prompt:{gen_prompt}") 45 | 46 | 47 | split_str[0]=split_str[0].strip() 48 | split_str[0]=split_str[0].strip(',') 49 | split_str[0]=split_str[0]+' ' 50 | for in_str in split_str: 51 | if "|" not in in_str: 52 | if "," in in_str: 53 | FL_str=in_str.split(",") 54 | right_str.append(FL_str[0]) 55 | right_str.append(FL_str[1]) 56 | else: 57 | right_str.append(in_str) 58 | #print (right_str) 59 | #print (len(right_str)) 60 | #d=int((len(right_str)-1)/2) 61 | #print(d) 62 | 63 | for ip in range(p.n_iter+1): 64 | 65 | my_prompt="" 66 | 67 | i=0 68 | for data in re.finditer(r'(<([^>]+)>)', gen_prompt): 69 | if data: 70 | 71 | items = data.group(2).split("|")#=list 72 | length=len(items)-1 73 | 74 | rand_item = items[random.randint(0,length)] 75 | 76 | rand_str=right_str[i]+rand_item+right_str[i+1] 77 | 78 | my_prompt=my_prompt+rand_str.strip()+"," 79 | i=i+2 80 | 81 | i_prompt=new_prompt+my_prompt 82 | all_prompts.append(i_prompt) 83 | #print(f"i_prompt:{i_prompt}") 84 | #print(f"all_prompts len:{len(all_prompts)}") 85 | 86 | if gen_prompt != '': 87 | all_prompts.remove(all_prompts[0]) 88 | 89 | 90 | p.prompt = all_prompts * p.n_iter #all_prompts * p.n_iter 91 | if sameseed == True: 92 | p.seed =[item for item in range(int(p.seed), int(p.seed) + p.n_iter) for _ in range(len(all_prompts))] 93 | #print(f"p.n_iter:{p.n_iter}") #=batch_count 94 | p.do_not_save_grid = True 95 | p.prompt_for_display = original_prompt 96 | 97 | return process_images(p) 98 | -------------------------------------------------------------------------------- /random_prompt.py: -------------------------------------------------------------------------------- 1 | import re 2 | import random 3 | import gradio as gr 4 | import modules.shared as shared 5 | import modules.scripts as scripts 6 | import modules.sd_samplers 7 | from modules.processing import process_images, StableDiffusionProcessingTxt2Img 8 | 9 | #https://github.com/huiyao8761380/random-prompt 10 | # ,1girl,【short|long|messy】 hair,【smile|blush|sad】, 11 | #Random prompt v0.7 因需要使用LORA模型的原因文本替换了'<|||>'为'【|||】' 12 | #能力有限-务必将随机tag置于末尾,因为就是这么设计的... 13 | 14 | class Script(scripts.Script): 15 | def title(self): 16 | return "Random prompt" 17 | 18 | def ui(self, is_img2img): 19 | dummy = gr.Textbox(label="random prompt script has been started",value="Batch count >=1,Batch size=1,random tags are recommended at the end: ,【short|long|messy】 hair, ") 20 | sameseed = gr.Checkbox(label="Same seed generated.", value=False) 21 | return [dummy,sameseed] 22 | 23 | def run(self, p, dummy, sameseed): 24 | 25 | original_prompt = p.prompt[0] if type(p.prompt) == list else p.prompt 26 | 27 | all_prompts = [original_prompt] 28 | 29 | 30 | split_str=[''] 31 | right_str=[] 32 | gen_prompt='' 33 | new_prompt='' 34 | 35 | for this_prompt in all_prompts: 36 | for data in re.finditer(r'(【([^】]+)】)', this_prompt): 37 | if data: 38 | span = data.span(1) 39 | new_prompt = this_prompt[:span[0]] 40 | gen_prompt = this_prompt[span[0]:] 41 | this_str=gen_prompt.replace("【","】") 42 | split_str =this_str.split("】") 43 | break 44 | 45 | #print(f"new_prompt:{new_prompt}") 46 | #print(f"gen_prompt:{gen_prompt}") 47 | 48 | 49 | split_str[0]=split_str[0].strip() 50 | split_str[0]=split_str[0].strip(',') 51 | split_str[0]=split_str[0]+' ' 52 | for in_str in split_str: 53 | if "|" not in in_str: 54 | if "," in in_str: 55 | FL_str=in_str.split(",") 56 | right_str.append(FL_str[0]) 57 | right_str.append(FL_str[1]) 58 | else: 59 | right_str.append(in_str) 60 | #print (right_str) 61 | #print (len(right_str)) 62 | #d=int((len(right_str)-1)/2) 63 | #print(d) 64 | 65 | for ip in range(p.n_iter+1): 66 | 67 | my_prompt="" 68 | 69 | i=0 70 | for data in re.finditer(r'(【([^】]+)】)', gen_prompt): 71 | if data: 72 | 73 | items = data.group(2).split("|")#=list 74 | length=len(items)-1 75 | 76 | rand_item = items[random.randint(0,length)] 77 | 78 | rand_str=right_str[i]+rand_item+right_str[i+1] 79 | 80 | my_prompt=my_prompt+rand_str.strip()+"," 81 | i=i+2 82 | 83 | i_prompt=new_prompt+my_prompt 84 | all_prompts.append(i_prompt) 85 | #print(f"i_prompt:{i_prompt}") 86 | #print(f"all_prompts len:{len(all_prompts)}") 87 | 88 | if gen_prompt != '': 89 | all_prompts.remove(all_prompts[0]) 90 | 91 | 92 | p.prompt = all_prompts * p.n_iter #all_prompts * p.n_iter 93 | if sameseed == True: 94 | p.seed =[item for item in range(int(p.seed), int(p.seed) + p.n_iter) for _ in range(len(all_prompts))] 95 | #print(f"p.n_iter:{p.n_iter}") #=batch_count 96 | p.do_not_save_grid = True 97 | p.prompt_for_display = original_prompt 98 | 99 | return process_images(p) 100 | -------------------------------------------------------------------------------- /old/improved_prompt_matrix_random.txt: -------------------------------------------------------------------------------- 1 | import re 2 | import random 3 | import gradio as gr 4 | import modules.shared as shared 5 | import modules.scripts as scripts 6 | import modules.sd_samplers 7 | from modules.processing import process_images, StableDiffusionProcessingTxt2Img 8 | 9 | 10 | class Script(scripts.Script): 11 | def title(self): 12 | return "Improved prompt matrix random" 13 | 14 | def ui(self, is_img2img): 15 | dummy = gr.Textbox(label="random script has been started",value="tag example: , hair,") 16 | sametag = gr.Checkbox(label="Same tag can be generated.", value=False) 17 | norand = gr.Checkbox(label="Not random,do each prompt", value=False) 18 | return [dummy,sametag,norand] 19 | 20 | def run(self, p, dummy,sametag,norand): 21 | #modules.processing.fix_seed(p) 22 | 23 | original_prompt = p.prompt[0] if type(p.prompt) == list else p.prompt 24 | 25 | matrix_count = 0 26 | prompt_matrix_parts = [] 27 | for data in re.finditer(r'(<([^>]+)>)', original_prompt): 28 | if data: 29 | matrix_count += 1 30 | span = data.span(1) 31 | items = data.group(2).split("|") 32 | prompt_matrix_parts.extend(items) 33 | 34 | all_prompts = [original_prompt] 35 | #只能叠4层到10w 36 | while True: 37 | found_matrix = False 38 | for this_prompt in all_prompts: 39 | for data in re.finditer(r'(<([^>]+)>)', this_prompt): 40 | if data: 41 | found_matrix = True 42 | # Remove last prompt as it has a found_matrix 43 | all_prompts.remove(this_prompt) 44 | span = data.span(1) 45 | items = data.group(2).split("|") 46 | #####length=len(items)-1 47 | #####for item in items: 48 | #####rand_item = items[random.randint(0,length)] 49 | #####new_prompt = this_prompt[:span[0]] + rand_item.strip() + this_prompt[span[1]:]#this_prompt=全长的prompt 50 | #####all_prompts.append(new_prompt.strip()) 51 | ###my_prompts.append(new_prompt.strip()) 52 | #####print(f"new prompt:{new_prompt}") 53 | #print(f"p.n_iter:{p.n_iter}")#=count 54 | for item in items: 55 | new_prompt = this_prompt[:span[0]] + item.strip() + this_prompt[span[1]:]#通过strip()去掉首尾空白字符 .span返回查找字的(首,尾) 56 | all_prompts.append(new_prompt.strip()) 57 | ######print(f"new prompt:{new_prompt}") 58 | break 59 | if found_matrix: 60 | break 61 | if not found_matrix: 62 | ###promptlength=len(my_prompts)-1 63 | ###rand_prompt = my_prompts[random.randint(0,promptlength)] 64 | ###all_prompts.append(rand_prompt) 65 | break 66 | 67 | promptlength=len(all_prompts)-1 68 | out_prompts = [] 69 | #rand_prompt = all_prompts[random.randint(0,promptlength)] 70 | if norand==False: 71 | for my_prompt in all_prompts: 72 | rand_i=random.randint(0,promptlength) 73 | out_prompts.append(all_prompts[rand_i]) 74 | if sametag==False: 75 | all_prompts.remove(all_prompts[rand_i])#大概随机不重复 76 | promptlength=len(all_prompts)-1# 77 | 78 | #print(f"out_prompts:{out_prompts}") 79 | 80 | total_images = len(all_prompts) * p.n_iter 81 | print(f"Prompt matrix will create {total_images} images") 82 | 83 | total_steps = p.steps * total_images 84 | if isinstance(p, StableDiffusionProcessingTxt2Img) and p.enable_hr: 85 | total_steps *= 2 86 | shared.total_tqdm.updateTotal(total_steps) 87 | 88 | 89 | 90 | 91 | #all_prompts.append(rand_prompt) 92 | if norand: 93 | p.prompt = all_prompts * p.n_iter #all_prompts * p.n_iter 94 | else: 95 | p.prompt = out_prompts*p.n_iter 96 | #p.seed =-1#[item for item in range(int(p.seed), int(p.seed) + p.n_iter) for _ in range(len(all_prompts))] 97 | p.n_iter = total_images 98 | #print(f"p.n_iter:{p.n_iter}") #=batch_count 99 | p.do_not_save_grid = True 100 | p.prompt_for_display = original_prompt 101 | 102 | return process_images(p) 103 | --------------------------------------------------------------------------------