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.

Enhance: no added look for H3 Max looks, which apply their own style

Adarshc93aca10a355
diff --git a/src/app/api/enhance/route.ts b/src/app/api/enhance/route.ts
index 6980e577..a3d1d537 100644
--- a/src/app/api/enhance/route.ts
+++ b/src/app/api/enhance/route.ts
@@ -1,8 +1,10 @@
import { enhancePrompt, writeLyrics } from "@/server/enhance";
+import { getModel } from "@/lib/catalog";
+import { appliesOwnStyle } from "@/lib/catalog/applied-style";
import type { MediaKind, Operation } from "@/lib/catalog/types";
export async function POST(request: Request) {
- const { prompt, kind, op, target, seconds, max } = (await request.json().catch(() => ({}))) as {
+ const { prompt, kind, op, target, seconds, max, modelId } = (await request.json().catch(() => ({}))) as {
prompt?: string;
kind?: MediaKind;
op?: Operation;
@@ -10,6 +12,8 @@ export async function POST(request: Request) {
target?: "lyrics";
seconds?: number;
max?: number;
+ /** The composer's model: one that puts its own look on the clip (an H3 Max look) gets no look of Fuobe's. */
+ modelId?: string;
};
if (!prompt?.trim()) return Response.json({ error: "Empty prompt" }, { status: 400 });
try {
@@ -18,7 +22,8 @@ export async function POST(request: Request) {
if (!lyrics) return Response.json({ error: "Writing lyrics needs the AI helper: pick Claude or a local model in Settings → AI helper", code: "no-llm" }, { status: 503 });
return Response.json({ lyrics });
}
- return Response.json({ prompt: await enhancePrompt(prompt, kind ?? "image", op ?? "t2i") });
+ const ownStyle = !!modelId && !!getModel(modelId)?.routes.some(appliesOwnStyle);
+ return Response.json({ prompt: await enhancePrompt(prompt, kind ?? "image", op ?? "t2i", { ownStyle }) });
} catch (e) {
return Response.json({ error: (e as Error).message }, { status: 502 });
}
diff --git a/src/components/studio/composer.tsx b/src/components/studio/composer.tsx
index 33cab79f..4a10f185 100644
--- a/src/components/studio/composer.tsx
+++ b/src/components/studio/composer.tsx
@@ -1021,7 +1021,7 @@ export function Composer({ docked }: { docked: boolean }) {
if (!draft.prompt.trim()) return toast("Write a short idea first, then enhance it");
setEnhancing(true);
try {
- const p = await enhance(draft.prompt, config.kind, op ?? (config.kind === "video" ? "t2v" : "t2i"));
+ const p = await enhance(draft.prompt, config.kind, op ?? (config.kind === "video" ? "t2v" : "t2i"), draft.modelId);
setDraft({ prompt: p });
} catch (e) {
toastError(e);
diff --git a/src/lib/api.ts b/src/lib/api.ts
index ae412ec7..9f1986b3 100644
--- a/src/lib/api.ts
+++ b/src/lib/api.ts
@@ -1094,13 +1094,13 @@ export function useClipFacts(url: string | undefined) {
});
}
-export async function enhance(prompt: string, kind: MediaKind, op: string): Promise<string> {
+export async function enhance(prompt: string, kind: MediaKind, op: string, modelId?: string): Promise<string> {
return (
await json<{ prompt: string }>(
await fetch("/api/enhance", {
method: "POST",
headers: { "Content-Type": "application/json" },
- body: JSON.stringify({ prompt, kind, op }),
+ body: JSON.stringify({ prompt, kind, op, modelId }),
}),
)
).prompt;
diff --git a/src/lib/catalog/applied-style.ts b/src/lib/catalog/applied-style.ts
new file mode 100644
index 00000000..38675284
--- /dev/null
+++ b/src/lib/catalog/applied-style.ts
@@ -0,0 +1,10 @@
+import type { ModelRoute } from "./types";
+
+/**
+ * Hosted routes that put their own look on whatever the prompt describes: fal's H3 Max looks (16-bit Pixel, Hand-drawn,
+ * Low Poly, Retro Toon 70s, VHS). Each endpoint's prompt field says "Describe the scene, action, camera and sound. The …
+ * style is applied automatically." Enhance adds no look of its own to their prompts (src/server/enhance.ts).
+ */
+export function appliesOwnStyle(route: Pick<ModelRoute, "provider" | "endpoint">): boolean {
+ return route.provider === "fal" && route.endpoint.startsWith("minimax/h3-max/styles/");
+}
diff --git a/src/server/enhance.ts b/src/server/enhance.ts
index 4c4c2176..ad590aec 100644
--- a/src/server/enhance.ts
+++ b/src/server/enhance.ts
@@ -20,7 +20,16 @@ Rules:
- For edits (an input image is attached), write an instruction that says what to change and what to keep.
- One paragraph, under 90 words, no preamble, no quotes around the answer, no lists.`;
-function instruction(prompt: string, kind: MediaKind, op: Operation): string {
+/**
+ * What the model a rewrite is for does by itself. ownStyle: it puts its own look on whatever the prompt describes (fal's H3
+ * Max looks, whose prompt field says "Describe the scene, action, camera and sound. The … style is applied automatically."),
+ * so the rewrite names no style, light, lens or film look, as Soul's enhancer does.
+ */
+export interface EnhanceHints {
+ ownStyle?: boolean;
+}
+
+function instruction(prompt: string, kind: MediaKind, op: Operation, hints: EnhanceHints = {}): string {
const what =
op === "edit" || op === "inpaint"
? "an image-editing instruction"
@@ -29,7 +38,10 @@ function instruction(prompt: string, kind: MediaKind, op: Operation): string {
? "a text-to-video prompt"
: "an image-to-video motion prompt (the first frame is already given; focus on motion and camera)"
: "a text-to-image prompt";
- return `Rewrite this as ${what}:\n\n${prompt}`;
+ const own = hints.ownStyle
+ ? "\n\nThe model applies its own visual style. Describe only the scene, the action, the camera and the sounds. Name no art style, lighting, lens or film look."
+ : "";
+ return `Rewrite this as ${what}:\n\n${prompt}${own}`;
}
/** A picture for a model that can see (Content Factory's reference frames): JPEG, PNG, GIF or WebP. */
@@ -155,9 +167,13 @@ export async function llmSeesImages(o: { ollamaOnly?: boolean } = {}): Promise<b
}
/** Deterministic fallback so the toggle always does something useful offline. */
-export function heuristicEnhance(prompt: string, kind: MediaKind, op: Operation): string {
+export function heuristicEnhance(prompt: string, kind: MediaKind, op: Operation, hints: EnhanceHints = {}): string {
const p = prompt.trim().replace(/[.\s]+$/, "");
if (op === "edit" || op === "inpaint") return `${p}. Keep everything else unchanged: identity, pose, framing, lighting and background.`;
+ // A model with its own look gets motion and camera only: Fuobe's light, lens and film look would fight it.
+ if (kind === "video" && hints.ownStyle) {
+ return op === "t2v" ? `${p}. Natural motion, smooth camera movement.` : `${p}. Natural, fluid motion that stays consistent with the first frame, smooth camera movement.`;
+ }
if (kind === "video") {
return op === "t2v"
? `${p}. Cinematic shot, natural motion, smooth camera movement, realistic physics, soft volumetric light, shallow depth of field, rich detail, 24fps film look.`
@@ -213,8 +229,8 @@ export function trimLyrics(words: string, max: number): string {
return out.length > max ? out.slice(0, max).trimEnd() : out;
}
-export async function enhancePrompt(prompt: string, kind: MediaKind, op: Operation): Promise<string> {
- return (await llmText(SYSTEM, instruction(prompt, kind, op))) ?? heuristicEnhance(prompt, kind, op);
+export async function enhancePrompt(prompt: string, kind: MediaKind, op: Operation, hints: EnhanceHints = {}): Promise<string> {
+ return (await llmText(SYSTEM, instruction(prompt, kind, op, hints))) ?? heuristicEnhance(prompt, kind, op, hints);
}
/**
diff --git a/src/server/generations.ts b/src/server/generations.ts
index 73f8c2e9..94c61096 100644
--- a/src/server/generations.ts
+++ b/src/server/generations.ts
@@ -130,6 +130,7 @@ import { fitStill } from "./fit-still";
import { renderPathVideo } from "./path-render";
import { songFormat, songToolProblem } from "@/lib/lyrics";
import { hostedUntested } from "@/lib/catalog/hosted-untested";
+import { appliesOwnStyle } from "@/lib/catalog/applied-style";
import { modelToFinish, startModelFinish, startTurntable, stopModelFinish, type OutputStore } from "./model3d-finish";
import { finishTask, pathOnWorker, poolFinishes3d, startWorkerModelFinish, stopWorkerFinish } from "./computer/finish";
import { PATH_FPS, PATH_FRAMES } from "@/lib/camera-path";
@@ -3462,7 +3463,7 @@ async function handOver(id: string, route: ModelRoute, providerId: ProviderId, p
// Soul: only the user's words are expanded (60–120 words of subject, wardrobe, place, light); the look stays as it is.
const longer = await enhanceSoulWords(words).catch(() => words);
prompt = prompt.slice(0, at) + longer + prompt.slice(at + words.length);
- } else prompt = await enhancePrompt(prompt, plan.model.kind, plan.op).catch(() => prompt);
+ } else prompt = await enhancePrompt(prompt, plan.model.kind, plan.op, { ownStyle: appliesOwnStyle(route) }).catch(() => prompt);
update(id, { prompt });
}
// Ideogram 4 reads a JSON caption (src/lib/ideogram-caption.ts): one given as the prompt (a reused run) is kept, plain
diff --git a/tests/h3max-look-enhance-button.test.ts b/tests/h3max-look-enhance-button.test.ts
new file mode 100644
index 00000000..a30648b0
--- /dev/null
+++ b/tests/h3max-look-enhance-button.test.ts
@@ -0,0 +1,35 @@
+import { describe, expect, it } from "vitest";
+import { tempDir } from "./helpers/temp-dir";
+
+/**
+ * The composer's Enhance button (/api/enhance) on an H3 Max look: fal's look endpoints apply their own style ("Describe the
+ * scene, action, camera and sound. The … style is applied automatically.", each endpoint's prompt field), so the rewrite
+ * adds no light, lens or film look of Fuobe's. Without a model, or for another model, the full rewrite stays. The AI helper
+ * is off, so the offline rewrite runs. No provider is called.
+ */
+process.env.FUOBE_DATA_DIR = tempDir("fuobe-look-enhance-button-");
+delete process.env.FUOBE_PASSWORD;
+
+const { setSetting } = await import("@/server/settings");
+const { POST } = await import("@/app/api/enhance/route");
+setSetting("enhanceProvider", "none");
+
+const IDEA = "A lighthouse keeper climbs a spiral stair at night, rain on the glass, a foghorn far off";
+const FUOBE_LOOK = /cinematic|volumetric|depth of field|film look|realistic physics/i;
+const enhance = async (body: Record<string, unknown>) =>
+ ((await (await POST(new Request("http://localhost/api/enhance", { method: "POST", body: JSON.stringify({ prompt: IDEA, kind: "video", ...body }) }))).json()) as { prompt: string }).prompt;
+
+describe("the Enhance button on an H3 Max look", () => {
+ it.each(["minimax-h3-max-look-pixel", "minimax-h3-max-look-vhs"])("%s: no light, lens or film look of Fuobe's", async (modelId) => {
+ for (const op of ["t2v", "i2v"]) {
+ const p = await enhance({ op, modelId });
+ expect(p.startsWith(IDEA)).toBe(true);
+ expect(p).not.toMatch(FUOBE_LOOK);
+ }
+ });
+
+ it("another model, or none, keeps the full rewrite", async () => {
+ expect(await enhance({ op: "t2v", modelId: "minimax-h3" })).toMatch(/24fps film look/);
+ expect(await enhance({ op: "t2v" })).toMatch(/24fps film look/);
+ });
+});
diff --git a/tests/h3max-look-enhance.test.ts b/tests/h3max-look-enhance.test.ts
new file mode 100644
index 00000000..5b7ae829
--- /dev/null
+++ b/tests/h3max-look-enhance.test.ts
@@ -0,0 +1,72 @@
+import { afterAll, beforeAll, describe, expect, it } from "vitest";
+import { startFakeFal, type FakeCloud } from "./helpers/fake-cloud";
+import { tempDir } from "./helpers/temp-dir";
+
+/**
+ * fal's H3 Max looks put their own style on the clip. Each endpoint's prompt field (fal's queue OpenAPI for
+ * minimax/h3-max/styles/<slug>) says "Describe the scene, action, camera and sound. The … style is applied automatically."
+ * So Enhance adds no light, lens or film look of Fuobe's to a look's prompt, as Soul's enhancer adds no style to Soul's.
+ * Other video models keep the full rewrite. The AI helper is off, so the offline rewrite runs (an account's run always
+ * gets it). Stand-in fal.ai (tests/helpers/fake-cloud.ts): no real key, no paid call.
+ */
+process.env.FUOBE_DATA_DIR = tempDir("fuobe-look-enhance-");
+process.env.COMFYUI_URL = "http://127.0.0.1:9";
+delete process.env.FUOBE_PASSWORD;
+globalThis.__fuobeTestDiskFree = 1e13;
+
+const { getModel } = await import("@/lib/catalog");
+const { setSetting } = await import("@/server/settings");
+const { createGenerations, getGeneration } = await import("@/server/generations");
+type GenerationRequest = import("@/lib/catalog/types").GenerationRequest;
+
+const LOOKS = ["minimax-h3-max-look-pixel", "minimax-h3-max-look-hand-drawn", "minimax-h3-max-look-low-poly", "minimax-h3-max-look-retro-toon", "minimax-h3-max-look-vhs"];
+const IDEA = "A lighthouse keeper climbs a spiral stair at night, rain on the glass, a foghorn far off";
+/** The offline rewrite's own look: light, lens, film. */
+const FUOBE_LOOK = /cinematic|volumetric|depth of field|film look|realistic physics/i;
+const PNG = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg==";
+const MP4 = `data:video/mp4;base64,${Buffer.from("\x00\x00\x00\x18ftypmp42\x00\x00\x00\x00mp42isom", "latin1").toString("base64")}`;
+
+let fal: FakeCloud;
+beforeAll(async () => {
+ fal = await startFakeFal();
+ globalThis.__fuobeTestFalUrl = fal.url;
+ fal.keys["stand-in-fal-key"] = "good";
+ fal.pollsToFinish = 0;
+ setSetting("falKey", "stand-in-fal-key");
+ setSetting("enhanceProvider", "none");
+ // A look's answer as fal's output schema has it: {video: File, seed}.
+ fal.script = (r) => (r.method === "GET" && /\/requests\/[^/]+$/.test(r.path.split("?")[0]) ? { status: 200, body: { video: { url: MP4, content_type: "video/mp4" }, seed: 1 } } : null);
+});
+afterAll(async () => {
+ globalThis.__fuobeTestFalUrl = undefined;
+ await fal.close();
+});
+
+/** The prompt fal got for one enhanced run of `modelId`. */
+async function sentPrompt(modelId: string, images?: string[]): Promise<{ path: string; prompt: string }> {
+ const m = getModel(modelId)!;
+ fal.log.length = 0;
+ const [g] = createGenerations({ feature: "video", modelId, engine: "cloud", prompt: IDEA, ...(images && { inputs: { images } }), params: { ...m.defaults, enhancePrompt: true } } as GenerationRequest);
+ for (let i = 0; i < 1500 && !["failed", "succeeded", "canceled"].includes(getGeneration(g.id)!.status); i++) await new Promise((r) => setTimeout(r, 10));
+ expect(getGeneration(g.id)!.status, `${modelId}: ${getGeneration(g.id)!.error}`).toBe("succeeded");
+ const submit = fal.log.find((r) => r.method === "POST" && !r.path.startsWith("/storage/"))!;
+ return { path: submit.path, prompt: JSON.parse(submit.body).prompt };
+}
+
+describe("Enhance on an H3 Max look leaves the look to fal", () => {
+ it.each(LOOKS)("%s: words and a first frame, enhanced without Fuobe's light, lens or film look", async (id) => {
+ for (const images of [undefined, [PNG]]) {
+ const { path, prompt } = await sentPrompt(id, images);
+ expect(path).toBe(`/${getModel(id)!.routes[0].endpoint}`);
+ expect(prompt.startsWith(IDEA)).toBe(true);
+ expect(prompt.length).toBeGreaterThan(IDEA.length);
+ expect(prompt).not.toMatch(FUOBE_LOOK);
+ }
+ });
+
+ it("another video model keeps the full rewrite (MiniMax H3 on fal)", async () => {
+ const { path, prompt } = await sentPrompt("minimax-h3");
+ expect(path).toBe("/minimax/h3/text-to-video");
+ expect(prompt).toMatch(/24fps film look/);
+ });
+});