first
parent
d165317275
commit
df7dbcdcb8
|
|
@ -1,2 +1,4 @@
|
|||
# stable-diffusion-webui-wildcards
|
||||
Wildcards
|
||||
# Wildcards
|
||||
An extension version of a script from https://github.com/jtkelm2/stable-diffusion-webui-1/blob/main/scripts/wildcards.py
|
||||
|
||||
Allows you to use `__name__` syntax in your prompt to get a random line from a file named `name.txt` in the wildcards directory.
|
||||
|
|
|
|||
|
|
@ -0,0 +1,33 @@
|
|||
import os
|
||||
import random
|
||||
|
||||
from modules import scripts
|
||||
|
||||
|
||||
class WildcardsScript(scripts.Script):
|
||||
def title(self):
|
||||
return "Simple wildcards"
|
||||
|
||||
def show(self, is_img2img):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def replace_wildcard(self, text):
|
||||
if " " in text:
|
||||
return text
|
||||
|
||||
replacement_file = os.path.join(scripts.basedir(), f"wildcards/{text}.txt")
|
||||
if os.path.exists(replacement_file):
|
||||
with open(replacement_file, encoding="utf8") as f:
|
||||
return random.choice(f.read().splitlines())
|
||||
|
||||
return text
|
||||
|
||||
def process(self, p):
|
||||
p.extra_generation_params["Wildcard prompt"] = p.all_prompts[0]
|
||||
|
||||
for i in range(len(p.all_prompts)):
|
||||
random.seed(p.all_seeds[i])
|
||||
|
||||
prompt = p.all_prompts[i]
|
||||
prompt = "".join(self.replace_wildcard(chunk) for chunk in prompt.split("__"))
|
||||
p.all_prompts[i] = prompt
|
||||
Loading…
Reference in New Issue