Skip to content
Python

lab queue for unattended runs; face-swap with the face photo as the only reference; chameleon colors

neuregexd7e1907b8b6c
diff --git a/.gitignore b/.gitignore
index 7991d81..bc349a1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -8,3 +8,4 @@ lab/assets/*.png
__pycache__/
*.pyc
.venv/
+lab/queue/
diff --git a/README.md b/README.md
index 81cd6c6..9d32af7 100644
--- a/README.md
+++ b/README.md
@@ -123,7 +123,7 @@ command that makes every example. Add a line to the table there, not a folder by
| `asmr-product` | ASMR Add-On | `video` | product photo |
| `asmr-whisper` | ASMR Classic | `video` | your photo |
| `asmr-host` | ASMR Host | `video` | your photo |
-| `chameleon` | Chameleon | `morph` | product photo |
+| `chameleon` | Chameleon | `morph` | product photo, product colors |
| `magic-button` | Magic button | `video` | product photo |
| `truck-ad` | Truck Ad | `video` | product photo |
| `kick-ad` | Kick Ad | `video` | product photo |
@@ -232,6 +232,20 @@ the cases that read the same reference together so each reference is made once (
The groups write to `<run_id>-s1`, `-s2`… on the volume and come back merged into one `lab/results/<run_id>`, with one
`review.html`; `--pull <run_id>` merges them the same way.
+Runs can also come from a queue, so that someone working on the repo (an assistant included) can ask for a run
+without waiting for you to type it. You start the watcher once, in a terminal where `modal` is logged in:
+
+```sh
+python tools/lab_queue.py # watches lab/queue/; Ctrl+C stops it, a file lab/queue/STOP pauses it
+```
+
+A job is a file `lab/queue/<name>.job.json` such as `{"only": "tpl-face-swap,tplx-face-swap-*", "note": "why"}`. The
+watcher runs exactly `modal run lab/lab_modal.py --only <only>` (plus `--shards N` if the job asks, up to 4), one job
+at a time, saves the output to `<name>.log` and writes `<name>.done.json` with the exit code, the run id and the
+"N/M ok" line. It accepts nothing else: no deploy, no other command, only case ids and patterns that exist in
+`lab/cases.json`, at most 60 cases per job and 12 jobs a day (`--max-cases`, `--max-jobs`); a job outside that gets a
+`<name>.refused.json` with the reason. Your Modal login never leaves your machine.
+
`--detach` keeps the GPU job running if the terminal closes; the run id is printed at the start. Missing models are
downloaded first on a CPU container, so no GPU is billed while they arrive (the whole catalog is
close to 300 GB). Then one GPU container runs the cases, recording time and peak VRAM, and keeps going when one fails;
diff --git a/apps/chameleon/app.json b/apps/chameleon/app.json
index 8441fe3..a3da2f8 100644
--- a/apps/chameleon/app.json
+++ b/apps/chameleon/app.json
@@ -3,7 +3,7 @@
"id": "chameleon",
"name": "Chameleon",
"section": "video",
- "summary": "A chameleon appears on your product and takes its colors; the product stays as it is.",
+ "summary": "A chameleon in your product's colors appears on it; the product stays as it is.",
"higgsfield_feature": "Chameleon",
"pack": "video-ltx25",
"status": "ready",
@@ -11,7 +11,7 @@
"source": {
"template": "comfyui_workflow_templates video_ltx2_5_flf2v.json (0.1.115) + image_flux3_klein_distilled_image_edit.json",
"comfyui": "0.42.0",
- "notes": "Template app written by tools/template_apps.py: the workflow is apps/morph's (built by tools/build_apps.py) with a fixed Klein instruction for the last frame (node edit:4: \"Add a chameleon perched on top of this exact product. The chameleon's skin copies the product's colors and pattern exactly, so it blends into it. The product itself unchanged, same background, macro product photo.\"); the prompt below is fixed and \"Extra direction\" is appended to it."
+ "notes": "Template app written by tools/template_apps.py: the workflow is apps/morph's (built by tools/build_apps.py) with a fixed Klein instruction for the last frame (node edit:4: \"Add a chameleon perched on top of this exact product. The chameleon is {colors} on its head, back and tail, the same colors as the product, so it blends into it. The product itself unchanged, same background, macro product photo.\"); the prompt below is fixed and \"Extra direction\" is appended to it."
},
"inputs": [
{
@@ -29,6 +29,14 @@
}
]
},
+ {
+ "id": "colors",
+ "type": "text",
+ "label": "Product colors",
+ "default": "bright white with bold red patches",
+ "required": true,
+ "help": "The product's main colors; the chameleon takes them on, so it blends into the product."
+ },
{
"id": "details",
"type": "textarea",
@@ -40,6 +48,11 @@
"node": "251:252",
"field": "value",
"template": "A chameleon climbs up onto the product and its skin shifts to the product's own colors and pattern, it blinks and rolls one eye; soft jungle ambience. {details}"
+ },
+ {
+ "node": "edit:4",
+ "field": "text",
+ "template": "Add a chameleon perched on top of this exact product. The chameleon is {colors} on its head, back and tail, the same colors as the product, so it blends into it. The product itself unchanged, same background, macro product photo."
}
]
},
@@ -245,6 +258,7 @@
"test": {
"image": "test/portrait.png",
"duration": 4,
- "aspect": "landscape"
+ "aspect": "landscape",
+ "colors": "bright white with bold red patches"
}
}
diff --git a/apps/chameleon/workflow.api.json b/apps/chameleon/workflow.api.json
index f04f427..77874b7 100644
--- a/apps/chameleon/workflow.api.json
+++ b/apps/chameleon/workflow.api.json
@@ -677,7 +677,7 @@
"edit:2",
0
],
- "text": "Add a chameleon perched on top of this exact product. The chameleon's skin copies the product's colors and pattern exactly, so it blends into it. The product itself unchanged, same background, macro product photo."
+ "text": "Add a chameleon perched on top of this exact product. The chameleon is bright white with bold red patches on its head, back and tail, the same colors as the product, so it blends into it. The product itself unchanged, same background, macro product photo."
},
"_meta": {
"title": "Positive Prompt"
diff --git a/apps/face-swap/app.json b/apps/face-swap/app.json
index d4abca1..5085f93 100644
--- a/apps/face-swap/app.json
+++ b/apps/face-swap/app.json
@@ -11,7 +11,7 @@
"source": {
"template": "image_flux3_klein_distilled_image_edit.json",
"comfyui": "0.42.0",
- "notes": "Template app written by tools/template_apps.py: the workflow is apps/edit's (built by tools/build_apps.py) plus a second LoadImage on ReferenceMultiLatent's images.image1; the sampler starts from the first image (scaled to 1 MP, encoded) with a noise mask on the face oval that the native MediaPipe nodes find, grown by 16 px, so only the face is redrawn; the prompt below is fixed and \"Extra direction\" is appended to it."
+ "notes": "Template app written by tools/template_apps.py: the workflow is apps/edit's (built by tools/build_apps.py) plus a second LoadImage on ReferenceMultiLatent's images.image1; the sampler starts from the first image (scaled to 1 MP, encoded) with a noise mask on the face oval that the native MediaPipe nodes find, grown by 16 px, so only the face is redrawn, and the second image is Klein's only reference; the prompt below is fixed and \"Extra direction\" is appended to it."
},
"inputs": [
{
@@ -55,7 +55,7 @@
{
"node": "4",
"field": "text",
- "template": "Give the person in image 1 the face of the person in image 2: the eyes, nose, mouth, brows and face shape of image 2, blended into image 1's head angle, expression, lighting and skin tone. {details}"
+ "template": "Give this person the face of the person in image 1: the eyes, nose, mouth, brows and face shape of image 1, matching the head angle, expression, lighting and skin tone around it. {details}"
}
]
},
diff --git a/apps/face-swap/workflow.api.json b/apps/face-swap/workflow.api.json
index 2ac57ae..7d2d948 100644
--- a/apps/face-swap/workflow.api.json
+++ b/apps/face-swap/workflow.api.json
@@ -126,15 +126,11 @@
0
],
"images.image0": [
- "11",
+ "12",
0
],
"resolution": "resize",
- "resolution.megapixels": 1,
- "images.image1": [
- "12",
- 0
- ]
+ "resolution.megapixels": 1
},
"_meta": {
"title": "Set Reference Multi Latent"
diff --git a/lab/cases.json b/lab/cases.json
index 55e1a0a..b045f0e 100644
--- a/lab/cases.json
+++ b/lab/cases.json
@@ -528,8 +528,8 @@
"note": "ASMR Classic. Whispering and tapping; calm."},
{"id": "tpl-asmr-host", "showcase": true, "app": "asmr-host", "values": {"image": "@case:ref-fx-man-b", "aspect": "9:16 (Portrait Widescreen)"},
"note": "ASMR Host. Studio, mic, whisper."},
- {"id": "tpl-chameleon", "showcase": true, "app": "chameleon", "values": {"image": "@case:ref-fx-sneaker", "aspect": "landscape", "duration": 4},
- "note": "Chameleon. A white and red chameleon on the sneaker; the sneaker unchanged."},
+ {"id": "tpl-chameleon", "showcase": true, "app": "chameleon", "values": {"image": "@case:ref-fx-sneaker", "aspect": "landscape", "duration": 4, "colors": "bright white with bold red patches"},
+ "note": "Chameleon. A white and red chameleon on the sneaker; the sneaker unchanged (tplx-chameleon-m2, 24 Oct)."},
{"id": "tpl-magic-button", "showcase": true, "app": "magic-button", "values": {"image": "@case:ref-product", "aspect": "9:16 (Portrait Widescreen)"},
"note": "Magic button. Button, sparks, the bottle floats."},
{"id": "tpl-truck-ad", "showcase": true, "app": "truck-ad", "values": {"image": "@case:ref-product", "aspect": "16:9 (Widescreen)", "enhance": false},
diff --git a/tools/lab_queue.py b/tools/lab_queue.py
new file mode 100644
index 0000000..46f4759
--- /dev/null
+++ b/tools/lab_queue.py
@@ -0,0 +1,185 @@
+#!/usr/bin/env python3
+"""Lab queue: runs lab jobs that show up as files, one at a time, with your own Modal login.
+
+ python tools/lab_queue.py # watch lab/queue/ until Ctrl+C
+ python tools/lab_queue.py --once # run what is queued now, then exit
+ python tools/lab_queue.py --max-jobs 12 --max-cases 60
+
+Whoever wants a run (you, or an assistant working in this folder) writes lab/queue/<name>.job.json:
+
+ {"only": "tpl-face-swap,tplx-face-swap-*", "shards": 1, "note": "why this run"}
+
+The watcher runs exactly `modal run lab/lab_modal.py --only <only> [--shards N]` from the repo root, prints
+the output and saves it to lab/queue/<name>.log, then writes lab/queue/<name>.done.json (exit code, run id,
+"N/M ok", times) and renames the job to <name>.job.done.json. Nothing else can be asked for: no deploy, no other
+script, no extra arguments. "only" may hold case ids and fnmatch patterns from lab/cases.json and nothing else.
+
+Limits: at most --max-cases cases matched per job (default 60) and --max-jobs jobs per calendar day (default 12).
+A file lab/queue/STOP pauses it (jobs wait until the file is gone); a job over a limit is refused with a
+<name>.refused.json that says why.
+"""
+from __future__ import annotations
+
+import argparse
+import datetime as dt
+import json
+import os
+import re
+import shutil
+import subprocess
+import sys
+import time
+from fnmatch import fnmatch
+from pathlib import Path
+
+ROOT = Path(__file__).resolve().parent.parent
+QUEUE = ROOT / "lab" / "queue"
+NAME = re.compile(r"^[A-Za-z0-9_-]{1,80}$")
+ONLY = re.compile(r"^[a-z0-9*?,\-]{1,2000}$")
+
+
+def now() -> str:
+ return dt.datetime.now().isoformat(timespec="seconds")
+
+
+def case_ids() -> list[str]:
+ return [c["id"] for c in json.loads((ROOT / "lab" / "cases.json").read_text(encoding="utf-8"))["cases"]]
+
+
+def check_job(name: str, job: dict, max_cases: int) -> tuple[list[str] | None, str]:
+ """The case ids a job selects, or None and the reason it is refused."""
+ if not NAME.match(name):
+ return None, "job name must be letters, digits, - and _"
+ if set(job) - {"only", "shards", "note"}:
+ return None, f"unknown keys: {sorted(set(job) - {'only', 'shards', 'note'})}"
+ only = job.get("only")
+ if not isinstance(only, str) or not ONLY.match(only):
+ return None, "only must be case ids or patterns: a-z 0-9 - * ? and commas"
+ shards = job.get("shards", 1)
+ if not isinstance(shards, int) or not 1 <= shards <= 4:
+ return None, "shards must be 1 to 4"
+ ids = case_ids()
+ wanted = [w for w in only.split(",") if w]
+ unknown = [w for w in wanted if not any(fnmatch(i, w) for i in ids)]
+ if unknown:
+ return None, f"no case matches: {', '.join(unknown)}"
+ picked = sorted({i for w in wanted for i in ids if fnmatch(i, w)})
+ if len(picked) > max_cases:
+ return None, f"{len(picked)} cases is over the limit of {max_cases}"
+ return picked, ""
+
+
+def jobs_today() -> int:
+ today = dt.date.today().isoformat()
+ n = 0
+ for p in QUEUE.glob("*.done.json"):
+ try:
+ if json.loads(p.read_text(encoding="utf-8")).get("started", "").startswith(today):
+ n += 1
+ except (OSError, ValueError):
+ pass
+ return n
+
+
+def modal_cmd() -> list[str]:
+ exe = os.environ.get("LAB_QUEUE_MODAL") or shutil.which("modal")
+ return [exe] if exe else [sys.executable, "-m", "modal"]
+
+
+def run_job(name: str, job: dict, picked: list[str]) -> dict:
+ args = modal_cmd() + ["run", "lab/lab_modal.py", "--only", job["only"]]
+ if job.get("shards", 1) > 1:
+ args += ["--shards", str(job["shards"])]
+ log_path = QUEUE / f"{name}.log"
+ started, t0 = now(), time.time()
+ print(f"\n[{started}] {name}: {len(picked)} cases · {' '.join(args[1:])}", flush=True)
+ run_id, ok_line, rc = None, None, None
+ env = {**os.environ, "PYTHONUTF8": "1", "PYTHONIOENCODING": "utf-8"}
+ with open(log_path, "w", encoding="utf-8") as log:
+ log.write(f"# {started} {' '.join(args)}\n# note: {job.get('note', '')}\n")
+ proc = subprocess.Popen(args, cwd=ROOT, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=env,
+ text=True, encoding="utf-8", errors="replace", bufsize=1)
+ assert proc.stdout is not None
+ for line in proc.stdout:
+ log.write(line)
+ log.flush()
+ print(line, end="", flush=True)
+ m = re.search(r"lab[\\/]results[\\/](\d{8}-\d{6}-[a-z0-9]+)", line)
+ if m:
+ run_id = m.group(1)
+ m = re.match(r"^\s*(\d+/\d+ ok)\s*$", line)
+ if m:
+ ok_line = m.group(1)
+ rc = proc.wait()
+ return {"name": name, "job": job, "cases": picked, "returncode": rc, "run_id": run_id, "result": ok_line,
+ "started": started, "finished": now(), "seconds": round(time.time() - t0, 1), "log": log_path.name}
+
+
+def write_json(path: Path, data: dict) -> None:
+ tmp = path.with_suffix(path.suffix + ".tmp")
+ tmp.write_text(json.dumps(data, indent=2, ensure_ascii=False) + "\n", encoding="utf-8")
+ os.replace(tmp, path)
+
+
+def pass_once(max_jobs: int, max_cases: int) -> int:
+ """Run every queued job (oldest first). Returns how many ran."""
+ ran = 0
+ for path in sorted(QUEUE.glob("*.job.json"), key=lambda p: p.stat().st_mtime):
+ if (QUEUE / "STOP").exists():
+ print(f"[{now()}] STOP is there: {path.name} waits", flush=True)
+ break
+ name = path.name[: -len(".job.json")]
+ try:
+ job = json.loads(path.read_text(encoding="utf-8"))
+ except (OSError, ValueError) as e:
+ write_json(QUEUE / f"{name}.refused.json", {"name": name, "reason": f"not readable JSON: {e}", "at": now()})
+ path.rename(path.with_name(f"{name}.job.refused"))
+ continue
+ picked, why = check_job(name, job, max_cases)
+ if picked is not None and jobs_today() >= max_jobs:
+ picked, why = None, f"already {max_jobs} jobs today (--max-jobs)"
+ if picked is None:
+ print(f"[{now()}] {name} refused: {why}", flush=True)
+ write_json(QUEUE / f"{name}.refused.json", {"name": name, "job": job, "reason": why, "at": now()})
+ path.rename(path.with_name(f"{name}.job.refused"))
+ continue
+ running = path.with_name(f"{name}.job.running")
+ path.rename(running)
+ done = run_job(name, job, picked)
+ write_json(QUEUE / f"{name}.done.json", done)
+ running.rename(path.with_name(f"{name}.job.done"))
+ print(f"[{now()}] {name} finished: exit {done['returncode']}, {done['result']}, run {done['run_id']}", flush=True)
+ ran += 1
+ return ran
+
+
+def main(argv=None) -> int:
+ ap = argparse.ArgumentParser(description=__doc__.splitlines()[0])
+ ap.add_argument("--once", action="store_true", help="run what is queued, then exit")
+ ap.add_argument("--max-jobs", type=int, default=12, help="jobs per calendar day (default 12)")
+ ap.add_argument("--max-cases", type=int, default=60, help="cases a job may select (default 60)")
+ ap.add_argument("--every", type=float, default=15.0, help="seconds between looks at the queue")
+ a = ap.parse_args(argv)
+ try:
+ sys.stdout.reconfigure(errors="replace") # Windows consoles that cannot print ✓
+ except AttributeError:
+ pass
+ QUEUE.mkdir(parents=True, exist_ok=True)
+ # a job left running by a closed window is put back in the queue
+ for p in QUEUE.glob("*.job.running"):
+ p.rename(p.with_name(p.name[: -len(".running")] + ".json"))
+ if a.once:
+ pass_once(a.max_jobs, a.max_cases)
+ return 0
+ print(f"[{now()}] watching {QUEUE} (Ctrl+C to stop; create lab/queue/STOP to pause)", flush=True)
+ try:
+ while True:
+ pass_once(a.max_jobs, a.max_cases)
+ time.sleep(a.every)
+ except KeyboardInterrupt:
+ print("\nstopped", flush=True)
+ return 0
+
+
+if __name__ == "__main__":
+ sys.exit(main())
diff --git a/tools/template_apps.py b/tools/template_apps.py
index 21b481c..4926459 100644
--- a/tools/template_apps.py
+++ b/tools/template_apps.py
@@ -10,7 +10,8 @@ Each entry below is a Higgsfield app (its name in `feature`) rebuilt as a prompt
these bases, all workflows built by tools/build_apps.py:
edit FLUX 3 Image Klein's edit pipeline (apps/edit), one reference image
edit2 the same with a second reference image (a garment, another person, a face); with
- face_mask, MediaPipe finds the face in the first image and Klein redraws only that oval
+ face_mask, MediaPipe finds the face in the first image and Klein redraws only that oval,
+ with the second image as its only reference (with both, it copied the first face back)
z-image Z-Image Turbo (apps/z-image), text to image
video LTX-2.5 image-to-video (apps/video), with its own audio
qwen-edit Qwen-Image-Edit-2509 (apps/relight) with a different LoRA: Multiple Angles or next-scene
@@ -379,8 +380,8 @@ A("character-swap", "Character Swap", "Character Swap", "identity", "edit2", "Sc
[], SCENE, {}, "The woman sits in the cafe in the man's place and pose.", image2_label="Photo of the new person", ref2=WOMAN)
A("face-swap", "Face Swap", "Face Swap", "identity", "edit2", "Photo to edit",
"Puts the face from a second photo onto the first; for faces you own or have permission to use.",
- "Give the person in image 1 the face of the person in image 2: the eyes, nose, mouth, brows and face shape of image 2, blended into image 1's head "
- "angle, expression, lighting and skin tone.",
+ "Give this person the face of the person in image 1: the eyes, nose, mouth, brows and face shape of image 1, matching the head angle, expression, "
+ "lighting and skin tone around it.",
[], PERSON, {}, "Her portrait with the other woman's face; hair, jacket and background untouched.", image2_label="Photo of the face", ref2=WOMAN,
help_="Only faces you own or have permission to use.", face_mask=True)
@@ -406,12 +407,15 @@ A("asmr-host", "ASMR Host", "ASMR Host", "clips", "video", "Your photo",
"brush; close whispering sound.",
[], MAN, {"aspect": PORTRAIT}, "Studio, mic, whisper.")
A("chameleon", "Chameleon", "Chameleon", "ads", "morph", "Product photo",
- "A chameleon appears on your product and takes its colors; the product stays as it is.",
+ "A chameleon in your product's colors appears on it; the product stays as it is.",
"A chameleon climbs up onto the product and its skin shifts to the product's own colors and pattern, it blinks and rolls one eye; soft jungle ambience.",
- [], SNEAKER, {"aspect": "landscape", "duration": 4}, "A white and red chameleon on the sneaker; the sneaker unchanged.",
+ [txt("colors", "Product colors", "bright white with bold red patches", required=True,
+ help_="The product's main colors; the chameleon takes them on, so it blends into the product.")],
+ SNEAKER, {"aspect": "landscape", "duration": 4, "colors": "bright white with bold red patches"},
+ "A white and red chameleon on the sneaker; the sneaker unchanged (tplx-chameleon-m2, 24 Oct).",
defaults={"aspect": "landscape"},
- klein="Add a chameleon perched on top of this exact product. The chameleon's skin copies the product's colors and pattern exactly, so it blends into it. "
- "The product itself unchanged, same background, macro product photo.")
+ klein="Add a chameleon perched on top of this exact product. The chameleon is {colors} on its head, back and tail, the same colors as the product, "
+ "so it blends into it. The product itself unchanged, same background, macro product photo.")
A("magic-button", "Magic Button", "Magic button", "ads", "video", "Product photo",
"A glowing button turns the scene around your product magical.",
"A hand presses a big glowing button next to the product; the scene transforms into a magical world with floating sparks and soft light, the product "
@@ -528,7 +532,7 @@ def check() -> None:
assert t["id"] not in existing or (ROOT / "apps" / t["id"] / "app.json").exists() and "tools/template_apps.py" in (ROOT / "apps" / t["id"] / "app.json").read_text(encoding="utf-8"), f"{t['id']} is a hand-made app"
assert len(t["name"]) <= 40 and len(t["summary"]) <= 160, t["id"]
assert t["base"] in BASES, t["id"]
- used = set(re.findall(r"\{([a-z][a-z0-9_]*)\}", t["prompt"]))
+ used = set(re.findall(r"\{([a-z][a-z0-9_]*)\}", t["prompt"] + " " + (t["klein"] or "")))
have = {i["id"] for i in t["inputs"]}
assert used <= have, (t["id"], used - have)
assert have <= used, (t["id"], have - used)
@@ -542,7 +546,6 @@ def check() -> None:
assert (t["base"] == "qwen-edit") == (t["lora"] in QWEN_LORAS), t["id"]
assert (t["base"] == "morph") == bool(t["klein"]), t["id"]
assert not t["face_mask"] or t["base"] == "edit2", t["id"]
- assert not t["klein"] or not re.search(r"\{[a-z]", t["klein"]), (t["id"], "the Klein instruction is fixed")
for k in t["defaults"]:
assert k in BASES[t["base"]]["keep"], (t["id"], k)
for k in t["values"]: # lab values name the template's own inputs or the settings kept from the base app
@@ -562,8 +565,11 @@ def manifest(t: dict) -> dict:
"bind": [{"node": base["image2"][0], "field": base["image2"][1]}]})
inputs += t["inputs"]
# the default "" matters: an optional input with no value is skipped everywhere, and the template with it
+ binds = [{"node": base["prompt"][0], "field": base["prompt"][1], "template": t["prompt"] + " {details}"}]
+ if t["klein"] and re.search(r"\{[a-z]", t["klein"]): # the Klein instruction takes the template's own inputs too
+ binds.append({"node": base["klein"][0], "field": base["klein"][1], "template": t["klein"]})
inputs.append({"id": "details", "type": "textarea", "label": "Extra direction", "default": "", "help": "Added at the end of the app's prompt.",
- "bind": [{"node": base["prompt"][0], "field": base["prompt"][1], "template": t["prompt"] + " {details}"}]})
+ "bind": binds})
inputs += [{**keep[k], "default": t["defaults"][k]} if k in t["defaults"] else keep[k] for k in base["keep"]]
test = {"image": "test/portrait.png"} if base["image"] else {}
if base.get("image2"):
@@ -577,7 +583,7 @@ def manifest(t: dict) -> dict:
notes += " plus a second LoadImage on ReferenceMultiLatent's images.image1"
if t["face_mask"]:
notes += ("; the sampler starts from the first image (scaled to 1 MP, encoded) with a noise mask on the face oval that the native "
- "MediaPipe nodes find, grown by 16 px, so only the face is redrawn")
+ "MediaPipe nodes find, grown by 16 px, so only the face is redrawn, and the second image is Klein's only reference")
models = models + [FACE_MODEL]
credits = credits + ["MediaPipe Face Landmarker (Google, Apache-2.0), ComfyUI port: Comfy-Org/mediapipe"]
if t["base"] == "morph":
@@ -625,8 +631,11 @@ def workflow(t: dict) -> dict:
api["fm_latent"] = {"class_type": "SetLatentNoiseMask", "inputs": {"samples": ["fm_encode", 0], "mask": ["fm_grow", 0]},
"_meta": {"title": "Only the face is redrawn"}}
api["7"]["inputs"]["latent_image"] = ["fm_latent", 0]
- if t["base"] == "morph": # the last frame Klein draws is fixed per template
- api[base["klein"][0]]["inputs"][base["klein"][1]] = t["klein"]
+ api["17"]["inputs"]["images.image0"] = ["12", 0] # the face photo is the only reference: with both, Klein copied the first face back
+ del api["17"]["inputs"]["images.image1"]
+ if t["base"] == "morph": # the last frame Klein draws is fixed per template (placeholders filled with the defaults)
+ defaults = {i["id"]: i.get("default", "") for i in t["inputs"]}
+ api[base["klein"][0]]["inputs"][base["klein"][1]] = re.sub(r"\{([a-z][a-z0-9_]*)\}", lambda m: str(defaults.get(m.group(1), "")), t["klein"])
if t["lora"]: # the relight pipeline with another LoRA; node 14 prepends the Relight trigger, so it is blanked
api["10:118"]["inputs"]["lora_name"] = QWEN_LORAS[t["lora"]]["file"]
api["14"]["inputs"]["string_a"] = ""