From 53e83ad096cd974acd931dea68c51ab6547bd4b7 Mon Sep 17 00:00:00 2001 From: Michi Date: Wed, 14 Oct 2026 16:36:58 +0200 Subject: [PATCH] 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) --- adopt.py | 12 +++++++++--- generate.py | 32 +++++++++++++++++++++++++++----- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/adopt.py b/adopt.py index a622528..b24da2a 100644 --- a/adopt.py +++ b/adopt.py @@ -8,6 +8,7 @@ PictureBoxSizeMode.Zoom, so square keeps every icon the same visual size. py -3.12 adopt.py stat_health one sprite py -3.12 adopt.py stat_health life_baby several py -3.12 adopt.py --all every name in the prompt list + py -3.12 adopt.py --size 512 hero larger square (default 128) """ import glob import importlib @@ -27,7 +28,8 @@ MARGIN = 0.04 # share of the side left free around the icon ALPHA_THRESHOLD = 8 -def adopt(name): +def adopt(name, size=None): + size = size or SIZE raws = sorted(glob.glob(os.path.join(config.OUTPUT_DIR, f"{name}_raw_*.png")), key=os.path.getmtime) if not raws: @@ -44,7 +46,7 @@ def adopt(name): side = int(max(image.size) * (1 + 2 * MARGIN)) square = Image.new("RGBA", (side, side), (0, 0, 0, 0)) square.paste(image, ((side - image.width) // 2, (side - image.height) // 2)) - square = square.resize((SIZE, SIZE), Image.LANCZOS) + square = square.resize((size, size), Image.LANCZOS) os.makedirs(DEST, exist_ok=True) dest = os.path.join(DEST, f"{name}.png") @@ -73,6 +75,10 @@ def adopt_backdrop(name, width=1920, height=1080): if __name__ == "__main__": args = sys.argv[1:] + size = None + if len(args) >= 2 and args[0] == "--size": + size = int(args[1]) + args = args[2:] if not args: print(__doc__) sys.exit(1) @@ -81,5 +87,5 @@ if __name__ == "__main__": if args == ["--all"]: prompts = importlib.import_module(getattr(config, "PROMPTS_MODULE", "prompts_life")) args = [p[0] for p in prompts.PROMPTS] - ok = sum(adopt(n) for n in args) + ok = sum(adopt(n, size) for n in args) print(f"{ok}/{len(args)} adopted") diff --git a/generate.py b/generate.py index 81edf20..933dc8e 100644 --- a/generate.py +++ b/generate.py @@ -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: