Skip to content

One-click character swap for videos: an open-source, local Higgsfield Genjutsu alternative built on ComfyUI and MiniMax H3, with FLUX.3 Klein relighting.

Name the object in Add mode when the request starts with a verb (#6)

mixbagdbc0dde462e5
diff --git a/lib/object.ts b/lib/object.ts
index e954bb7..c2668a0 100644
--- a/lib/object.ts
+++ b/lib/object.ts
@@ -50,12 +50,14 @@ export const OBJECT_VIDEO = "Source video";
export const OBJECT_PICTURE = "Picture 1";
export const objectTargets = (target: string) => target.split(",").map((t) => t.trim()).filter(Boolean);
+// What to add, without the verb people type first: the plan writes "Add <it> <where>", and "Add add a toy car" names no object.
+export const addedObject = (changeTo: string) => changeTo.replace(/^(?:add|insert|put)\s+/i, "");
// The picture describer names only what is copied from the picture, with about 20 more words for each thing.
// Asked for "the top", it described only the tee under an open flannel shirt, so layers are named outer first.
function describer(settings: ObjectSettings) {
const background = settings.mode === "background";
- const things = background ? ["place (the setting, its lighting and what is around)"] : settings.mode === "add" ? [settings.changeTo.replace(/^(?:a|an|the)\s+/i, "") || "main object"] : objectTargets(settings.target);
+ const things = background ? ["place (the setting, its lighting and what is around)"] : settings.mode === "add" ? [addedObject(settings.changeTo).replace(/^(?:a|an|the)\s+/i, "") || "main object"] : objectTargets(settings.target);
const named = things.length === 1 ? things[0] : things.slice(0, -1).join(", ") + " and the " + things.at(-1);
const words = 30 + 20 * things.length;
return {
@@ -110,6 +112,7 @@ export function pruneObject(source: ApiGraph, picture: boolean, settings: Object
if (settings.mode === "add") {
const placement = JSON.stringify(parsePlacement(settings.placement));
plan.placement = placement;
+ plan.change_to = addedObject(settings.changeTo);
plan.keep_outline = false;
ref["ref_videos.ref_video_0"] = [id("Motion reference for this clip"), 0];
graph.object_placement = { class_type: "H3ObjectPlacementMask", inputs: {
diff --git a/test/object.test.ts b/test/object.test.ts
index e7338a5..2f65835 100644
--- a/test/object.test.ts
+++ b/test/object.test.ts
@@ -100,6 +100,16 @@ test("adding an object uses placement keyframes and the original video, without
}
});
+test("adding drops a leading verb, so the plan and the picture describer name the object", () => {
+ const placement = [{ frame: 0, x: 0.3456, y: 0.7576, width: 0.2395, height: 0.0863 }];
+ for (const [changeTo, object] of [["add a toy car", "a toy car"], ["Insert a vase", "a vase"], ["a chocolate cake on a plate", "a chocolate cake on a plate"]]) {
+ const pruned = pruneObject(graph, true, { ...settings("add"), target: "on the table", changeTo, placement });
+ assert.equal(node(pruned, "Object Swap Plan (what to change)").inputs.change_to, object);
+ assert.ok(String(node(pruned, "Describe picture 1").inputs.prompt).startsWith(`Describe the ${object.replace(/^a /, "")} in this picture`));
+ }
+ assert.equal(node(pruneObject(graph, false, { ...settings("change"), changeTo: "add a toy car" }), "Object Swap Plan (what to change)").inputs.change_to, "add a toy car");
+});
+
test("add placements use the selected canvas and the model settings still reach generation", () => {
const pruned = pruneObject(graph, false, { ...settings("add"), placement: [{ frame: -24, x: 0.2, y: 0.4, width: 0.3, height: 0.2 }], resolution: { width: 640, height: 960 } });
applyModel(pruned, { ...DEFAULT_MODEL, steps: 8 });