generate: per-prompt SIZES and several names/--all; adopt: --size

Optional and backward compatible: SIZES = {name: (w, h)} in the prompt
module overrides the latent/scheduler size, generate.py accepts several
names or --all (PROMPTS + BACKDROPS), adopt.py --size N for larger sprites.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-10-14 16:36:58 +02:00
parent 9b35c3a7cc
commit 53e83ad096
2 changed files with 36 additions and 8 deletions

View File

@@ -45,7 +45,11 @@ def escape_json_string(text):
return text.replace("\\", "\\\\").replace('"', '\\"').replace("\n", "\\n")
def build_workflow(name, positive_prompt, negative_prompt, seed):
# Knoten, deren width/height ein Eintrag in SIZES (Prompt-Modul) überschreibt.
SIZE_NODES = ("Flux2Scheduler", "EmptyFlux2LatentImage", "EmptyLatentImage", "EmptySD3LatentImage")
def build_workflow(name, positive_prompt, negative_prompt, seed, size=None):
text = load_workflow_template()
text = text.replace("{{CHECKPOINT}}", escape_json_string(getattr(config, "CHECKPOINT", "")))
text = text.replace("{{UNET}}", escape_json_string(getattr(config, "UNET_NAME", "")))
@@ -57,7 +61,12 @@ def build_workflow(name, positive_prompt, negative_prompt, seed):
text = text.replace("{{NEGATIVE}}", escape_json_string(negative_prompt))
text = text.replace("{{NAME}}", escape_json_string(name))
text = text.replace("{{SEED}}", str(seed))
return json.loads(text)
wf = json.loads(text)
if size:
for node in wf.values():
if node.get("class_type") in SIZE_NODES:
node["inputs"]["width"], node["inputs"]["height"] = size
return wf
def post_json(url, payload):
@@ -131,7 +140,9 @@ def list_models():
def run_one(name, positive_prompt, negative_prompt=None):
os.makedirs(config.OUTPUT_DIR, exist_ok=True)
seed = random.randint(1, 2**32 - 1)
wf = build_workflow(name, positive_prompt, negative_prompt or config.NEGATIVE_PROMPT, seed)
# optional: SIZES = {"name": (width, height)} im Prompt-Modul (Standard: Größe des Workflows)
size = getattr(prompts, "SIZES", {}).get(name)
wf = build_workflow(name, positive_prompt, negative_prompt or config.NEGATIVE_PROMPT, seed, size)
images = queue_and_wait(name, wf)
if not images:
print(f"[{name}] FAILED")
@@ -147,10 +158,21 @@ if __name__ == "__main__":
list_models()
sys.exit(0)
# ohne Argument: alle PROMPTS; --all: PROMPTS und BACKDROPS; sonst die genannten Namen
everything = list(prompts.PROMPTS) + list(getattr(prompts, "BACKDROPS", []))
todo = [p for p in everything if (p[0] == arg if arg else p in prompts.PROMPTS)]
names = sys.argv[1:]
if not names:
todo = list(prompts.PROMPTS)
elif names == ["--all"]:
todo = everything
else:
missing = [n for n in names if n not in {p[0] for p in everything}]
if missing:
print(f"No prompt named {', '.join(missing)} in {prompts.__name__}.py")
sys.exit(1)
todo = [p for n in names for p in everything if p[0] == n]
if not todo:
print(f"No prompt named '{arg}' in {prompts.__name__}.py" if arg else f"{prompts.__name__}.py has no PROMPTS entries.")
print(f"{prompts.__name__}.py has no PROMPTS entries.")
sys.exit(1)
for entry in todo: