Skip to content

armgit / fuobe

Public Imported from GitHub
0

The open creative studio on ComfyUI: images, video, 3D and audio on open weights, on your own GPU or the cloud. Camera motions, effects, apps, Cinema, Layers, Image to 3D and an AI agent.

No Higgsfield (O7): Ad Multiplier on Happy Horse binds its @images, keeps the sound, says what it cuts

Claude8b1b5709c186
diff --git a/src/lib/catalog/marketing.ts b/src/lib/catalog/marketing.ts
index 64f14dcf..e0403984 100644
--- a/src/lib/catalog/marketing.ts
+++ b/src/lib/catalog/marketing.ts
@@ -826,12 +826,13 @@ export function mentionedImages(prompt: string): number[] {
/**
* The images a model gets, and the prompt rewritten for it: the mentioned images first (then the
- * rest) up to the model's limit, renumbered; Kling reads "@Image1", the others "image 1".
+ * rest) up to the model's limit, renumbered; Kling and Happy Horse bind "@Image1" (their prompt
+ * fields say so), the others read "image 1".
*/
export function mentionsFor(prompt: string, images: string[], modelId: string, max: number): { prompt: string; images: string[]; dropped: number } {
const order = [...mentionedImages(prompt).filter((n) => n <= images.length), ...images.map((_, i) => i + 1)].filter((n, i, a) => a.indexOf(n) === i);
const used = order.slice(0, Math.max(0, max));
- const kling = modelId.startsWith("kling");
+ const kling = modelId.startsWith("kling") || modelId.startsWith("happy-horse");
const text = prompt.replace(/@image_(\d{1,2})\b/g, (all, d: string) => {
const at = used.indexOf(Number(d));
if (at < 0) return "the reference";
@@ -993,13 +994,20 @@ export const OPEN_SOUND_JOIN = { first: "oss-join-sound1", second: "oss-join-sou
/** The models the Ad Multiplier can recreate with, per engine (the first that's usable is the default). */
export const MULTIPLIER_MODELS: Record<Engine, ModelChoice[]> = {
cloud: [
- { id: "kling-o3", note: "Kling O3 edit, up to 4 @images" },
- { id: "happy-horse-video-edit", note: "Happy Horse video edit, up to 4 @images" },
+ { id: "kling-o3", note: "Kling O3 edit, up to 4 @images, keeps the sound · 15 s at most" },
+ { id: "happy-horse-video-edit", note: "Happy Horse video edit, up to 4 @images, keeps the sound · 15 s at most" },
{ id: "gemini-omni-flash", note: "Gemini Omni Flash edit, prompt only" },
],
open: [{ id: "fuobe-genjutsu-motion", note: "Fuobe Genjutsu · Motion (Wan Animate 2): your @image_1 takes over the performance" }],
};
+/**
+ * The longest part of the reference a cloud edit model recreates (docs/research/paid-model-apis-3/4.json): Kling O3's
+ * edit takes 3–15 s clips; Happy Horse's takes up to 60 s but returns at most the first 15 s (and bills the input
+ * seconds too). A longer selection is cut to its first seconds, and the run says so.
+ */
+export const MULTIPLIER_WINDOW: Readonly<Record<string, number>> = { "kling-o3": 15, "happy-horse-video-edit": 15 };
+
/** Ad Multiplier quality → the resolution sent; open models top out at 720p. */
export const multiplierResolution = (q: string, engine: Engine) => (engine === "open" && q === "1080p" ? "720p" : q);
diff --git a/src/server/marketing.ts b/src/server/marketing.ts
index bf80d599..5f7d5628 100644
--- a/src/server/marketing.ts
+++ b/src/server/marketing.ts
@@ -18,6 +18,7 @@ import {
mentionsFor,
MULTIPLIER,
MULTIPLIER_MODELS,
+ MULTIPLIER_WINDOW,
multiplierResolution,
OPEN_SOUND_JOIN,
overlayLayout,
@@ -788,6 +789,9 @@ function planAd(input: ClickToAdInput, ctx: { product: Product; brand?: BrandKit
// ---------------------------------------------------------------------------
// Ad Multiplier: a reference ad (4–30 s) → new versions (whole ad, or a new hook / CTA around it)
+/** How each cloud edit model is asked to keep the reference's own soundtrack. */
+const KEEP_SOUND: Record<string, Record<string, unknown>> = { "kling-o3": { keep_audio: true }, "happy-horse-video-edit": { audio_setting: "origin" } };
+
export function multiplierModel(input: Pick<MultiplierInput, "engine" | "modelId">): ModelDef {
const choices = keepOffered(MULTIPLIER_MODELS[input.engine], (c) => isOffered(c.id, input.engine));
const id = input.modelId && choices.some((c) => c.id === input.modelId) ? input.modelId : choices[0].id;
@@ -805,10 +809,9 @@ export interface MultiplierContext {
export function planMultiplier(input: MultiplierInput, ctx: MultiplierContext): RunPlan {
const open = input.engine === "open";
const start = Math.max(0, input.start ?? 0);
- const end = Math.min(input.duration, input.end ?? input.duration);
- const length = end - start;
+ const asked = Math.min(input.duration, input.end ?? input.duration);
+ const length = asked - start;
if (length < MULTIPLIER.minSeconds - 0.05 || length > MULTIPLIER.maxSeconds + 0.05) throw new PlanError("Video duration: 4-30 seconds");
- const trimmed = start > 0.05 || end < input.duration - 0.05;
const images = input.images ?? [];
const text = multiplierText({ mode: input.mode, prompt: input.prompt, hook: input.hook, cta: input.cta });
if (input.mode === "sections" && input.hook == null && input.cta == null) throw new PlanError("Turn on Change hook or Change CTA");
@@ -818,14 +821,20 @@ export function planMultiplier(input: MultiplierInput, ctx: MultiplierContext):
const notes: string[] = [];
const steps: Step[] = [];
const resolution = multiplierResolution(input.quality, input.engine);
+ // A cloud edit model that recreates a shorter part than the one selected gets its first seconds (MULTIPLIER_WINDOW).
+ const editModel = input.mode === "prompt" ? multiplierModel(input) : undefined;
+ const window = !open && editModel ? MULTIPLIER_WINDOW[editModel.id] : undefined;
+ const end = window && length > window + 0.05 ? start + window : asked;
+ if (end < asked) notes.push(`${editModel!.name} recreates up to ${window} s: the first ${window} s of your selection are used (move the selection for another part)`);
+ const trimmed = start > 0.05 || end < input.duration - 0.05;
if (trimmed) {
steps.push({ key: "clip", label: "Trimming the reference", request: { feature: step, modelId: M.trim, op: "trim", inputs: { video: input.video }, params: { startTime: round(start), endTime: round(end) } } });
}
const source = (slot: "video"): { inputs?: GenerationRequest["inputs"]; after?: string[]; chain?: ChainSlot[] } =>
trimmed ? { after: ["clip"], chain: [{ slot }] } : { inputs: { video: input.video } };
- if (input.mode === "prompt") {
- const model = multiplierModel(input);
+ if (editModel) {
+ const model = editModel;
const title = `Recreated ad · ${model.name}`;
if (open) {
// Wan Animate: the first image takes over the reference's performance; the original sound is laid back on.
@@ -859,8 +868,9 @@ export function planMultiplier(input: MultiplierInput, ctx: MultiplierContext):
}
if (images.length > 1) notes.push("Wan Animate uses one image (the first you mention)");
} else {
- const max = model.options.maxImages ?? 0;
- const m = mentionsFor(text, images, model.id, model.routes.some((r) => r.op === "v2v" && r.map?.images) ? max : 0);
+ // A model whose edit route takes no images (Gemini Omni Flash) edits from the prompt alone.
+ const max = model.routes.some((r) => r.op === "v2v" && r.map?.images) ? (model.options.maxImages ?? 0) : 0;
+ const m = mentionsFor(text, images, model.id, max);
if (m.dropped && images.length) notes.push(max ? `${model.name} takes ${max} images — the first ${max} you mention are used` : `${model.name} edits from the prompt alone; pick Kling O3 to use your images`);
const src = source("video");
steps.push({
@@ -872,7 +882,9 @@ export function planMultiplier(input: MultiplierInput, ctx: MultiplierContext):
op: "v2v",
prompt: m.prompt,
inputs: { ...src.inputs, ...(m.images.length && { images: m.images }) },
- params: { resolution, ...(model.id === "kling-o3" && { extra: { keep_audio: true } }) },
+ // The clip's length prices the edit (a v2v route sends none); the reference's own sound is kept (Kling's
+ // keep_audio, Happy Horse's audio_setting "origin").
+ params: { resolution, duration: round(end - start), ...(KEEP_SOUND[model.id] && { extra: KEEP_SOUND[model.id] }) },
chain: src.chain,
title,
batchTitle: title,
diff --git a/tests/marketing-api.test.ts b/tests/marketing-api.test.ts
index cdf8f5ee..79aacc5c 100644
--- a/tests/marketing-api.test.ts
+++ b/tests/marketing-api.test.ts
@@ -387,6 +387,38 @@ describe("Ad Multiplier", () => {
expect(() => mk.planMultiplier({ engine: "open", video: video(), duration: 12, mode: "prompt", quality: "720p" }, {})).toThrow(/Add an image/);
});
+ it("binds Happy Horse's @images, keeps the sound, and recreates at most 15 s on Kling and Happy Horse, saying so", async () => {
+ const { buildPayload } = await import("@/lib/catalog/payload");
+ const { planGeneration, routesFor } = await import("@/lib/catalog/plan");
+ const imgs = [upload("a.png"), upload("b.png")];
+ const v = video();
+ const hh = mk.planMultiplier({ engine: "cloud", video: v, duration: 30, images: imgs, mode: "prompt", prompt: "Swap the bottle for @image_2", quality: "720p", modelId: "happy-horse-video-edit" }, {});
+ // The first 15 s are cut first (Happy Horse returns at most 15 s and bills the input seconds too).
+ expect(hh.steps.map((s) => s.key)).toEqual(["clip", "edit"]);
+ expect(hh.steps[0].request.params).toEqual({ startTime: 0, endTime: 15 });
+ expect(hh.notes.join(" ")).toMatch(/Happy Horse Video Edit recreates up to 15 s: the first 15 s of your selection are used/);
+ const edit = hh.steps[1].request;
+ expect(edit).toMatchObject({ modelId: "happy-horse-video-edit", op: "v2v", prompt: "Swap the bottle for @Image1", params: { resolution: "720p", duration: 15, extra: { audio_setting: "origin" } } });
+ const model = getModel("happy-horse-video-edit")!;
+ const plan = planGeneration({ ...edit, inputs: { video: v, images: edit.inputs!.images } }, getModel, () => undefined);
+ const payload = buildPayload(routesFor(model, "v2v")[0].map!, { ...plan.params, prompt: plan.prompt, video: v, images: edit.inputs!.images });
+ expect(payload).toMatchObject({ prompt: "Swap the bottle for @Image1", reference_image_urls: [imgs[1], imgs[0]], video_url: v, audio_setting: "origin" });
+ expect(payload).not.toHaveProperty("duration");
+ // Within the window nothing is cut; the selection's own start is kept.
+ const short = mk.planMultiplier({ engine: "cloud", video: v, duration: 40, start: 20, end: 32, images: imgs, mode: "prompt", prompt: "x", quality: "720p", modelId: "happy-horse-video-edit" }, {});
+ expect(short.steps[0].request.params).toEqual({ startTime: 20, endTime: 32 });
+ expect(short.notes).toEqual([]);
+ // Kling O3's edit takes 3–15 s clips: the same cut; Gemini Omni Flash takes the whole selection.
+ const kling = mk.planMultiplier({ engine: "cloud", video: v, duration: 30, images: imgs, mode: "prompt", prompt: "x", quality: "720p" }, {});
+ expect(kling.steps[0].request.params).toEqual({ startTime: 0, endTime: 15 });
+ expect(kling.steps[1].request.params).toMatchObject({ duration: 15, extra: { keep_audio: true } });
+ const gemini = mk.planMultiplier({ engine: "cloud", video: v, duration: 30, images: imgs, mode: "prompt", prompt: "x", quality: "720p", modelId: "gemini-omni-flash" }, {});
+ expect(gemini.steps.map((s) => s.key)).toEqual(["edit"]);
+ expect(gemini.steps[0].request).toMatchObject({ params: { resolution: "720p", duration: 30 }, inputs: { video: v } });
+ expect(gemini.steps[0].request.inputs).not.toHaveProperty("images");
+ expect(gemini.notes).toEqual(["Gemini Omni Flash 1.1 edits from the prompt alone; pick Kling O3 to use your images"]);
+ });
+
it("adds a hook and a CTA around the original (trimmed first), from the frames the browser grabbed", () => {
const v = video();
const plain = mk.planMultiplier({ engine: "cloud", video: v, duration: 20, mode: "sections", hook: "Wait for it", cta: "Shop today", quality: "720p", firstFrame: upload("f.png"), lastFrame: upload("l.png") }, {});