One-click character swap for videos: an open-source, local Higgsfield Genjutsu alternative built on ComfyUI and MiniMax H3, with FLUX.3 Klein relighting.
Add Keep original outline switch to Object swap change mode
D3voz7abd6c8f50c4
diff --git a/app/api/jobs/route.ts b/app/api/jobs/route.tsindex 631d2e1..4d95a28 100644--- a/app/api/jobs/route.ts+++ b/app/api/jobs/route.ts@@ -65,7 +65,8 @@ function parseObject(form: FormData) {const picture = entry instanceof File && entry.size > 0 && mode !== "remove" ? parsePicture(entry) : null;if (mode !== "remove" && !changeTo && !picture) throw new Error("Say what it becomes, or add a picture.");const settings: ObjectSettings = {- mode: mode as EditMode, target, changeTo, biggestOnly: form.get("biggest_only") === "true", margin: margin as ObjectMargin, ...parseRun(form),+ mode: mode as EditMode, target, changeTo, biggestOnly: form.get("biggest_only") === "true", keepOutline: form.get("keep_outline") === "true",+ margin: margin as ObjectMargin, ...parseRun(form),};return { picture, settings };}diff --git a/app/globals.css b/app/globals.cssindex 55c4753..58ac6d8 100644--- a/app/globals.css+++ b/app/globals.css@@ -102,7 +102,8 @@ video { width: 100%; border-radius: 12px; background: #000; max-height: 420px; }.segmented { display: flex; background: var(--panel-2); border-radius: 10px; padding: 3px; flex-wrap: wrap; }.segmented button { border: 0; background: none; padding: 6px 12px; border-radius: 8px; color: var(--muted); }.segmented button.on { background: var(--accent); color: var(--accent-ink); font-weight: 600; }-.toggle { cursor: pointer; }+.toggle { cursor: pointer; flex-wrap: nowrap; }+.toggle > span { flex: 1; }.toggle input { position: absolute; opacity: 0; pointer-events: none; }.toggle i { width: 42px; height: 24px; border-radius: 99px; background: var(--panel-2); border: 1px solid var(--line); position: relative; flex: none; }.toggle i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: var(--muted); transition: transform 0.15s; }diff --git a/components/openjutsu.tsx b/components/openjutsu.tsxindex 3729d3d..103d476 100644--- a/components/openjutsu.tsx+++ b/components/openjutsu.tsx@@ -151,6 +151,7 @@ export function Openjutsu() {const [changeTo, setChangeTo] = useState("");const [look, setLook] = useState<{ file: File; url: string } | null>(null);const [biggestOnly, setBiggestOnly] = useState(false);+ const [keepOutline, setKeepOutline] = useState(true);const [post, setPost] = useState<Post>("face");const [detailOn, setDetailOn] = useState(true);const [detail, setDetail] = useState(DETAIL.default);@@ -357,6 +358,7 @@ export function Openjutsu() {form.set("change_to", changeTo);if (look && editMode !== "remove") form.set("picture", look.file);form.set("biggest_only", String(biggestOnly));+ form.set("keep_outline", String(keepOutline));form.set("resolution", resolution);form.set("seed", String(seed));form.set("clip_seconds", String(clipSeconds));@@ -640,6 +642,13 @@ export function Openjutsu() {<i aria-hidden /></label>)}+ {mode === "object" && editMode === "change" && (+ <label className="setting toggle">+ <span>Keep original outline <small>On: the face, hands and arms around it stay exact, but the new look keeps the old shape (sleeves, length). Off: the shape can change (long hair to a bob, pants to a skirt), but edges near the face and hands may be lost.</small></span>+ <input type="checkbox" checked={keepOutline} onChange={(event) => setKeepOutline(event.target.checked)} />+ <i aria-hidden />+ </label>+ )}{mode === "simple" && (<div className="setting"><span>What to replace <small>What SAM tracks, in English: person, cat, dog, or a short description such as “black and white cat”. The biggest match is replaced.</small></span>diff --git a/lib/object.ts b/lib/object.tsindex ace4c76..8784b44 100644--- a/lib/object.ts+++ b/lib/object.ts@@ -16,6 +16,7 @@ export type ObjectSettings = {target: string; // what SAM tracks, several separated by commas; for background, what stayschangeTo: string; // what it becomes, or for remove what shows insteadbiggestOnly: boolean;+ keepOutline: boolean; // change: send the grey shape, which keeps the face and hands around it but also the old outlineresolution: Resolution;motion: MotionSize;margin: ObjectMargin;@@ -59,8 +60,8 @@ export function pruneObject(source: ApiGraph, picture: boolean, settings: Objectdelete plan.picture_1_text;delete ref["ref_images.ref_image_0"];}- // H3 copies a grey shape's colour and cut, so a changed top would keep the old silhouette and a removed object would come back grey.- if (settings.mode !== "background") {+ // H3 copies a grey shape's outline, so a changed top keeps the old silhouette and a removed object would come back grey.+ if (settings.mode === "remove" || settings.mode === "change" && !settings.keepOutline) {delete ref["ref_videos.ref_video_0"];delete ref["ref_video_audios.ref_video_audio_0"];}@@ -80,6 +81,7 @@ export function pruneObject(source: ApiGraph, picture: boolean, settings: Objectmode: settings.mode,target: settings.target,change_to: settings.changeTo,+ keep_outline: settings.keepOutline,resolution: settings.resolution,seed: settings.seed,clip_seconds: settings.clipSeconds,diff --git a/test/object.test.ts b/test/object.test.tsindex 75eb312..07bf6b3 100644--- a/test/object.test.ts+++ b/test/object.test.ts@@ -8,7 +8,7 @@ import { isLink, type ApiGraph } from "../lib/simple.ts";const graph: ApiGraph = JSON.parse(readFileSync(new URL("../workflows/object.api.json", import.meta.url), "utf8"));const settings = (mode: ObjectSettings["mode"]): ObjectSettings => ({- mode, target: "hair", changeTo: "pink hair", biggestOnly: true, resolution: "480p", motion: 512, margin: "loose", seed: 5, clipSeconds: 4,+ mode, target: "hair", changeTo: "pink hair", biggestOnly: true, keepOutline: false, resolution: "480p", motion: 512, margin: "loose", seed: 5, clipSeconds: 4,});const dangling = (g: ApiGraph) => Object.entries(g).flatMap(([id, node]) =>Object.entries(node.inputs).filter(([, v]) => isLink(v) && !g[v[0]]).map(([name]) => `${id}.${name}`));@@ -46,9 +46,12 @@ test("without a picture the picture branch goes", () => {assert.ok(!titles(pruned).includes(OBJECT_PICTURE));});-test("change drops the grey motion reference", () => {+test("change drops the grey motion reference unless the outline is kept", () => {const ref = node(pruneObject(graph, true, settings("change")), "Reference Conditioning").inputs;assert.deepEqual(Object.keys(ref).filter((name) => name.startsWith("ref_")), ["ref_image_size", "ref_images.ref_image_0"]);+ const kept = pruneObject(graph, true, { ...settings("change"), keepOutline: true });+ assert.ok(node(kept, "Reference Conditioning").inputs["ref_videos.ref_video_0"]);+ assert.equal(node(kept, "Object Swap Plan (what to change)").inputs.keep_outline, true);});test("remove drops the picture and the grey motion reference", () => {