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.

Apps: Fix Faces, soft or smeared faces in a video redrawn sharp and true

Adarsh6961742214f5
diff --git a/public/previews/presets/app-fix-faces.jpg b/public/previews/presets/app-fix-faces.jpg
new file mode 100644
index 00000000..3c37ecd6
Binary files /dev/null and b/public/previews/presets/app-fix-faces.jpg differ
diff --git a/public/previews/presets/app-fix-faces.mp4 b/public/previews/presets/app-fix-faces.mp4
new file mode 100644
index 00000000..922abf56
Binary files /dev/null and b/public/previews/presets/app-fix-faces.mp4 differ
diff --git a/public/previews/presets/hd/1024/app-fix-faces.avif b/public/previews/presets/hd/1024/app-fix-faces.avif
new file mode 100644
index 00000000..f5f2ab36
Binary files /dev/null and b/public/previews/presets/hd/1024/app-fix-faces.avif differ
diff --git a/public/previews/presets/hd/1024/app-fix-faces.jpg b/public/previews/presets/hd/1024/app-fix-faces.jpg
new file mode 100644
index 00000000..6c9ad843
Binary files /dev/null and b/public/previews/presets/hd/1024/app-fix-faces.jpg differ
diff --git a/public/previews/presets/hd/1024/app-fix-faces.mp4 b/public/previews/presets/hd/1024/app-fix-faces.mp4
new file mode 100644
index 00000000..59d36c95
Binary files /dev/null and b/public/previews/presets/hd/1024/app-fix-faces.mp4 differ
diff --git a/public/previews/presets/hd/320/app-fix-faces.avif b/public/previews/presets/hd/320/app-fix-faces.avif
new file mode 100644
index 00000000..95db9e3b
Binary files /dev/null and b/public/previews/presets/hd/320/app-fix-faces.avif differ
diff --git a/public/previews/presets/hd/640/app-fix-faces.avif b/public/previews/presets/hd/640/app-fix-faces.avif
new file mode 100644
index 00000000..1d9e6d53
Binary files /dev/null and b/public/previews/presets/hd/640/app-fix-faces.avif differ
diff --git a/public/previews/presets/hd/640/app-fix-faces.jpg b/public/previews/presets/hd/640/app-fix-faces.jpg
new file mode 100644
index 00000000..0ed3e998
Binary files /dev/null and b/public/previews/presets/hd/640/app-fix-faces.jpg differ
diff --git a/public/previews/presets/hd/640/app-fix-faces.mp4 b/public/previews/presets/hd/640/app-fix-faces.mp4
new file mode 100644
index 00000000..b1e3e694
Binary files /dev/null and b/public/previews/presets/hd/640/app-fix-faces.mp4 differ
diff --git a/public/previews/presets/mini/app-fix-faces.jpg b/public/previews/presets/mini/app-fix-faces.jpg
new file mode 100644
index 00000000..3f153cc1
Binary files /dev/null and b/public/previews/presets/mini/app-fix-faces.jpg differ
diff --git a/public/previews/presets/thumbs/app-fix-faces.jpg b/public/previews/presets/thumbs/app-fix-faces.jpg
new file mode 100644
index 00000000..91a3d2bf
Binary files /dev/null and b/public/previews/presets/thumbs/app-fix-faces.jpg differ
diff --git a/public/samples/fix-faces/dance-before.mp4 b/public/samples/fix-faces/dance-before.mp4
new file mode 100644
index 00000000..c283ca76
Binary files /dev/null and b/public/samples/fix-faces/dance-before.mp4 differ
diff --git a/public/samples/fix-faces/dance-compare.jpg b/public/samples/fix-faces/dance-compare.jpg
new file mode 100644
index 00000000..18286043
Binary files /dev/null and b/public/samples/fix-faces/dance-compare.jpg differ
diff --git a/public/samples/fix-faces/dance-compare.mp4 b/public/samples/fix-faces/dance-compare.mp4
new file mode 100644
index 00000000..6cd948cd
Binary files /dev/null and b/public/samples/fix-faces/dance-compare.mp4 differ
diff --git a/src/app/(studio)/apps/[id]/page.tsx b/src/app/(studio)/apps/[id]/page.tsx
index a1319e82..724b9b4e 100644
--- a/src/app/(studio)/apps/[id]/page.tsx
+++ b/src/app/(studio)/apps/[id]/page.tsx
@@ -7,6 +7,7 @@ import { AnyAngleGate } from "@/components/any-angle/any-angle-tool";
import { RelightGate } from "@/components/relight/relight-gate";
import { RecolorTool } from "@/components/recolor/recolor-tool";
import { BodyDoubleTool } from "@/components/body-double/body-double-tool";
+import { FixFacesTool } from "@/components/fix-faces/fix-faces-tool";
import { WatermarkTool } from "@/components/watermark/watermark-tool";
import { APPS, getModel, getPreset } from "@/lib/catalog";
import { withRecipe } from "@/lib/catalog/preset-recipes";
@@ -38,6 +39,7 @@ async function AppStudio({ params }: { params: PageProps<"/apps/[id]">["params"]
if (preset.tool === "recolor") return <RecolorTool app={{ name: preset.name, description: preset.description }} />;
// Body Double: Live (in the browser, no GPU) is open to everyone; a photo or a clip runs on a GPU.
if (preset.tool === "body-double") return <BodyDoubleTool app={{ name: preset.name, description: preset.description }} />;
+ if (preset.tool === "fix-faces") return <FixFacesTool app={{ name: preset.name, description: preset.description }} />;
// The Watermark Remover: scan, keep what you like, remove the rest (src/components/watermark).
if (preset.tool === "watermark") return <WatermarkTool app={{ name: preset.name, description: preset.description }} cover={presetCover(preset.id)} />;
// The app opens on the model its preview was made with, its own route one pick away.
diff --git a/src/components/fix-faces/fix-faces-tool.tsx b/src/components/fix-faces/fix-faces-tool.tsx
new file mode 100644
index 00000000..b1d1b1ce
--- /dev/null
+++ b/src/components/fix-faces/fix-faces-tool.tsx
@@ -0,0 +1,340 @@
+"use client";
+
+import { ChevronRight, Film, ImagePlus, Library, Loader2, ScanFace, Upload, X } from "lucide-react";
+import { nanoid } from "nanoid";
+import Link from "next/link";
+import { useSearchParams } from "next/navigation";
+import { useEffect, useId, useRef, useState } from "react";
+import { toast } from "sonner";
+import { Panel, ToolHero, ToolShell } from "@/components/av/tool-shell";
+import { usePlayInView } from "@/components/body-double/use-play-in-view";
+import { Segmented } from "@/components/faceless/controls";
+import { useGenjutsuRun } from "@/components/genjutsu/hooks";
+import { OwnSetupChip, useOwnSetupPress } from "@/components/own-setup";
+import { Feed } from "@/components/studio/feed";
+import { fileToSlot, kindOfFile, LibraryGrid, type SlotValue } from "@/components/studio/media-slot";
+import { Button } from "@/components/ui/button";
+import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
+import { askToSignUp, useAskBeforeUpload, useGenerations, useIsGuest } from "@/lib/api";
+import { FIX_FACES, FIX_FACES_DEMO, FIX_FACES_STYLES, type FixFacesStyle, fixFacesBody } from "@/lib/catalog/fix-faces";
+import { pickFaceFrame } from "@/lib/fix-faces/face-frame";
+import { toastError } from "@/lib/refusals";
+import { postFile } from "@/lib/upload";
+import { cn } from "@/lib/utils";
+
+const SUBTITLE = "Soft or smeared faces in a video, redrawn sharp and true to the person, frame by frame. Add a photo of them, or let Fix Faces find the clearest face in your clip.";
+const EXAMPLE_NAME = "fix-faces-example.mp4";
+
+/** A clip or a photo: upload, from the Library, or (for the clip) the example. */
+function Picker({ kind, onPick, children }: { kind: "video" | "image"; onPick: (v: SlotValue) => void; children: (open: () => void, library: React.ReactNode) => React.ReactNode }) {
+ const [picking, setPicking] = useState(false);
+ const askFirst = useAskBeforeUpload();
+ const inputId = useId();
+ const take = (f: File | undefined) => {
+ if (!f || askFirst()) return;
+ if (kindOfFile(f) !== kind) return void toast(kind === "video" ? "A video file, please" : "A photo, please");
+ void fileToSlot(f, (v) => v && onPick(v), kind);
+ };
+ const library = (
+ <Popover open={picking} onOpenChange={setPicking}>
+ <PopoverTrigger asChild>
+ <Button variant="ghost" size="sm" className="rounded-full">
+ <Library className="size-4" /> From your Library
+ </Button>
+ </PopoverTrigger>
+ <PopoverContent className="w-[min(92vw,360px)] p-2" collisionPadding={12}>
+ <p className="px-1 pb-2 text-[13px] font-medium">From your library</p>
+ {picking && (
+ <LibraryGrid
+ kinds={[kind]}
+ onPick={(v) => {
+ onPick(v);
+ setPicking(false);
+ }}
+ />
+ )}
+ </PopoverContent>
+ </Popover>
+ );
+ return (
+ <>
+ {children(() => askFirst() || document.getElementById(inputId)?.click(), library)}
+ <input
+ id={inputId}
+ type="file"
+ accept={kind === "video" ? "video/mp4,video/quicktime,video/webm" : "image/png,image/jpeg,image/webp"}
+ hidden
+ onChange={(e) => {
+ take(e.target.files?.[0]);
+ e.target.value = "";
+ }}
+ />
+ </>
+ );
+}
+
+function AddClip({ onPick }: { onPick: (v: SlotValue) => void }) {
+ const [over, setOver] = useState(false);
+ const askFirst = useAskBeforeUpload();
+ return (
+ <Picker kind="video" onPick={onPick}>
+ {(open, library) => (
+ <div
+ className={cn(
+ "flex flex-col items-center justify-center gap-3 rounded-2xl border-2 border-dashed border-border-strong bg-background px-4 py-10 text-center transition-colors",
+ over && "border-primary bg-brand-faint",
+ )}
+ onDragOver={(e) => {
+ e.preventDefault();
+ setOver(true);
+ }}
+ onDragLeave={() => setOver(false)}
+ onDrop={(e) => {
+ e.preventDefault();
+ setOver(false);
+ const f = e.dataTransfer.files?.[0];
+ if (!f || askFirst()) return;
+ if (kindOfFile(f) !== "video") return void toast("A video file, please");
+ void fileToSlot(f, (v) => v && onPick(v), "video");
+ }}
+ >
+ <span className="grid size-12 place-items-center rounded-2xl bg-brand-faint text-brand-text">
+ <Film className="size-5" />
+ </span>
+ <div>
+ <p className="text-[15px] font-medium">Add a video</p>
+ <p className="mt-1 text-[13px] text-muted-foreground">Up to {FIX_FACES.maxSeconds} seconds, one main person in view</p>
+ </div>
+ <div className="flex flex-wrap items-center justify-center gap-1.5">
+ <Button size="lg" className="rounded-full" onClick={open}>
+ <Upload className="size-4" /> Upload
+ </Button>
+ {library}
+ </div>
+ <button
+ type="button"
+ onClick={() => onPick({ ref: "", preview: FIX_FACES_DEMO.clip, kind: "video", name: EXAMPLE_NAME })}
+ className="mt-1 flex items-center gap-3 rounded-xl border bg-card p-1.5 pr-4 text-left outline-none transition hover:border-border-strong focus-visible:ring-2 focus-visible:ring-ring"
+ >
+ <video src={FIX_FACES_DEMO.clip} muted playsInline preload="metadata" className="h-12 w-16 rounded-lg object-cover" />
+ <span className="block text-[13px] font-medium">Try it on this dance</span>
+ </button>
+ </div>
+ )}
+ </Picker>
+ );
+}
+
+/** The before and after example, playing only while it is on screen. */
+function Demo() {
+ const ref = useRef<HTMLVideoElement>(null);
+ usePlayInView(ref);
+ return (
+ <figure className="space-y-2 rounded-2xl border bg-background p-2.5 shadow-soft">
+ <video ref={ref} src={FIX_FACES_DEMO.video} poster={FIX_FACES_DEMO.poster} muted loop playsInline preload="none" className="block w-full rounded-xl bg-media" />
+ <figcaption className="px-0.5 text-[12px] text-muted-foreground">The dance as it was made, then fixed: the line sweeps across to the sharp, true face.</figcaption>
+ </figure>
+ );
+}
+
+type Meta = { duration?: number; width?: number; height?: number };
+type Auto = { url: string; blob: Blob } | null;
+
+export function FixFacesTool({ app }: { app: { name: string; description: string } }) {
+ // ?video=<url> (a finished result's "Fix faces"): opens on that clip.
+ const asked = useSearchParams().get("video");
+ const [clip, setClip] = useState<SlotValue | null>(asked ? { ref: asked, preview: asked, kind: "video", name: "video.mp4" } : null);
+ const [meta, setMeta] = useState<Meta>({});
+ const [photo, setPhoto] = useState<SlotValue | null>(null);
+ // The clip's clearest face, and how far the search is: each kept with the clip it belongs to.
+ const [found, setFound] = useState<{ for: string; face: Auto } | null>(null);
+ const [progress, setProgress] = useState<{ for: string; done: number; total: number } | null>(null);
+ const [style, setStyle] = useState<FixFacesStyle>("mouth");
+ const [sending, setSending] = useState(false);
+ const run = useGenjutsuRun();
+ const press = useOwnSetupPress();
+ const askFirst = useAskBeforeUpload();
+ const guest = useIsGuest();
+
+ const example = !!clip && !clip.ref && clip.preview === FIX_FACES_DEMO.clip;
+ const ready = clip && !clip.uploading && (clip.ref || example) ? clip : null;
+
+ // With no photo of their own, the clip's clearest face is found in the browser as soon as the clip is in.
+ const preview = clip?.preview;
+ useEffect(() => {
+ if (!preview || photo) return;
+ let gone = false;
+ pickFaceFrame(preview, (done, total) => !gone && setProgress({ for: preview, done, total }))
+ .then((f) => !gone && setFound({ for: preview, face: f ? { url: URL.createObjectURL(f.photo), blob: f.photo } : null }))
+ .catch(() => !gone && setFound({ for: preview, face: null }));
+ return () => {
+ gone = true;
+ };
+ }, [preview, photo]);
+ // The found face's object URL is let go when another one replaces it.
+ useEffect(() => () => void (found?.face && URL.revokeObjectURL(found.face.url)), [found]);
+ const auto: Auto = found && found.for === preview ? found.face : null;
+ const finding: { done: number; total: number } | "none" | null =
+ !preview || photo ? null : found?.for === preview ? (found.face ? null : "none") : progress?.for === preview ? progress : { done: 0, total: 1 };
+
+ const clear = () => {
+ setClip(null);
+ setMeta({});
+ };
+
+ const go = async () => {
+ if (!ready) return void toast("Add a video");
+ if (!photo && !auto) return void toast(finding === "none" ? "Add a photo of the person: no clear face was found in the clip" : "Finding the clearest face first…");
+ if (example && guest) return askToSignUp("run");
+ if (example && askFirst()) return;
+ if (!press(FIX_FACES.model)) return;
+ setSending(true);
+ try {
+ let url = ready.ref;
+ if (!url) {
+ const blob = await (await fetch(FIX_FACES_DEMO.clip)).blob();
+ url = (await postFile(new File([blob], EXAMPLE_NAME, { type: blob.type || "video/mp4" }))).url;
+ setClip({ ...ready, ref: url });
+ }
+ const face = photo?.ref || (auto ? (await postFile(new File([auto.blob], "face.jpg", { type: "image/jpeg" }))).url : "");
+ await run.mutateAsync(fixFacesBody({ clip: { url, name: ready.name, ...meta }, photo: face, style, requestId: nanoid(16) }));
+ toast.success("Fixing the faces");
+ document.getElementById("fix-faces-results")?.scrollIntoView({ behavior: "smooth", block: "start" });
+ } catch (e) {
+ toastError(e, "That didn't start. Please try again.");
+ } finally {
+ setSending(false);
+ }
+ };
+
+ const face = photo?.preview ?? auto?.url;
+ return (
+ <ToolShell
+ title="Apps"
+ engineSwitch={false}
+ header={
+ <nav aria-label="Breadcrumb" className="hidden items-center gap-1 text-[13px] text-muted-foreground sm:flex">
+ <Link href="/apps" className="hover:text-foreground">
+ Apps
+ </Link>
+ <ChevronRight className="size-3.5" />
+ <span className="text-foreground">{app.name}</span>
+ </nav>
+ }
+ >
+ <ToolHero title={app.name} subtitle={SUBTITLE} />
+ <div className="mx-auto mt-4 max-w-[1040px]">
+ {!clip ? (
+ <div className="grid gap-3 lg:grid-cols-[minmax(0,1fr)_minmax(0,1fr)] lg:items-start">
+ <AddClip onPick={setClip} />
+ <Demo />
+ </div>
+ ) : (
+ <div className="grid gap-3 lg:grid-cols-[minmax(0,1fr)_340px] lg:items-start">
+ <Panel
+ title="Your video"
+ aside={
+ <Button variant="ghost" size="icon-sm" className="rounded-full" aria-label="Remove it" onClick={clear}>
+ <X className="size-4" />
+ </Button>
+ }
+ >
+ <div className="overflow-hidden rounded-xl bg-media">
+ <video
+ src={clip.preview}
+ controls
+ muted
+ playsInline
+ loop
+ className="block max-h-[52vh] w-full object-contain"
+ onLoadedMetadata={(e) => setMeta({ duration: e.currentTarget.duration, width: e.currentTarget.videoWidth, height: e.currentTarget.videoHeight })}
+ />
+ </div>
+ <p className="mt-2 text-[12px] text-muted-foreground" aria-live="polite">
+ {clip.uploading
+ ? "Uploading…"
+ : meta.duration && meta.duration > FIX_FACES.maxSeconds + 0.05
+ ? `The first ${FIX_FACES.maxSeconds} seconds are fixed, at full size, with the sound kept.`
+ : "The whole clip is fixed at full size, with the sound kept."}
+ </p>
+ </Panel>
+ <Panel className="space-y-5">
+ <div className="space-y-2">
+ <h3 className="text-[13px] font-semibold">Face to match</h3>
+ <div className="flex items-center gap-3">
+ <div className="grid size-16 shrink-0 place-items-center overflow-hidden rounded-xl bg-media">
+ {face ? (
+ // eslint-disable-next-line @next/next/no-img-element
+ <img src={face} alt="The face the video is matched to" className="size-full object-cover" />
+ ) : finding && finding !== "none" ? (
+ <Loader2 className="size-5 animate-spin text-white/70" />
+ ) : (
+ <ScanFace className="size-5 text-white/70" />
+ )}
+ </div>
+ <div className="min-w-0 text-[12px] text-muted-foreground" aria-live="polite">
+ {photo
+ ? "Your photo"
+ : auto
+ ? "The clearest face in your clip"
+ : finding === "none"
+ ? "Add a photo of the person"
+ : finding
+ ? `Finding the clearest face… ${finding.done}/${finding.total}`
+ : ""}
+ <Picker kind="image" onPick={setPhoto}>
+ {(open, library) => (
+ <div className="mt-1 flex flex-wrap items-center gap-1">
+ <Button variant="outline" size="sm" className="rounded-full" onClick={open}>
+ <ImagePlus className="size-4" /> {photo ? "Another photo" : "Use a photo"}
+ </Button>
+ {library}
+ {photo && (
+ <Button variant="ghost" size="sm" className="rounded-full" onClick={() => setPhoto(null)}>
+ From the clip
+ </Button>
+ )}
+ </div>
+ )}
+ </Picker>
+ </div>
+ </div>
+ </div>
+ <div className="space-y-2">
+ <h3 className="text-[13px] font-semibold">Style</h3>
+ <Segmented label="Style" value={style} onChange={setStyle} options={FIX_FACES_STYLES.map(({ value, label }) => ({ value, label }))} />
+ <p className="text-[12px] text-muted-foreground">{FIX_FACES_STYLES.find((s) => s.value === style)?.hint}</p>
+ </div>
+ <div className="space-y-2">
+ <div className="flex justify-center">
+ <OwnSetupChip setup={FIX_FACES.model} />
+ </div>
+ <Button size="lg" className="h-11 w-full rounded-full text-[15px]" onClick={go} disabled={sending || !ready || (!photo && !auto)}>
+ {sending ? <Loader2 className="size-4 animate-spin" /> : <ScanFace className="size-4" />}
+ Fix the faces
+ </Button>
+ <p className="text-center text-[12px] text-muted-foreground">A few minutes for each 5 seconds of video.</p>
+ </div>
+ </Panel>
+ </div>
+ )}
+ </div>
+ <Results />
+ </ToolShell>
+ );
+}
+
+/** The runs so far, newest first, with each video's usual actions. */
+function Results() {
+ const runs = useGenerations({ features: [FIX_FACES.feature], limit: 24 });
+ const items = runs.data ?? [];
+ if (!items.length) return null;
+ return (
+ <section className="mx-auto mt-10 max-w-[1040px]" aria-labelledby="fix-faces-results">
+ <h3 id="fix-faces-results" className="mb-3 scroll-mt-20 font-heading text-[22px]">
+ Your fixed videos
+ </h3>
+ <Feed items={items} features={[FIX_FACES.feature]} />
+ </section>
+ );
+}
diff --git a/src/components/genjutsu/hooks.ts b/src/components/genjutsu/hooks.ts
index b8da3149..ac237187 100644
--- a/src/components/genjutsu/hooks.ts
+++ b/src/components/genjutsu/hooks.ts
@@ -50,6 +50,8 @@ export interface GenjutsuBody {
originalSound?: OriginalSound;
/** Client nonce: a repeat of it gets the first answer (see useSubmitGuard). */
requestId?: string;
+ /** The app the run was sent from: its result is listed with that app's runs. */
+ app?: "app-fix-faces";
}
export interface GenjutsuEstimate {
diff --git a/src/lib/catalog/apps.ts b/src/lib/catalog/apps.ts
index 640b3611..73f52639 100644
--- a/src/lib/catalog/apps.ts
+++ b/src/lib/catalog/apps.ts
@@ -1,6 +1,7 @@
import { QMA_MODEL } from "@/lib/qma";
import { ANGLES_2511_LORA } from "./open-tools";
import { BODY_DOUBLE, BODY_LOOKS } from "./body-double";
+import { FIX_FACES } from "./fix-faces";
import { CUSTOM_COLOUR, ITEMS, RECOLOR, RECOLOR_TEMPLATE, SWATCHES } from "./recolor";
import { CAST_LOOK } from "./soul-cards";
import type { InputSlot, Preset, PresetOption, PresetRoute } from "./types";
@@ -206,6 +207,26 @@ export const APPS: Preset[] = [
openAlso: [{ modelId: BODY_DOUBLE.clipModel, op: BODY_DOUBLE.clipOp }],
parity: "Every person's 3D body, pose and hands. Photos and clips run on a GPU; Live runs in your browser.",
}),
+ // Fix Faces: a tool of its own (src/components/fix-faces/fix-faces-tool.tsx) that runs Genjutsu's Finish with its Fix faces
+ // tool. With no photo, the clip's clearest face is found in the browser (src/lib/fix-faces/face-frame.ts).
+ app({
+ id: FIX_FACES.appId,
+ name: "Fix Faces",
+ category: "Identity",
+ description: "Soft or smeared faces in a video, redrawn sharp and true",
+ icon: "ScanFace",
+ hue: 330,
+ badges: ["new"],
+ tool: "fix-faces",
+ inputs: [
+ { key: "video", label: "Video", accept: "video", required: true, hint: `Up to ${FIX_FACES.maxSeconds} seconds, one main person` },
+ { key: "image", label: "Face photo", accept: "image", hint: "Optional: the clip's clearest face is used otherwise" },
+ ],
+ prompt: "Fix the faces",
+ cloud: null,
+ open: { modelId: FIX_FACES.model, op: "face-fix-video" },
+ parity: "Faces redrawn frame by frame with MiniMax H3 and pasted back at full size, the sound kept. Runs on a GPU.",
+ }),
app({
name: "Character Swap",
category: "Identity",
diff --git a/src/lib/catalog/fix-faces.ts b/src/lib/catalog/fix-faces.ts
new file mode 100644
index 00000000..1dd76a1c
--- /dev/null
+++ b/src/lib/catalog/fix-faces.ts
@@ -0,0 +1,58 @@
+/**
+ * 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,
+ * the same graph and steps (the part fitted, then the faces redrawn and pasted back), and its result is listed with
+ * the app's runs.
+ */
+export const FIX_FACES = {
+ appId: "app-fix-faces",
+ feature: "app:app-fix-faces",
+ model: "oss-h3-fix-faces",
+ /** The longest part one run fixes, in seconds: Fix faces' own limit (OPENJUTSU_LIMITS.facesMaxSeconds; tested to match). */
+ maxSeconds: 10,
+} as const;
+
+export type FixFacesStyle = "mouth" | "photo";
+
+/** The two ways to redraw, the default first (Genjutsu's names). */
+export const FIX_FACES_STYLES: readonly { value: FixFacesStyle; label: string; hint: string }[] = [
+ { value: "mouth", label: "Follow the mouth", hint: "Lips and expressions keep moving with the clip, so speech and singing stay in sync" },
+ { value: "photo", label: "Match the photo", hint: "Each face is drawn fresh from the photo: best for clips without speech" },
+];
+
+/** The before and after example: a dance whose faces came out soft, and the same dance fixed. */
+export const FIX_FACES_DEMO = {
+ video: "/samples/fix-faces/dance-compare.mp4?v=f916176a",
+ poster: "/samples/fix-faces/dance-compare.jpg?v=f3a4b3cb",
+ /** The example to try: the dance as it was made, its faces soft. */
+ clip: "/samples/fix-faces/dance-before.mp4?v=a6fab2f7",
+} as const;
+
+export type FixFacesClip = { url: string; name?: string; duration?: number; width?: number; height?: number };
+
+/** The part of the clip one run fixes: from the start, at most maxSeconds. */
+export function fixFacesRange(duration: number | undefined): { start: number; end: number } | undefined {
+ if (!duration || !Number.isFinite(duration) || duration <= 0) return undefined;
+ return { start: 0, end: Math.round(Math.min(duration, FIX_FACES.maxSeconds) * 1000) / 1000 };
+}
+
+/** The body of POST /api/genjutsu for one Fix Faces run. */
+export function fixFacesBody(o: { clip: FixFacesClip; photo: string; style: FixFacesStyle; requestId?: string }) {
+ const range = fixFacesRange(o.clip.duration);
+ return {
+ engine: "open" as const,
+ mode: "finish" as const,
+ modelId: FIX_FACES.model,
+ source: {
+ url: o.clip.url,
+ ...(o.clip.name && { name: o.clip.name.slice(0, 200) }),
+ ...(o.clip.duration && { duration: o.clip.duration }),
+ ...(o.clip.width && o.clip.height && { width: o.clip.width, height: o.clip.height }),
+ },
+ ...(range && { range }),
+ references: [o.photo],
+ finish: { tool: "faces" as const, faceStyle: o.style },
+ app: FIX_FACES.appId,
+ ...(o.requestId && { requestId: o.requestId }),
+ };
+}
diff --git a/src/lib/catalog/preset-recipe-routes.ts b/src/lib/catalog/preset-recipe-routes.ts
index d468066b..d22c930b 100644
--- a/src/lib/catalog/preset-recipe-routes.ts
+++ b/src/lib/catalog/preset-recipe-routes.ts
@@ -78,6 +78,7 @@ export const OWN_ROUTE_APPS: ReadonlySet<string> = new Set([
"app-restore-photo",
"app-head-swap",
"app-body-double",
+ "app-fix-faces",
"app-outfit-swap",
"app-photo-to-3d",
"app-watermark-remover",
diff --git a/src/lib/catalog/types.ts b/src/lib/catalog/types.ts
index 61218e28..faff29d2 100644
--- a/src/lib/catalog/types.ts
+++ b/src/lib/catalog/types.ts
@@ -1778,7 +1778,7 @@ export interface Preset {
/** Fuobe DoP's relight effects: a step that makes the start frame first, on each engine (src/lib/catalog/dop.ts). */
prestep?: PresetPrestep;
/** An app that is a tool of its own: its page renders that tool rather than the composer (Clean up voice, Relight, Any Angle, Tap to Recolor, Watermark Remover). */
- tool?: "clean-voice" | "relight" | "any-angle" | "recolor" | "body-double" | "watermark";
+ tool?: "clean-voice" | "relight" | "any-angle" | "recolor" | "body-double" | "fix-faces" | "watermark";
/** The recipe its preview was made with (src/lib/catalog/preset-recipe-book.json): the route it opens on follows it. */
recipe?: PresetRecipeBook;
}
diff --git a/src/lib/fix-faces/face-frame.ts b/src/lib/fix-faces/face-frame.ts
new file mode 100644
index 00000000..a867f7eb
--- /dev/null
+++ b/src/lib/fix-faces/face-frame.ts
@@ -0,0 +1,186 @@
+/**
+ * Fix Faces' face photo when the person adds none: the clip's clearest face, found in the browser. A few moments of the
+ * clip are looked at with Google's MediaPipe face detector (Apache-2.0, the task library Body Double Live already
+ * loads), and the frame whose face is sure, large and sharp wins. The face and some of the head and shoulders around
+ * it are cut out as the photo the redraw follows.
+ *
+ * The scoring is plain arithmetic (tested in tests/fix-faces.test.ts); the detector and the frames need a browser.
+ */
+
+const TASKS_VERSION = "0.10.21";
+const TASKS_BASE = `https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@${TASKS_VERSION}`;
+const MODEL = "https://storage.googleapis.com/mediapipe-models/face_detector/blaze_face_short_range/float16/1/blaze_face_short_range.tflite";
+
+/** How many moments of the clip are looked at. */
+export const FACE_FRAME_SAMPLES = 16;
+/** A face at least this share of the frame height counts as fully large; larger faces earn no more. */
+const FULL_SIZE = 0.25;
+
+/** A face in a frame, in the frame's pixels. */
+export type FaceBox = { x: number; y: number; width: number; height: number; score: number };
+
+/**
+ * Sharpness of a grey image: the variance of its Laplacian (4-neighbour). Blur and smear lower it; detail raises it.
+ * `grey` is row-major, `width` x `height`, values 0-255.
+ */
+export function sharpness(grey: ArrayLike<number>, width: number, height: number): number {
+ let n = 0, sum = 0, sq = 0;
+ for (let y = 1; y < height - 1; y++)
+ for (let x = 1; x < width - 1; x++) {
+ const i = y * width + x;
+ const l = grey[i - 1] + grey[i + 1] + grey[i - width] + grey[i + width] - 4 * grey[i];
+ sum += l;
+ sq += l * l;
+ n++;
+ }
+ if (!n) return 0;
+ const mean = sum / n;
+ return sq / n - mean * mean;
+}
+
+/**
+ * How good a face is as the redraw's photo: sure (the detector's score), large (up to FULL_SIZE of the frame height)
+ * and sharp. A face cut off by the frame's edge scores half.
+ */
+export function faceScore(face: FaceBox, frameWidth: number, frameHeight: number, faceSharpness: number): number {
+ const size = Math.min(1, face.height / frameHeight / FULL_SIZE);
+ const inside = face.x > 1 && face.y > 1 && face.x + face.width < frameWidth - 1 && face.y + face.height < frameHeight - 1;
+ return face.score * size * Math.sqrt(Math.max(0, faceSharpness)) * (inside ? 1 : 0.5);
+}
+
+/** The photo's box around a face: the head with some hair and neck, square, kept inside the frame. */
+export function photoBox(face: FaceBox, frameWidth: number, frameHeight: number): { x: number; y: number; size: number } {
+ const size = Math.min(frameWidth, frameHeight, Math.round(Math.max(face.width, face.height) * 2.4));
+ const cx = face.x + face.width / 2;
+ const cy = face.y + face.height * 0.55;
+ const x = Math.round(Math.min(Math.max(0, cx - size / 2), frameWidth - size));
+ const y = Math.round(Math.min(Math.max(0, cy - size / 2), frameHeight - size));
+ return { x, y, size };
+}
+
+/** The moments to look at: spread over the clip, away from its very first and last frames. */
+export function sampleTimes(duration: number, count = FACE_FRAME_SAMPLES): number[] {
+ if (!(duration > 0)) return [0];
+ const margin = Math.min(0.25, duration * 0.05);
+ const span = Math.max(0, duration - 2 * margin);
+ return Array.from({ length: count }, (_, i) => Math.round((margin + (span * (i + 0.5)) / count) * 1000) / 1000);
+}
+
+// The slice of the task library this file uses.
+type Detection = { boundingBox?: { originX: number; originY: number; width: number; height: number }; categories?: { score: number }[] };
+type Detector = { detect(image: HTMLCanvasElement): { detections: Detection[] }; close(): void };
+type Tasks = {
+ FilesetResolver: { forVisionTasks(base: string): Promise<unknown> };
+ FaceDetector: { createFromOptions(fileset: unknown, options: Record<string, unknown>): Promise<Detector> };
+};
+
+async function createDetector(): Promise<Detector> {
+ const tasks = (await import(/* webpackIgnore: true */ /* turbopackIgnore: true */ `${TASKS_BASE}/vision_bundle.mjs`)) as Tasks;
+ const fileset = await tasks.FilesetResolver.forVisionTasks(`${TASKS_BASE}/wasm`);
+ const make = (delegate: "GPU" | "CPU") =>
+ tasks.FaceDetector.createFromOptions(fileset, { baseOptions: { modelAssetPath: MODEL, delegate }, runningMode: "IMAGE", minDetectionConfidence: 0.5 });
+ try {
+ return await make("GPU");
+ } catch {
+ return make("CPU");
+ }
+}
+
+function seek(video: HTMLVideoElement, t: number): Promise<void> {
+ return new Promise((resolve, reject) => {
+ const done = () => {
+ video.removeEventListener("seeked", done);
+ video.removeEventListener("error", fail);
+ resolve();
+ };
+ const fail = () => {
+ video.removeEventListener("seeked", done);
+ reject(new Error("The clip can't be read here"));
+ };
+ video.addEventListener("seeked", done);
+ video.addEventListener("error", fail);
+ video.currentTime = t;
+ });
+}
+
+function greyOf(ctx: CanvasRenderingContext2D, box: { x: number; y: number; width: number; height: number }): { grey: Uint8ClampedArray; width: number; height: number } {
+ const w = Math.max(3, Math.round(box.width)), h = Math.max(3, Math.round(box.height));
+ const rgba = ctx.getImageData(Math.round(box.x), Math.round(box.y), w, h).data;
+ const grey = new Uint8ClampedArray(w * h);
+ for (let i = 0; i < w * h; i++) grey[i] = (rgba[i * 4] * 299 + rgba[i * 4 + 1] * 587 + rgba[i * 4 + 2] * 114) / 1000;
+ return { grey, width: w, height: h };
+}
+
+/** The faces in the canvas: the whole frame, then (for a wide frame) zoomed tiles of its upper part, where small faces are. */
+function facesIn(detector: Detector, frame: HTMLCanvasElement): FaceBox[] {
+ const read = (d: Detection, ox = 0, oy = 0, k = 1): FaceBox | null =>
+ d.boundingBox ? { x: ox + d.boundingBox.originX / k, y: oy + d.boundingBox.originY / k, width: d.boundingBox.width / k, height: d.boundingBox.height / k, score: d.categories?.[0]?.score ?? 0 } : null;
+ const found = detector.detect(frame).detections.map((d) => read(d)).filter((f): f is FaceBox => !!f);
+ if (found.length) return found;
+ // Small faces (a full figure on a runway) are under the short-range model's size: look again at 2x, in tiles.
+ const tile = document.createElement("canvas");
+ const tw = Math.round(frame.width / 2), th = Math.round(frame.height / 2);
+ tile.width = tw * 2;
+ tile.height = th * 2;
+ const tctx = tile.getContext("2d")!;
+ for (const [ox, oy] of [[0, 0], [tw / 2, 0], [tw, 0], [tw / 2, th / 2]] as const) {
+ tctx.drawImage(frame, ox, oy, tw, th, 0, 0, tile.width, tile.height);
+ for (const d of detector.detect(tile).detections) {
+ const f = read(d, ox, oy, 2);
+ if (f) found.push(f);
+ }
+ }
+ return found;
+}
+
+export type FaceFrame = { photo: Blob; time: number; face: FaceBox };
+
+/**
+ * The clip's clearest face as a JPEG photo, or null when no moment shows a face. `src` is the clip's URL (an object URL
+ * of the person's file works). Runs in the page; nothing leaves the browser.
+ */
+export async function pickFaceFrame(src: string, onProgress?: (done: number, total: number) => void): Promise<FaceFrame | null> {
+ const video = document.createElement("video");
+ video.muted = true;
+ video.playsInline = true;
+ video.preload = "auto";
+ video.crossOrigin = "anonymous";
+ video.src = src;
+ await new Promise<void>((resolve, reject) => {
+ video.onloadedmetadata = () => resolve();
+ video.onerror = () => reject(new Error("The clip can't be read here"));
+ });
+ const W = video.videoWidth, H = video.videoHeight;
+ const frame = document.createElement("canvas");
+ frame.width = W;
+ frame.height = H;
+ const ctx = frame.getContext("2d", { willReadFrequently: true })!;
+ const detector = await createDetector();
+ let best: { score: number; time: number; face: FaceBox } | null = null;
+ const times = sampleTimes(video.duration);
+ try {
+ for (const [i, t] of times.entries()) {
+ await seek(video, t);
+ ctx.drawImage(video, 0, 0, W, H);
+ for (const face of facesIn(detector, frame)) {
+ const g = greyOf(ctx, face);
+ const score = faceScore(face, W, H, sharpness(g.grey, g.width, g.height));
+ if (!best || score > best.score) best = { score, time: t, face };
+ }
+ onProgress?.(i + 1, times.length);
+ }
+ if (!best) return null;
+ await seek(video, best.time);
+ ctx.drawImage(video, 0, 0, W, H);
+ const box = photoBox(best.face, W, H);
+ const out = document.createElement("canvas");
+ out.width = out.height = Math.min(1024, box.size);
+ out.getContext("2d")!.drawImage(frame, box.x, box.y, box.size, box.size, 0, 0, out.width, out.height);
+ const photo = await new Promise<Blob | null>((resolve) => out.toBlob(resolve, "image/jpeg", 0.92));
+ return photo ? { photo, time: best.time, face: best.face } : null;
+ } finally {
+ detector.close();
+ video.removeAttribute("src");
+ video.load();
+ }
+}
diff --git a/src/lib/preset-covers.generated.ts b/src/lib/preset-covers.generated.ts
index 7dddd901..7ecbfd29 100644
--- a/src/lib/preset-covers.generated.ts
+++ b/src/lib/preset-covers.generated.ts
@@ -50,6 +50,7 @@ export const PRESET_COVERS: Record<string, PresetCoverEntry> = {
"app-expression-edit": ["4666152b","24e4fb1b"],
"app-face-swap": ["feda2683","7be531da"],
"app-figurine": ["58289aab","6f35b67d"],
+ "app-fix-faces": ["b06f4d33","263883e5"],
"app-fridge-ad": "2ac8c16a",
"app-fuobe-angles": ["a8c29228","b345ec66"],
"app-game-dump": ["ac39c93c","547049b4"],
diff --git a/src/lib/preset-featured.ts b/src/lib/preset-featured.ts
index 4c0cdec8..4333ed0a 100644
--- a/src/lib/preset-featured.ts
+++ b/src/lib/preset-featured.ts
@@ -11,7 +11,7 @@ const ORDER: Record<"app" | "motion" | "effect", string[]> = {
app: [
`
app-behind-the-scenes app-relight app-macroshot-product app-color-grading app-age-shift app-makeup-studio
- app-body-double app-angles app-shots app-match-lighting app-match-colors app-product-shot app-bullet-time-scene
+ app-body-double app-fix-faces app-angles app-shots app-match-lighting app-match-colors app-product-shot app-bullet-time-scene
app-bullet-time-splash app-chameleon app-outfit-swap app-tap-to-recolor app-steal-the-look app-outfit-shot app-sketch-to-real
app-video-face-swap app-video-background-remover app-watermark-remover app-clean-up-voice app-breakdown
`,
diff --git a/src/lib/preset-hd.generated.ts b/src/lib/preset-hd.generated.ts
index c25e716d..edbcc9e9 100644
--- a/src/lib/preset-hd.generated.ts
+++ b/src/lib/preset-hd.generated.ts
@@ -46,6 +46,7 @@ export const PRESET_HD: Record<string, { w: number[]; v: string; still?: number;
"app-expression-edit": { "w":[640,1024], "v":"07c09836" },
"app-face-swap": { "w":[640,1024], "v":"6c0bdacd" },
"app-figurine": { "w":[640,1024], "v":"04738bec" },
+ "app-fix-faces": { "w":[640,1024], "v":"b90f8527" },
"app-fridge-ad": { "w":[1024], "v":"f89ad850", "still":768 },
"app-fuobe-angles": { "w":[640,1024], "v":"1a878bf1" },
"app-game-dump": { "w":[640,1024], "v":"25d2872e" },
diff --git a/src/lib/preset-minis.generated.ts b/src/lib/preset-minis.generated.ts
index 5bca6873..2d7a6841 100644
--- a/src/lib/preset-minis.generated.ts
+++ b/src/lib/preset-minis.generated.ts
@@ -46,6 +46,7 @@ export const PRESET_MINIS: Record<string, string> = {
"app-expression-edit": "ac9558b1",
"app-face-swap": "400bffeb",
"app-figurine": "9f35a4e5",
+ "app-fix-faces": "65834df5",
"app-fridge-ad": "77b24cd2",
"app-fuobe-angles": "5e78337c",
"app-game-dump": "888a9784",
diff --git a/src/lib/preset-previews.generated.ts b/src/lib/preset-previews.generated.ts
index ca2a1660..c4291aab 100644
--- a/src/lib/preset-previews.generated.ts
+++ b/src/lib/preset-previews.generated.ts
@@ -345,6 +345,14 @@ export const PRESET_PREVIEWS: Record<string, PresetPreviewMedia> = {
"model": "minimax-h3",
"variant": "lean-json"
},
+ "app-fix-faces": {
+ "poster": "/previews/presets/app-fix-faces.jpg?v=b06f4d33",
+ "video": "/previews/presets/app-fix-faces.mp4?v=263883e5",
+ "run": "fix-faces-covers",
+ "engine": "comfyui",
+ "model": "oss-h3-fix-faces",
+ "variant": ""
+ },
"app-fridge-ad": {
"poster": "/previews/presets/app-fridge-ad.jpg?v=2ac8c16a",
"run": "comfyui-previews-2026-10",
diff --git a/src/server/genjutsu.ts b/src/server/genjutsu.ts
index df90ea02..7d808696 100644
--- a/src/server/genjutsu.ts
+++ b/src/server/genjutsu.ts
@@ -124,6 +124,8 @@ export interface GenjutsuBody {
finish?: FinishOptions;
/** Fuobe Reshoot: who's in it or what's in it. */
reshoot?: ReshootOptions;
+ /** The app the run was sent from: its result is listed with that app's runs. */
+ app?: "app-fix-faces";
}
/**
@@ -247,6 +249,8 @@ export const GenjutsuBodySchema = z.object({
originalSound: z.enum(ORIGINAL_SOUND_IDS).optional(),
/** A client nonce for one submit: a repeat gets the first answer (see once()). */
requestId: z.string().trim().min(8).max(64).optional(),
+ /** The app the run was sent from (Fix Faces sends Finish's faces): its result is listed with that app's runs. */
+ app: z.enum(["app-fix-faces"]).optional(),
});
/** The estimate is asked for before uploads finish: any URL stands in. */
@@ -739,7 +743,7 @@ export async function planGenjutsuRun(body: GenjutsuBody, viewer: GenjutsuViewer
const plan = planGenjutsu(input);
// The same check as the estimate: nothing starts when only some of the steps have a provider.
price(plan.steps, input);
- return { steps: plan.steps, final: plan.final };
+ return { steps: fromApp(plan.steps, plan.final, body), final: plan.final };
} catch (e) {
if (e instanceof ShortsError) throw e;
if (e instanceof ConnectComfyError) throw e;
@@ -748,6 +752,12 @@ export async function planGenjutsuRun(body: GenjutsuBody, viewer: GenjutsuViewer
}
}
+/** A run sent from an app (body.app): its finished video carries the app's feature and preset, so the app lists it. */
+function fromApp(steps: GenjutsuRun["steps"], final: string, body: GenjutsuBody): GenjutsuRun["steps"] {
+ if (body.app !== "app-fix-faces" || body.mode !== "finish" || body.finish?.tool !== "faces") return steps;
+ return steps.map((s) => (s.key === final ? { ...s, request: { ...s.request, feature: `app:${body.app}`, presetId: body.app } } : s));
+}
+
/** A planned run's steps as the requests they make, with how many earlier steps each waits for. */
export const genjutsuSteps = (run: GenjutsuRun): { request: GenerationRequest; deps: number }[] => run.steps.map((s) => ({ request: withChain(s), deps: s.after?.length ?? 0 }));
diff --git a/tests/fix-faces.test.ts b/tests/fix-faces.test.ts
new file mode 100644
index 00000000..2163f3d0
--- /dev/null
+++ b/tests/fix-faces.test.ts
@@ -0,0 +1,78 @@
+import { describe, expect, it } from "vitest";
+import { faceScore, photoBox, sampleTimes, sharpness } from "@/lib/fix-faces/face-frame";
+
+const flat = (w: number, h: number, v = 128) => new Array(w * h).fill(v);
+const checker = (w: number, h: number) => Array.from({ length: w * h }, (_, i) => ((i % w) + Math.floor(i / w)) % 2 ? 255 : 0);
+
+describe("Fix Faces' face frame", () => {
+ it("measures sharpness: a flat patch has none, fine detail has a lot", () => {
+ expect(sharpness(flat(16, 16), 16, 16)).toBe(0);
+ expect(sharpness(checker(16, 16), 16, 16)).toBeGreaterThan(10000);
+ expect(sharpness([1, 2, 3], 3, 1)).toBe(0);
+ });
+
+ it("prefers a sure, large, sharp face that is fully in the frame", () => {
+ const face = { x: 400, y: 100, width: 120, height: 150, score: 0.9 };
+ const base = faceScore(face, 1024, 768, 900);
+ expect(faceScore({ ...face, score: 0.5 }, 1024, 768, 900)).toBeLessThan(base);
+ expect(faceScore(face, 1024, 768, 100)).toBeLessThan(base);
+ expect(faceScore({ ...face, width: 40, height: 50 }, 1024, 768, 900)).toBeLessThan(base);
+ expect(faceScore({ ...face, x: 0 }, 1024, 768, 900)).toBe(base / 2);
+ // Larger than a quarter of the frame height earns no more.
+ expect(faceScore({ ...face, height: 300 }, 1024, 768, 900)).toBe(faceScore({ ...face, height: 200 }, 1024, 768, 900));
+ });
+
+ it("cuts a square photo around the head, inside the frame", () => {
+ const box = photoBox({ x: 500, y: 40, width: 60, height: 80, score: 1 }, 1024, 768);
+ expect(box.size).toBe(192);
+ expect(box.y).toBe(0);
+ expect(box.x + box.size).toBeLessThanOrEqual(1024);
+ const edge = photoBox({ x: 1000, y: 700, width: 20, height: 60, score: 1 }, 1024, 768);
+ expect(edge.x + edge.size).toBe(1024);
+ expect(edge.y + edge.size).toBe(768);
+ });
+
+ it("looks at moments spread over the clip, away from its ends", () => {
+ const t = sampleTimes(5.17);
+ expect(t).toHaveLength(16);
+ expect(t[0]).toBeGreaterThan(0.25);
+ expect(t[15]).toBeLessThan(5.17 - 0.25);
+ expect([...t].sort((a, b) => a - b)).toEqual(t);
+ expect(sampleTimes(0)).toEqual([0]);
+ });
+});
+
+describe("Fix Faces app", () => {
+ it("sends Genjutsu's Finish with the Fix faces tool, the first 10 seconds, the photo and the app", async () => {
+ const { fixFacesBody, FIX_FACES } = await import("@/lib/catalog/fix-faces");
+ const body = fixFacesBody({ clip: { url: "/api/files/a.mp4", name: "a.mp4", duration: 14.2, width: 1920, height: 1080 }, photo: "/api/files/face.jpg", style: "mouth", requestId: "abcdefgh12" });
+ expect(body).toMatchObject({
+ engine: "open",
+ mode: "finish",
+ modelId: FIX_FACES.model,
+ source: { url: "/api/files/a.mp4", duration: 14.2, width: 1920, height: 1080 },
+ range: { start: 0, end: 10 },
+ references: ["/api/files/face.jpg"],
+ finish: { tool: "faces", faceStyle: "mouth" },
+ app: "app-fix-faces",
+ });
+ const { GenjutsuBodySchema } = await import("@/server/genjutsu");
+ expect(GenjutsuBodySchema.safeParse(body).success).toBe(true);
+ // An unknown clip length leaves the range to the server.
+ expect(fixFacesBody({ clip: { url: "/api/files/b.mp4" }, photo: "/api/files/f.jpg", style: "photo" })).not.toHaveProperty("range");
+ });
+
+ it("is an app with its own tool, cover and route, defaulting to Follow the mouth", async () => {
+ const { getPreset } = await import("@/lib/catalog");
+ const { FIX_FACES_STYLES } = await import("@/lib/catalog/fix-faces");
+ const app = getPreset("app-fix-faces");
+ expect(app?.type).toBe("app");
+ expect(app?.tool).toBe("fix-faces");
+ expect(FIX_FACES_STYLES[0].value).toBe("mouth");
+ const { OPENJUTSU_LIMITS } = await import("@/lib/catalog/genjutsu");
+ const { FIX_FACES } = await import("@/lib/catalog/fix-faces");
+ expect(FIX_FACES.maxSeconds).toBe(OPENJUTSU_LIMITS.facesMaxSeconds);
+ const { PRESET_PREVIEWS } = await import("@/lib/preset-previews.generated");
+ expect(PRESET_PREVIEWS["app-fix-faces"]?.video).toMatch(/app-fix-faces\.mp4\?v=/);
+ });
+});
diff --git a/tests/own-setup-labels.test.ts b/tests/own-setup-labels.test.ts
index 1a502770..374dc618 100644
--- a/tests/own-setup-labels.test.ts
+++ b/tests/own-setup-labels.test.ts
@@ -118,7 +118,8 @@ describe("a model none of this install's GPUs holds", () => {
const own = poolOwnSetups((e) => !zEndpoints.includes(e), () => false);
const preset = PRESETS.find((p) => p.open?.modelId === Z.id);
// A preset on a model these GPUs still run.
- const other = PRESETS.find((p) => p.open && getModel(p.open.modelId)?.kind === Z.kind && !own[p.open.modelId] && p.open.modelId !== Z.id);
+ // (Not one whose model waits for its own GPU test: that one shows its own label.)
+ const other = PRESETS.find((p) => p.open && getModel(p.open.modelId)?.kind === Z.kind && !own[p.open.modelId] && p.open.modelId !== Z.id && !ownSetupOnly(p.open.modelId));
const rules = poolRulesOf({}, PRESETS.map((p) => ({ id: p.id, ...(p.open && getModel(p.open.modelId) && { model: { id: p.open.modelId, kind: getModel(p.open.modelId)!.kind } }) })), own);
it("shows a label from the pool rules in the model picker", () => {
diff --git a/tests/preset-recipes.test.ts b/tests/preset-recipes.test.ts
index 14526e8d..1bc3932d 100644
--- a/tests/preset-recipes.test.ts
+++ b/tests/preset-recipes.test.ts
@@ -67,7 +67,7 @@ describe("which presets get a recipe", () => {
// Graded presets whose clip was graded afterwards and that have no recipe in the book.
const gradesWithoutRecipe = [...MOTIONS, ...EFFECTS].filter((x) => x.grade && !recipeKind(x));
expect(new Set(none.map((x) => x.id))).toEqual(new Set([...gradesWithoutRecipe.map((x) => x.id), ...OWN_ROUTE_APPS]));
- expect(none).toHaveLength(36);
+ expect(none).toHaveLength(37);
for (const x of none) for (const engine of ["open", "cloud"] as const) expect(presetRecipe(x, engine, inCatalog), x.id).toBeUndefined();
});