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.

Video: an opt-in Fix faces switch for MiniMax H3 from a start picture

Adarsh72ad1a7863f9
diff --git a/src/components/fix-faces/fix-faces-switch.tsx b/src/components/fix-faces/fix-faces-switch.tsx
new file mode 100644
index 00000000..667b0ef6
--- /dev/null
+++ b/src/components/fix-faces/fix-faces-switch.tsx
@@ -0,0 +1,27 @@
+"use client";
+
+import { useId } from "react";
+import { OwnSetupChip } from "@/components/own-setup";
+import { Switch } from "@/components/ui/switch";
+import { FIX_FACES } from "@/lib/catalog/fix-faces";
+import { cn } from "@/lib/utils";
+
+/**
+ * "Fix faces" beside Run for a MiniMax H3 video from a start picture: off until the person turns it on. On, the take is
+ * followed by Fix faces with the start picture as the face, and both videos are kept.
+ */
+export function FixFacesAfterSwitch({ on, onChange, className }: { on: boolean; onChange: (on: boolean) => void; className?: string }) {
+ const id = useId();
+ return (
+ <div className={cn("flex min-w-0 items-start gap-2", className)}>
+ <Switch id={id} checked={on} onCheckedChange={onChange} className="mt-0.5 shrink-0" />
+ <div className="min-w-0">
+ <label htmlFor={id} className="text-[13px] font-medium">
+ Fix faces
+ </label>
+ <OwnSetupChip setup={FIX_FACES.model} className="ml-1.5 align-[1px]" />
+ <p className="text-[12px] text-pretty text-muted-foreground">Redraws every face sharp and true to your picture. Your video is ready a few minutes later.</p>
+ </div>
+ </div>
+ );
+}
diff --git a/src/components/studio/composer.tsx b/src/components/studio/composer.tsx
index 35cc1660..bdc763ce 100644
--- a/src/components/studio/composer.tsx
+++ b/src/components/studio/composer.tsx
@@ -157,6 +157,8 @@ import { useEdgeFade } from "./use-edge-fade";
import { CleanVoiceSlot, CleanVoiceSwitch, useVoiceCleaning } from "@/components/audio-tools/clean-voice-switch";
import { useVoiceFirstLive, useVoiceFirstShown, VoiceFirstSwitch } from "@/components/audio-tools/voice-first-switch";
import { VOICE_FIRST_PARAM, voiceFirstDefault } from "@/lib/av/voice-first";
+import { FixFacesAfterSwitch } from "@/components/fix-faces/fix-faces-switch";
+import { FIX_FACES_AFTER_PARAM, fixFacesAfterOffered } from "@/lib/catalog/fix-faces";
import { useSignature } from "../palettes/use-signature";
import { placeholdersOn } from "@/lib/demo-mode";
import { FILM_LOOK_PARAM, takesFilmLooks } from "@/lib/film-looks";
@@ -355,6 +357,8 @@ export function Composer({ docked }: { docked: boolean }) {
const voiceFirstShown = useVoiceFirstShown(true);
const voiceFirstLive = useVoiceFirstLive();
const [voiceFirstAsked, setVoiceFirstAsked] = useState<boolean | null>(null);
+ // "Fix faces" after an H3 video from a start picture: off until turned on.
+ const [fixFacesAsked, setFixFacesAsked] = useState(false);
const voiceFirstKind: "audio" | "video" | null = !config.voiceFirst ? null : typed.slots.audio?.ref ? "audio" : typed.slots.video?.ref && config.ops.includes("transcribe") ? "video" : null;
const draft = useMemo(
() =>
@@ -1027,7 +1031,8 @@ export function Composer({ docked }: { docked: boolean }) {
buildRequest(config.feature, songDraft(draft, model, config.slots), resolvesOnServer ? studioOp : op, config.promptSuffix, config.multiRef?.kind, framesCtx, targetFor(draft.modelId)),
);
const withVoiceFirst = cleanFirst ? { ...sent.request, params: { ...sent.request.params, extra: { ...sent.request.params?.extra, [VOICE_FIRST_PARAM]: true } } } : sent.request;
- return runOnceOnKey(withVoiceFirst, a, (r) => create.mutateAsync(r)).then(
+ const withFixFaces = fixFacesOn ? { ...withVoiceFirst, params: { ...withVoiceFirst.params, extra: { ...withVoiceFirst.params?.extra, [FIX_FACES_AFTER_PARAM]: true } } } : withVoiceFirst;
+ return runOnceOnKey(withFixFaces, a, (r) => create.mutateAsync(r)).then(
(words) => void toast.success(words),
(e) => toastError(e),
);
@@ -1164,7 +1169,8 @@ export function Composer({ docked }: { docked: boolean }) {
model?.kind,
);
const withVoiceFirst = cleanFirst ? { ...sent.request, params: { ...sent.request.params, extra: { ...sent.request.params?.extra, [VOICE_FIRST_PARAM]: true } } } : sent.request;
- const onKey = withKey ? onCloudKey(withVoiceFirst, withKey) : withVoiceFirst;
+ const withFixFaces = fixFacesOn ? { ...withVoiceFirst, params: { ...withVoiceFirst.params, extra: { ...withVoiceFirst.params?.extra, [FIX_FACES_AFTER_PARAM]: true } } } : withVoiceFirst;
+ const onKey = withKey ? onCloudKey(withFixFaces, withKey) : withFixFaces;
const body = { ...withRoute(onKey), ...hosted, ...(skipGpu && { gpuCheck: "skip" }) } as typeof sent.request;
create.mutate(body, {
// Accepted: nothing to try again (a card opened later never starts this run a second time). Back from sign-up, the
@@ -1251,6 +1257,9 @@ export function Composer({ docked }: { docked: boolean }) {
preset?.userPrompt,
);
const effectiveOp = studioOp ?? op;
+ // Fix faces after the take: an H3 video from a start picture, no longer than one Fix faces run, and not at 2K.
+ const fixFacesShown = fixFacesAfterOffered(draft.modelId, effectiveOp ?? (typed.slots.image?.ref ? "i2v" : undefined), p.duration, !!typed.slots.image?.ref) && p.resolution !== "2K";
+ const fixFacesOn = fixFacesShown && fixFacesAsked;
// Qwen-Image 2.1's Options → GPU on Small: what the small encoder can't do (or that a speed with its own graph wins).
// MiniMax H3's GPU tier: what FastH3 V2 or Trim changes, picked or as Auto runs it on the card the GPU check read.
const h3Note = opts.controls?.some((c) => c.param === H3_TIER_PARAM) ? h3TierNote(p.extra, effectiveOp, gpuBadges?.h3Tier) : undefined;
@@ -1930,6 +1939,7 @@ export function Composer({ docked }: { docked: boolean }) {
{showAttachments && !collapsed && !framesOn && <FitCropNote fit={cropFit} className="px-3" />}
{/* On a phone the slot row scrolls sideways, so the switch gets its own line under it. */}
{showAttachments && !collapsed && !framesOn && hasCleanVoice && <CleanVoiceSwitch status className="px-3 pb-2 sm:hidden" hint="first, free on your GPU" />}
+ {showAttachments && !collapsed && !framesOn && fixFacesShown && <FixFacesAfterSwitch className="px-3 pb-2" on={fixFacesOn} onChange={setFixFacesAsked} />}
{showAttachments && !collapsed && !framesOn && voiceFirstShown && voiceFirstKind && (
<VoiceFirstSwitch className="px-3 pb-2" engine={voiceFirstEngine} on={cleanFirst} onChange={setVoiceFirstAsked} seconds={voice?.duration} lip={!config.ops.includes("transcribe")} />
)}
diff --git a/src/lib/catalog/fix-faces.ts b/src/lib/catalog/fix-faces.ts
index 717d808d..c0c0b528 100644
--- a/src/lib/catalog/fix-faces.ts
+++ b/src/lib/catalog/fix-faces.ts
@@ -1,3 +1,5 @@
+import type { GenerationRequest } from "./types";
+
/**
* Fix Faces: a video's soft or smeared faces redrawn sharp, matched to a photo of the person (or the clip's own clearest
* face, picked in the browser: src/lib/fix-faces/face-frame.ts). It runs Genjutsu's Finish with its Fix faces tool,
@@ -65,3 +67,43 @@ export function fixFacesBody(o: { clip: FixFacesClip; photo: string; style: FixF
...(o.requestId && { requestId: o.requestId }),
};
}
+
+// ---------------------------------------------------------------------------
+// Fix faces after a MiniMax H3 video (an opt-in switch beside Run): the clip, then its faces fixed from its start picture.
+
+/** The switch's flag on the H3 request (params.extra). */
+export const FIX_FACES_AFTER_PARAM = "fixFacesAfter";
+/** The H3 models it follows: the full model and its fast and flash versions, on your GPU or the site's. */
+const H3_MODELS = new Set(["oss-minimax-h3", "oss-minimax-h3-fast", "oss-minimax-h3-flash"]);
+
+/** Whether the switch is offered: an H3 video from a start picture, no longer than one Fix faces run. */
+export function fixFacesAfterOffered(modelId: string | undefined, op: string | undefined, seconds: number | undefined, hasStart: boolean): boolean {
+ return !!modelId && H3_MODELS.has(modelId) && op === "i2v" && hasStart && !(seconds && seconds > FIX_FACES.maxSeconds);
+}
+
+/** Whether a request asks for it, and may have it. */
+export function wantsFixFacesAfter(req: Pick<GenerationRequest, "modelId" | "op" | "params" | "inputs">): boolean {
+ return req.params?.extra?.[FIX_FACES_AFTER_PARAM] === true && fixFacesAfterOffered(req.modelId, req.op ?? "i2v", req.params?.duration, !!req.inputs?.images?.[0]);
+}
+
+/**
+ * The step after the clip: Fix faces on it, its start picture as the face, in Genjutsu's default style (Follow the mouth),
+ * labelled as the run's second step. `chain` puts the clip in once it is made.
+ */
+export function fixFacesAfterStep(req: GenerationRequest): GenerationRequest {
+ const seed = req.params?.seed;
+ return {
+ feature: req.feature,
+ ...(req.title && { title: req.title }),
+ ...(req.batchTitle && { batchTitle: req.batchTitle }),
+ ...(req.demo && { demo: true }),
+ engine: "open",
+ modelId: FIX_FACES.model,
+ op: "face-fix-video",
+ prompt: "",
+ inputs: { images: [req.inputs!.images![0]] },
+ params: { extra: { openjutsu: { faceStyle: "mouth", chunkSeconds: 6.5, ...(seed !== undefined && { seed }) } } },
+ chain: [{ slot: "video" }],
+ step: { label: "Fix faces", index: 1, of: 2 },
+ } as GenerationRequest;
+}
diff --git a/src/server/generations.ts b/src/server/generations.ts
index 728ba76a..0bc0431c 100644
--- a/src/server/generations.ts
+++ b/src/server/generations.ts
@@ -74,6 +74,7 @@ import { pollTrainings } from "./training";
import { createEndFrameClip, createExtendChain, createKeyframeFilm, createMosaicRun, createRefinedModel, createRelitClip, createShotFilm, createStillTo3d, createVoiceFirst, joinClips } from "./chains";
import { chainedRefine } from "@/lib/av/hi3d";
import { wantsVoiceFirst } from "@/lib/av/voice-first";
+import { FIX_FACES, FIX_FACES_AFTER_PARAM, fixFacesAfterStep, wantsFixFacesAfter } from "@/lib/catalog/fix-faces";
import { createH3TwoKRun, createRegenerateRun, keepsH3Latent, regenHeld, regenSwitchedOff } from "./regenerate";
import { H3_2K_STEPS_NOTE, h3TwoKRequests, REGEN_COPY, REGEN_MODEL, regenerateGraphLoras, wantsH3TwoK } from "@/lib/catalog/regenerate";
import { enhancePrompt, enhanceSoulWords, ideogramCaption } from "./enhance";
@@ -1502,8 +1503,15 @@ export function previewGeneration(asked: GenerationRequest) {
if (twoK.costUsd !== null) post += twoK.costUsd;
notes.push(...twoK.notes);
}
+ // Fix faces after the take (the switch beside Run): one more step per take, planned and priced beside it.
+ const faces = twoK ? null : fixFacesExtra(moved.request, plan.jobs);
+ if (faces) {
+ if (faces.costUsd !== null) post += faces.costUsd;
+ notes.push(faces.note);
+ }
+ const extraSteps: { model: string; op: string }[] = [...(twoK?.steps ?? []), ...(faces?.steps ?? [])];
// A finish whose price isn't known leaves the run's price unknown too, never the main step's alone.
- const priceUnknown = cost === null || twoK?.costUsd === null;
+ const priceUnknown = cost === null || twoK?.costUsd === null || faces?.costUsd === null;
return {
model: plan.model,
op: plan.op,
@@ -1513,7 +1521,7 @@ export function previewGeneration(asked: GenerationRequest) {
providerId,
costUsd: priceUnknown || cost === null ? null : post ? Math.round((cost * plan.jobs + post) * 1000) / 1000 : cost * plan.jobs,
// The other steps the run makes beside its own model (a 2K take's finish), so a policy and a price see them all.
- ...(twoK?.steps.length && { steps: twoK.steps }),
+ ...(extraSteps.length && { steps: extraSteps }),
// The engine it runs on (a Fuobe Original picks one per request).
engine: plan.model.engine,
// What the route runs (the evaluation harness records it): the provider endpoint, the final prompt and the LoRAs it loads.
@@ -1547,6 +1555,17 @@ function h3TwoKExtra(req: GenerationRequest, model: ModelDef, op: Operation): {
};
}
+/** Fix faces after an H3 take from a start picture (the switch beside Run): one Fix faces step per take, checked and priced. */
+function fixFacesExtra(req: GenerationRequest, takes: number): { costUsd: number | null; note: string; steps: { model: string; op: string }[] } | null {
+ if (!wantsFixFacesAfter(req)) return null;
+ const p = previewChained(fixFacesAfterStep(req), 1);
+ return {
+ costUsd: p.costUsd === null ? null : Math.round(p.costUsd * takes * 10000) / 10000,
+ note: "Then its faces are fixed from the start picture: a few more minutes",
+ steps: Array.from({ length: takes }, () => ({ model: FIX_FACES.model, op: "face-fix-video" })),
+ };
+}
+
/** Preview a step that will wait for `deps` earlier steps: validated with placeholders in its chain slots, as createGenerations does. */
export function previewChained(req: GenerationRequest, deps: number) {
if (!deps) return previewGeneration(req);
@@ -1665,6 +1684,22 @@ export function createGenerations(sent: GenerationRequest, opts: CreateOptions =
const run = createRegenerateRun(original, shotModel, opts, createGenerations, joinClips, (id) => void cancelGeneration(id));
if (run) return run;
}
+ // Fix faces after a MiniMax H3 video from a start picture (the switch beside Run): each take, then its faces fixed from that
+ // picture. Both are kept: the take as it came, and the fixed one. 2K keeps its own two steps instead.
+ if (!opts.dependsOn && shotModel && wantsFixFacesAfter(original) && !wantsH3TwoK(shotModel.id, original.params?.resolution)) {
+ const batchId = opts.batchId ?? nanoid(10);
+ const extra = { ...original.params?.extra };
+ delete extra[FIX_FACES_AFTER_PARAM];
+ const takes = createGenerations({ ...original, params: { ...original.params, extra } }, { batchId });
+ const fixed: Generation[] = [];
+ try {
+ for (const t of takes) fixed.push(...createGenerations(fixFacesAfterStep(original), { batchId, dependsOn: t.id }));
+ } catch (e) {
+ for (const g of [...fixed, ...takes]) void cancelGeneration(g.id);
+ throw e;
+ }
+ return [...fixed, ...takes];
+ }
// MiniMax H3 at 2K on your GPU (n7-10): a 768p draft, then Open-H3 Regenerate at 2K from it (from its latent for text to video).
if (shotModel && wantsH3TwoK(shotModel.id, original.params?.resolution)) {
return createH3TwoKRun(original, inferOperation(shotModel, original), opts, createGenerations, (id) => void cancelGeneration(id));
diff --git a/src/server/pool-own-setup.ts b/src/server/pool-own-setup.ts
index f34b16c3..cbc7cc8c 100644
--- a/src/server/pool-own-setup.ts
+++ b/src/server/pool-own-setup.ts
@@ -7,6 +7,7 @@ import { directRunFeatures } from "@/lib/catalog/genjutsu";
import { ENHANCE_FEATURES, REGEN_MODEL, wantsH3TwoK } from "@/lib/catalog/regenerate";
import { RESTORE } from "@/lib/catalog/restore";
import { wantsVoiceFirst } from "@/lib/av/voice-first";
+import { FIX_FACES, wantsFixFacesAfter } from "@/lib/catalog/fix-faces";
import { ownSetupGraphs, ownSetupOnly, type OwnSetup } from "@/lib/own-setup";
import { controlSetup } from "@/lib/own-setup-controls";
import { RTX_CLASSES, rtxCardOf } from "@/lib/catalog/rtx-video";
@@ -28,7 +29,7 @@ import { ownSetupOnlyNow } from "./own-setup-live";
*/
/** The ids a request's own setup is asked by: its model, then the modes and options of it that have their own. */
-export function requestSetupIds(req: Pick<GenerationRequest, "modelId" | "op" | "feature" | "params">): string[] {
+export function requestSetupIds(req: Pick<GenerationRequest, "modelId" | "op" | "feature" | "params" | "inputs">): string[] {
const ids = [req.modelId];
const extra = req.params?.extra ?? {};
if (wantsH3TwoK(req.modelId, req.params?.resolution)) ids.push("regenerate:h3-2k");
@@ -41,6 +42,8 @@ export function requestSetupIds(req: Pick<GenerationRequest, "modelId" | "op" |
if (id) ids.push(id);
}
if (wantsVoiceFirst(req)) ids.push("sound:clean-voice-first");
+ // Fix faces after an H3 take: Fix faces' own setup too.
+ if (wantsFixFacesAfter(req)) ids.push(FIX_FACES.model);
const genjutsu = extra.openjutsu;
const features = directRunFeatures(req.modelId, genjutsu && typeof genjutsu === "object" ? (genjutsu as Record<string, unknown>) : {});
for (const f of features ?? []) ids.push(`genjutsu:${f}`);
diff --git a/tests/fix-faces.test.ts b/tests/fix-faces.test.ts
index 8cb01602..c95f70bf 100644
--- a/tests/fix-faces.test.ts
+++ b/tests/fix-faces.test.ts
@@ -90,3 +90,34 @@ describe("the Fix faces action on a finished video", () => {
expect(outputActions(g({ feature: "app:app-fix-faces" }), 0).some((a) => a.id === "fix-faces")).toBe(false);
});
});
+
+describe("Fix faces after an H3 video", () => {
+ const h3 = { modelId: "oss-minimax-h3", op: "i2v", feature: "studio", prompt: "She walks", inputs: { images: ["/api/files/start.png"] }, params: { duration: 5, seed: 7, extra: { fixFacesAfter: true } } } as never;
+
+ it("is offered for an H3 video from a start picture up to 10 s", async () => {
+ const { fixFacesAfterOffered, wantsFixFacesAfter } = await import("@/lib/catalog/fix-faces");
+ expect(fixFacesAfterOffered("oss-minimax-h3", "i2v", 5, true)).toBe(true);
+ expect(fixFacesAfterOffered("oss-minimax-h3-fast", "i2v", 10, true)).toBe(true);
+ expect(fixFacesAfterOffered("oss-minimax-h3", "t2v", 5, false)).toBe(false);
+ expect(fixFacesAfterOffered("oss-minimax-h3", "i2v", 12, true)).toBe(false);
+ expect(fixFacesAfterOffered("wan-2-2", "i2v", 5, true)).toBe(false);
+ expect(wantsFixFacesAfter(h3)).toBe(true);
+ expect(wantsFixFacesAfter({ ...(h3 as object), params: { duration: 5 } } as never)).toBe(false);
+ });
+
+ it("follows the take with Fix faces from its start picture, in Follow the mouth, waiting for the clip", async () => {
+ const { fixFacesAfterStep } = await import("@/lib/catalog/fix-faces");
+ const step = fixFacesAfterStep(h3);
+ expect(step).toMatchObject({
+ modelId: "oss-h3-fix-faces",
+ op: "face-fix-video",
+ inputs: { images: ["/api/files/start.png"] },
+ params: { extra: { openjutsu: { faceStyle: "mouth", chunkSeconds: 6.5, seed: 7 } } },
+ chain: [{ slot: "video" }],
+ step: { index: 1, of: 2 },
+ });
+ // Its own setup is asked along with the take's.
+ const { requestSetupIds } = await import("@/server/pool-own-setup");
+ expect(requestSetupIds(h3)).toContain("oss-h3-fix-faces");
+ });
+});