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.
TypeScript ai-videocomfyuicreative-toolsgenerative-aiideogramimage-generationimage-to-3dimage-to-videoltx-videominimax-h3nextjsopen-sourceopen-weightsqwen-imagetext-to-imagevideo-generationwan
Merge main's newer work (Restore & colourise, Shorts Enhance and Regenerate to 1080p on a visitor's own setup)
Adarshf57bdddae7dd
diff --cc docs/public-signup.mdindex c3971cdb,47d1d280..02eead6a--- a/docs/public-signup.md+++ b/docs/public-signup.md@@@ -294,9 -299,11 +299,12 @@@ cloudflared tunnel --url http://localhoyour GPU, Character Swap's Sharpen and its 1080p / 2K / 4K on your GPU; and Kandinsky 6.0 Pro) show to everyone,marked "Runs on your own GPU · 48 GB" (Kandinsky Pro's choice says about 80 GB). An account runs them on its own GPUonly, when that GPU has the memory (`src/server/own-setup-run.ts`); otherwise it gets "Connect your GPU" (`connect-gpu`).- Cinema's exact orbit is marked "Runs on your own GPU · 48 GB or fal.ai key". Faceless's "Regenerate to 1080p" and- Shorts' Enhance run on an account's own GPU through their own routes (`.../regenerate`, `.../enhance`). The owner sees- these surfaces too; while they are held on this studio's GPU, the owner's run answers with what it needs ("needs a- GPU with 48 GB or more"). Cinema's "Make a prop from a picture" (Idol 3D) runs on a visitor's own GPU through Image to- 3D's route.+ Cinema's and the Video studio's exact orbit are marked "Runs on your own GPU · 48 GB or fal.ai key". Faceless's- "Regenerate to 1080p" shows on an account's finished open-source episodes with its label, and runs on its own GPU.- MiniMax H3's "Fast decode", once it is offered, carries its label in the same way.++ "Regenerate to 1080p" and Shorts' Enhance run on an account's own GPU through their own routes (`.../regenerate`,++ `.../enhance`). The owner sees these surfaces too; while they are held on this studio's GPU, the owner's run answers++ with what it needs ("needs a GPU with 48 GB or more"). Cinema's "Make a prop from a picture" (Idol 3D) runs on a++ visitor's own GPU through Image to 3D's route. MiniMax H3's "Fast decode", once it is offered, carries its label in++ the same way."Write the lyrics" and "Rewrite my prompt now" use the studio's AI helper and are hidden from guests and accounts.A song's stems come back as one zip: for an account it is fetched from public addresses only, within what its fileshave room for (128 MB at most, 256 MB unpacked), and each stem is saved to disk as it is unpacked.@@@ -394,15 -401,6 +403,14 @@@owner's library answers 404. Katana's runs are its own projects (`GET /api/katana`, `GET`/`DELETE/api/katana/<id>`): up to 50, another account's or the owner's read as 404, deleted with the account. A guest getsthe sign-up card.- - **Restore & colourise.** An account runs it (`POST /api/restore`) on its own GPU only, the same way as the Video- tools: every window, join and the sound put back on its own ComfyUI, with only its own clip and reference picture,- after the same checks. Its ComfyUI needs the gated Restore IC-LoRA; the run names the file before anything starts.- The prompt is the account's own words, or Fuobe's offline template filled with its few words. The prompt writer- (`POST /api/restore/prompt`) stays the owner's, because it uses the studio's AI helper. A cloud run is refused with- one sentence that says to switch to the open engine: the gated LoRA is never sent with a visitor's own key. Its price- check (`POST /api/restore/estimate`) is priced for the account's own GPU. With hosted runs on, an account without a- GPU of its own gets the "own setup" label (`video-tools:restore`) in the price check, and Run opens Connect your GPU.- A guest gets the sign-up card.++- **Restore & colourise.** An account runs it (`POST /api/restore`) on its own GPU or its own fal.ai key, the same way++ as the Video tools: every window, join and the sound put back on its own setup, with only its own clip and reference++ picture, after the same checks. The prompt is the account's own words, or Fuobe's offline template filled with its++ few words. The prompt writer (`POST /api/restore/prompt`) stays the owner's, because it uses the studio's AI helper.++ A cloud run that has no copy of the gated Restore IC-LoRA to send is refused with one sentence that says to switch to++ the open engine. Its price check (`POST /api/restore/estimate`) is priced as the account's run would go: on its own++ GPU, or on its own key for the cloud engine. With hosted runs on, an account with neither gets the "own setup" label++ (`video-tools:restore`) in the price check, and Run opens that setup. A guest gets the sign-up card.- **Audio tools.** An account runs Split soundtrack and Clean up dialogue, Video tools → Remove dialogue, Edit speech,Loop / extend, Join and Clean up voice (`POST /api/audio-tools`) the same way as Genjutsu's: every step on its ownComfyUI, or on its own fal.ai or Replicate key where a step is a cloud model, with only its own files, after the samediff --cc src/components/studio/model-picker.tsxindex 41053c68,6fa8aef6..275b2667--- a/src/components/studio/model-picker.tsx+++ b/src/components/studio/model-picker.tsx@@@ -92,7 -91,7 +93,8 @@@ export function ModelRow(needs,made,edits,+ setup,+ guest,}: {m: ModelDef;selected: boolean;@@@ -154,13 -153,11 +158,13 @@@</span>)}</span>- {needs ? (+ {setup && !needs ? (+ <OwnSetupChip setup={setup} className="h-auto min-h-4 max-w-[45%]" />+ ) : needs ? (// On a phone the short words, so the model's name keeps its room.<span className="shrink-0 text-right text-[11px] font-medium text-brand-text">- <span className="sm:hidden">Add key</span>- <span className="max-sm:hidden">{addKeyLabel(needs[0])}</span>+ <span className="sm:hidden">{guest ? "Your key" : "Add key"}</span>+ <span className="max-sm:hidden">{guest ? ownSetupLabel({ need: "key", provider: needs[0] }) : addKeyLabel(needs[0])}</span></span>) : (<span className="shrink-0 text-right text-[11px] text-muted-foreground tabular-nums">{pickerPrice(m, today, edits)}</span>@@@ -424,10 -441,10 +454,11 @@@ function PickerList(onStar={() => setStarred((s) => toggleIn(s, m.id))}gpu={m.engine === "open" ? badgeFor(badges, { modelId: m.id }) : null}gpuName={badges?.gpu}- needs={needsKey(m, status)}+ needs={rowNeeds(m)}+ guest={guest}made={m.id === madeWith}edits={editsClips}+ setup={ownSetup?.(m)}/></CommandItem>))}diff --cc src/server/restore.tsindex 877086f0,3e78fc12..3a86fdea--- a/src/server/restore.ts+++ b/src/server/restore.ts@@@ -289,61 -302,20 +302,28 @@@ export async function planRestoreRun(bo// a copy to send (a live one on fal, or the file on this machine), every piece would fail at submit, so the run is// refused before anything starts (a placeholder run needs no file).if (body.engine === "cloud" && !gatedReady("cloud") && !price(plan.steps).demo) {+ if (tenant()) throw new ShortsError("Restore this clip on your own GPU: switch to open source.", 422);throw new ShortsError(`${gatedHint("Lightricks' Restore IC-LoRA", RESTORE.loras.restore.page)}. A cloud run gets Fuobe's copy of the file, never your token`, 422);}- return startRestore({ plan, prompt, negative: input.negative, by });- }-- // ---------------------------------------------------------------------------- // An account's run (public sign-up)-- /** A run planned before it starts: its steps, and the words they use. */- export interface RestoreRun {- plan: ReturnType<typeof planRestore>;- prompt: string;- negative: string;- by: PromptAnswer["by"] | "you";+ return { steps: plan.steps, final: plan.final, prompt, negative: input.negative, by };}- /**- * An account's run in the cloud would carry the gated Restore IC-LoRA, which is never sent to a provider on the- * account's own key (src/server/loras.ts): it runs on the account's own GPU.- */- export const RESTORE_ON_OWN_GPU = "Restore & colourise runs on your own GPU. Switch the engine to open source to run it.";+ /** A planned run's steps, for an account's checks. */-export const restoreSteps = (r: RestoreRun): { request: GenerationRequest; deps: number }[] => r.steps.map((s) => ({ request: withChain(s), deps: s.after?.length ?? 0 }));++export const restoreSteps = (r: Pick<RestoreRun, "steps">): { request: GenerationRequest; deps: number }[] => r.steps.map((s) => ({ request: withChain(s), deps: s.after?.length ?? 0 }));+- /**- * An account's run, planned as its own GPU runs it (src/server/account-tool-run.ts): the prompt is the account's own- * words, or Fuobe's offline template filled with its hint. The studio's AI helper is never asked.- */- export async function planRestoreRun(body: z.infer<typeof RestoreBodySchema>): Promise<RestoreRun> {- if (body.engine === "cloud") throw new ShortsError(RESTORE_ON_OWN_GPU, 422);- mustMatchMode(body.engine);- mustBeOffered(body.engine);- const info = await probeSource(body.source.url);- const typed = body.prompt?.trim();- const offline = typed ? null : offlineRestorePrompt(body.hint);- const prompt = typed || offline!.prompt;- const { input } = planInput({ ...body, negative: body.negative?.trim() || offline?.negative }, info, prompt, true);- return { plan: planRestore(input), prompt, negative: input.negative, by: typed ? "you" : "offline" };- }-- /** A planned run's steps as the requests they make, with how many earlier steps each waits for (account-tool-run.ts). */- export const restoreSteps = (run: Pick<RestoreRun, "plan">): { request: GenerationRequest; deps: number }[] =>- run.plan.steps.map((s) => ({ request: withChain(s), deps: s.after?.length ?? 0 }));-- /** The steps an estimate's settings would run (with the estimate's stand-in prompt), for a price check. */++/** The steps an estimate's settings would run (with the estimate's stand-in words), for a price check. */+export function estimateRestoreSteps(body: z.infer<typeof RestoreEstimateSchema>): { request: GenerationRequest; deps: number }[] {+ mustMatchMode(body.engine);+ mustBeOffered(body.engine);+ const { input } = planInput(body as z.infer<typeof RestoreBodySchema>, {}, body.prompt?.trim() || offlineRestorePrompt(body.hint).prompt, false);- return restoreSteps({ plan: planRestore(input) });++ return restoreSteps(planRestore(input));+}- /** Start a planned run as one pipeline. Returns the finished video's generation and the words used. */- export function startRestore(run: RestoreRun): { final: Generation; items: Generation[]; prompt: string; negative: string; by: RestoreRun["by"] } {+ /** Start a planned run: the finished video's generation, every step, and the words used. */+ export function startRestore(r: RestoreRun): { final: Generation; items: Generation[]; prompt: string; negative: string; by: PromptAnswer["by"] | "you" } {let p: ReturnType<typeof createPipeline>;try {- p = createPipeline(run.plan.steps);+ p = createPipeline(r.steps);} catch (e) {throw new ShortsError((e as Error).message, 422);}diff --cc tests/public-signup.test.tsindex 490a03b3,c187243d..7a74f642--- a/tests/public-signup.test.ts+++ b/tests/public-signup.test.ts@@@ -241,10 -237,9 +237,9 @@@ describe("accounts never run on the ownexpect(r.headers.get(access.CONNECT_GPU_HEADER), p).toBeNull();expect((await r.json()).code, p).toBe("own-gpu-tool");}- // Cinema Studio's takes and the video tools (Remove a person's mask preview and "Redo from here", Katana's retry) run- // on its own GPU or key (tests/account-cinema.test.ts, tests/account-video-tools.test.ts): with neither, connect one- // first. A run route that ignores ?preview=1 isn't a price check.+ // Cinema Studio's takes and the video tools (Remove a person's mask preview and "Redo from here", Katana's retry,- // Restore & colourise) run- // on its own GPU or key (tests/account-cinema.test.ts, tests/account-video-tools.test.ts): with neither, connect one- // first. A run route that ignores ?preview=1 isn't a price check.++ // Restore & colourise) run on its own GPU or key (tests/account-cinema.test.ts, tests/account-video-tools.test.ts):++ // with neither, connect one first. A run route that ignores ?preview=1 isn't a price check.for (const p of ["/api/cinema/projects/p1/generate","/api/cinema/projects/p1/generate?preview=1",diff --cc tests/restore-account.test.tsindex 23728296,00000000..a7a83002mode 100644,000000..100644--- a/tests/restore-account.test.ts+++ b/tests/restore-account.test.ts@@@ -1,197 -1,0 +1,196 @@@+import fs from "node:fs";+import path from "node:path";+import { afterAll, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";+import { startFakeComfy, type FakeComfy } from "./helpers/fake-comfy-runner";+import { tempDir } from "./helpers/temp-dir";++vi.mock("next/server", async (importOriginal) => ({ ...(await importOriginal<typeof import("next/server")>()), connection: async () => {} }));++/**+ * Restore & colourise for a signed-in account (public sign-up): its run goes to the account's own ComfyUI (a stand-in+ * here) as one batch of its own steps, with only its own clip; the prompt is its own words or Fuobe's offline template,+ * and the studio's ComfyUI and AI helper are never reached. A guest signs up first; an account with no GPU is asked to- * connect one before anything is made; the cloud engine says to switch to the open engine.++ * connect one before anything is made.+ */+const dir = tempDir("fuobe-restore-account-");+process.env.FUOBE_DATA_DIR = dir;+process.env.COMFYUI_URL = "http://owner-comfy.test:8188";+process.env.OLLAMA_URL = "http://owner-llm.test:11434";+process.env.FUOBE_PUBLIC_SIGNUP = "1";+delete process.env.FUOBE_PASSWORD;+delete process.env.FUOBE_ALLOW_PRIVATE_URLS;+delete process.env.FUOBE_HOSTED_RUNS;+globalThis.__fuobeTestDiskFree = 1e13;++// Plain fetch is the install's own ComfyUI, its LLM or anything else: recorded, so a test sees that nothing reached them.+const realFetch = globalThis.fetch;+const fetched: string[] = [];+globalThis.fetch = (async (input: RequestInfo | URL, init?: RequestInit) => {+ const url = new URL(String(input instanceof Request ? input.url : input));+ if (url.hostname === "127.0.0.1") return realFetch(input, init);+ fetched.push(url.toString());+ if (url.host !== "owner-comfy.test:8188") return new Response("not stubbed", { status: 599 });+ if (url.pathname === "/system_stats") return Response.json({ system: { comfyui_version: "owner", ram_total: 1 }, devices: [] });+ return Response.json({});+}) as typeof fetch;++const auth = await import("@/server/auth");+const restoreRoute = await import("@/app/api/restore/route");+const estimateRoute = await import("@/app/api/restore/estimate/route");+const uploadsRoute = await import("@/app/api/uploads/route");+const gpuRoute = await import("@/app/api/account/gpu/route");+const access = await import("@/lib/guest-access");+const { getGeneration } = await import("@/server/generations");+const { db } = await import("@/server/db");+const { resetRates } = await import("@/server/rate");+const { clearAccountLoras } = await import("@/server/account-loras");+const { setSetting } = await import("@/server/settings");+const { saveFile } = await import("@/server/storage");+const { runAsTenant } = await import("@/server/tenant");- const { RESTORE_ON_OWN_GPU } = await import("@/server/restore");++const { NOT_YOURS_MESSAGE } = await import("@/server/storage");+const { offlineRestorePrompt, RESTORE } = await import("@/lib/catalog/restore");++const CLIP = fs.readFileSync(path.join(__dirname, "fixtures/shorts-12s.mp4"));++let fake: FakeComfy;+let a = "";+let c = "";+const cookies: Record<string, string> = {};+beforeAll(async () => {+ fake = await startFakeComfy({ loras: [], delayMs: 0, output: "video" });+ globalThis.__fuobeTestGpuPort = fake.port;+ auth.setPassword("install password");+ // The owner's AI helper is set up: an account's run must still never use it.+ setSetting("enhanceProvider", "ollama");+ for (const [k, email] of [+ ["a", "[email protected]"],+ ["c", "[email protected]"],+ ] as const) {+ const id = auth.createAccount(email, "long enough").id;+ cookies[k] = `${auth.SESSION_COOKIE}=${auth.createSession(id).value}`;+ if (k === "a") a = id;+ else c = id;+ }+ // A links its own ComfyUI; C has neither a GPU nor a key.+ expect((await gpuRoute.PUT(json("/api/account/gpu", "PUT", { url: fake.url }, "a"))).status).toBe(200);+});+afterAll(async () => {+ globalThis.fetch = realFetch;+ globalThis.__fuobeTestGpuPort = undefined;+ globalThis.__fuobeTestDiskFree = undefined;+ await fake.close();+});+beforeEach(() => {+ resetRates();+ clearAccountLoras(a);+ db().prepare("UPDATE generations SET status = 'canceled' WHERE status IN ('queued', 'running') AND json_extract(request_json, '$.account') IS NOT NULL").run();+});++function json(url: string, method: string, body: unknown, who?: string): Request {+ const text = JSON.stringify(body);+ return new Request(`http://localhost:3000${url}`, {+ method,+ headers: { host: "localhost:3000", "content-type": "application/json", "content-length": String(Buffer.byteLength(text)), ...(who && { cookie: cookies[who] }) },+ body: text,+ });+}++async function upload(who: string, data: Buffer, type: string, name: string): Promise<string> {+ const r = await uploadsRoute.POST(new Request("http://localhost:3000/api/uploads", { method: "POST", headers: { host: "localhost:3000", cookie: cookies[who], "content-type": type, "x-file-name": name, "content-length": String(data.length) }, body: new Uint8Array(data) }));+ expect(r.status, await r.clone().text()).toBe(201);+ return ((await r.json()) as { url: string }).url;+}++/** Send a run; a LoRA its ComfyUI lacks is put there (the 409 names it), then it is sent again. */+async function start(send: () => Promise<Response>): Promise<Response> {+ let r = await send();+ if (r.status === 409) {+ const j = (await r.clone().json()) as { code: string; fix?: { items: { file: string }[] } };+ if (j.code === "comfy_missing_model" && j.fix) {+ fake.opts.loras = [...(fake.opts.loras ?? []), ...j.fix.items.map((i) => i.file)];+ clearAccountLoras(a);+ r = await send();+ }+ }+ return r;+}++/** What the studio reads of its own ComfyUI and AI helper to say whether they answer: never a job or a call to them. */+const notStatus = (u: string) => !/\/(system_stats|api\/tags)$/.test(u);+const count = () => (db().prepare("SELECT COUNT(*) AS n FROM generations").get() as { n: number }).n;+const source = (url: string) => ({ url, name: "old.mp4", duration: 12, fps: 16, width: 72, height: 128, hasAudio: true });++describe("Restore & colourise for an account", () => {+ it("runs on its own ComfyUI as one batch of its own steps, with Fuobe's offline prompt; nothing of the studio's is reached", async () => {+ const clip = await upload("a", CLIP, "video/mp4", "old.mp4");+ fetched.length = 0;+ const hint = "a market in 1923";+ const r = await start(() => restoreRoute.POST(json("/api/restore", "POST", { engine: "open", source: source(clip), hint, requestId: "restore-run-1" }, "a")));+ expect(r.status, await r.clone().text()).toBe(201);+ const body = (await r.json()) as { final: { id: string }; items: { id: string; batchId: string | null }[]; prompt: string; by: string };+ expect(body.by).toBe("offline");+ expect(body.prompt).toBe(offlineRestorePrompt(hint).prompt);+ expect(new Set(body.items.map((g) => g.batchId)).size).toBe(1);+ for (const { id } of body.items) {+ const g = getGeneration(id)!;+ expect(g.request.account, id).toBe(a);+ expect(g.provider, id).toBe("comfyui");+ }+ expect(body.items.some(({ id }) => getGeneration(id)!.modelId === RESTORE.model)).toBe(true);+ expect(getGeneration(body.final.id)!.request.feature).toBe(RESTORE.feature);+ expect(fetched.filter(notStatus)).toEqual([]);+ // A repeat of the same request id gets the first run.+ const n = count();+ const again = await restoreRoute.POST(json("/api/restore", "POST", { engine: "open", source: source(clip), hint, requestId: "restore-run-1" }, "a"));+ expect(((await again.json()) as { final: { id: string } }).final.id).toBe(body.final.id);+ expect(count()).toBe(n);+ });++ it("keeps the account's own words when it wrote the prompt", async () => {+ const clip = await upload("a", CLIP, "video/mp4", "old2.mp4");+ const r = await start(() => restoreRoute.POST(json("/api/restore", "POST", { engine: "open", source: source(clip), prompt: "a harbour at dawn, natural colour" }, "a")));+ expect(r.status, await r.clone().text()).toBe(201);+ const body = (await r.json()) as { prompt: string; by: string };+ expect(body).toMatchObject({ prompt: "a harbour at dawn, natural colour", by: "you" });+ });+- it("says to switch to the open engine for a cloud run, before anything is made", async () => {- const clip = await upload("a", CLIP, "video/mp4", "old3.mp4");++ it("takes only its own clip: another account's real upload is refused as not its own, before anything is made", async () => {++ const theirs = runAsTenant({ kind: "account", id: c }, () => saveFile({ data: CLIP, contentType: "video/mp4", source: "upload", name: "theirs.mp4" }).url);+ const n = count();- const r = await restoreRoute.POST(json("/api/restore", "POST", { engine: "cloud", source: source(clip) }, "a"));- expect(r.status).toBe(422);- expect((await r.json()).error).toBe(RESTORE_ON_OWN_GPU);- expect(count()).toBe(n);- });-- it("takes only its own clip", async () => {- const n = count();- const r = await restoreRoute.POST(json("/api/restore", "POST", { engine: "open", source: source("/api/files/uploads/someone-else.mp4") }, "a"));- expect(r.status).toBeGreaterThanOrEqual(400);++ fetched.length = 0;++ const r = await restoreRoute.POST(json("/api/restore", "POST", { engine: "open", source: source(theirs), requestId: "restore-theirs" }, "a"));++ expect(r.status, await r.clone().text()).toBe(403);++ expect(await r.json()).toEqual({ error: NOT_YOURS_MESSAGE, code: "input-not-yours" });+ expect(count()).toBe(n);++ expect(fetched.filter(notStatus)).toEqual([]);++ // Its own copy of the same clip runs.++ const mine = await upload("a", CLIP, "video/mp4", "mine.mp4");++ const ok = await start(() => restoreRoute.POST(json("/api/restore", "POST", { engine: "open", source: source(mine), requestId: "restore-mine" }, "a")));++ expect(ok.status, await ok.clone().text()).toBe(201);+ });++ it("asks an account with neither a GPU nor a key to connect one, before anything is made", async () => {+ const clip = runAsTenant({ kind: "account", id: c }, () => saveFile({ data: CLIP, contentType: "video/mp4", source: "upload", name: "c.mp4" }).url);+ const n = count();+ const r = await restoreRoute.POST(json("/api/restore", "POST", { engine: "open", source: source(clip) }, "c"));+ expect(r.status, await r.clone().text()).toBe(403);+ expect(r.headers.get(access.CONNECT_GPU_HEADER)).toBe("1");+ expect((await r.json()).code).toBe("connect-gpu");+ expect(count()).toBe(n);+ });++ it("gives a guest the sign-up card", async () => {+ const r = await restoreRoute.POST(json("/api/restore", "POST", { engine: "open", source: source("/api/files/uploads/x.mp4") }));+ expect(r.status).toBe(401);+ expect(r.headers.get(access.GUEST_HEADER)).toBe("1");+ });++ it("prices an account's run on its own GPU, with the hosted runs off as today", async () => {+ const r = await estimateRoute.POST(json("/api/restore/estimate", "POST", { engine: "open", source: source("/api/files/uploads/x.mp4") }, "a"));+ expect(r.status, await r.clone().text()).toBe(200);+ const e = await r.json();+ expect(e).toMatchObject({ engine: "open", demo: false, costUsd: 0 });+ expect(e).not.toHaveProperty("place");+ expect(e).not.toHaveProperty("loraReady");+ });+});