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.

Upscale hub: FLUX.3's optional prompt, the size an API's factor range really makes, and no upscale that wouldn't enlarge the clip

Claudeb2a50e65902a
diff --git a/src/components/studio/composer.tsx b/src/components/studio/composer.tsx
index b10cd772..09a273c3 100644
--- a/src/components/studio/composer.tsx
+++ b/src/components/studio/composer.tsx
@@ -14,7 +14,7 @@ import { formatsOf } from "@/lib/av/formats";
import { enhance, useClipFacts, useCreateGeneration, useElements, useEngine, useHydrated, useStatus } from "@/lib/api";
import { applyMentions, type StudioElement } from "@/lib/catalog/elements";
import { applySketch, stripMotionPaths } from "@/lib/catalog/sketch";
-import { blockerFor, clipOutcome, costLabel, filterModels, firstMissingSlot, namedImageSlots, PLACEHOLDER, pushRecent, settingsShape } from "@/lib/composer";
+import { blockerFor, clipBlocker, clipOutcome, costLabel, filterModels, firstMissingSlot, namedImageSlots, PLACEHOLDER, pushRecent, settingsShape, showsPrompt } from "@/lib/composer";
import { formatCost } from "@/lib/format";
import { cn } from "@/lib/utils";
import { AttachMenu } from "./attach-menu";
@@ -249,6 +249,10 @@ export function Composer({ docked }: { docked: boolean }) {
planError = (e as Error).message;
}
}
+ // What the clip's header rules out before Generate (as the server does): an upscale that wouldn't enlarge it,
+ // an open tool that holds the whole clip in more RAM than the ComfyUI can spare.
+ const clipProblem = config.clipFacts ? clipBlocker(studioOp ?? op, facts, draft.params, model, status?.providers.comfyui?.ramBytes) : null;
+ if (clipProblem && !planError) planError = clipProblem;
if (signed.blocker) planError = signed.blocker;
// Models that take no prompt (try-on, 3D, transcription, upscalers), or can run without one, never ask for one.
const promptMissing =
@@ -319,7 +323,8 @@ export function Composer({ docked }: { docked: boolean }) {
// Studios with the Moodboard chip pick Soul's styles there (its Curated tab), not in a second Style chip.
const soulStyles = !!config.signature && (opts.presets?.source === "soul-v1" || opts.presets?.source === "soul-v2");
const opNote = op && model ? routesFor(model, op)[0]?.note : undefined;
- const showPrompt = !config.hidePrompt && preset?.userPrompt !== "none" && !opts.promptless;
+ // Booleans in, not the model's options object: the React Compiler keeps the memos above.
+ const showPrompt = showsPrompt({ hidePrompt: config.hidePrompt, modelPrompt: config.modelPrompt }, { promptless: !!opts.promptless, promptOptional: !!opts.promptOptional }, preset?.userPrompt);
const effectiveOp = studioOp ?? op;
// SDR to HDR, Export: every format the studio's models on this engine write; picking one this model doesn't
// write moves the request to the model that does (EXR frames → LTX 2.3 HDR on the cloud).
@@ -336,7 +341,8 @@ export function Composer({ docked }: { docked: boolean }) {
// "via LTX 2.3 HDR": the name without what it makes in brackets (the format already says it).
return m && m.id !== model?.id ? `via ${m.name.replace(/\s*\([^)]*\)$/, "")}` : undefined;
};
- const shape = settingsShape(model, effectiveOp, config.kind, showPrompt, p, config.ops, studioFormats);
+ // Enhance writes a scene; a tool's optional words (FLUX.3 Upscale's details) stay as typed.
+ const shape = settingsShape(model, effectiveOp, config.kind, showPrompt && !config.hidePrompt, p, config.ops, studioFormats);
const outcome = config.clipFacts && draft.slots.video?.ref ? clipOutcome(effectiveOp, facts, p, model) : null;
const video = draft.slots.video?.ref;
const alternative = config.comfyOnly?.alternative;
@@ -504,7 +510,7 @@ export function Composer({ docked }: { docked: boolean }) {
value={draft.prompt}
onChange={(v) => setDraft({ prompt: v })}
onSubmit={submit}
- placeholder={preset?.promptPlaceholder ?? config.placeholder}
+ placeholder={preset?.promptPlaceholder ?? (config.hidePrompt && config.modelPrompt ? config.modelPrompt : config.placeholder)}
elements={elements}
collapsed={collapsed}
/>
diff --git a/src/components/studio/studio-context.tsx b/src/components/studio/studio-context.tsx
index fa723f35..59e21f28 100644
--- a/src/components/studio/studio-context.tsx
+++ b/src/components/studio/studio-context.tsx
@@ -33,6 +33,11 @@ export interface StudioConfig {
/** Prompt is optional (e.g. motions, upscale). */
promptOptional?: boolean;
hidePrompt?: boolean;
+ /**
+ * The prompt box's placeholder for a model that reads an optional prompt in a studio that hides it
+ * (Upscale: FLUX.3 Upscale's details to preserve or enhance); without it such a model gets no box either.
+ */
+ modelPrompt?: string;
/** Paint tools offered on the first image: an inpaint mask and/or freehand drawing. */
sketch?: ("mask" | "draw")[];
/** Open the editor as soon as an image is attached (Inpaint). */
diff --git a/src/lib/av/upscale.ts b/src/lib/av/upscale.ts
index fb8dbfa5..0447b62e 100644
--- a/src/lib/av/upscale.ts
+++ b/src/lib/av/upscale.ts
@@ -18,7 +18,8 @@ export function targetShortEdge(resolution: string | undefined): number | undefi
/**
* The factor an upscaler that takes one needs to reach `resolution` from a clip of `source` size: target ÷
- * shorter edge, kept within the API's min–max and rounded to 2 decimals. "Original" is 1 (enhance only).
+ * shorter edge, kept within the API's min–max and rounded to 3 decimals (1080p → 1440p is 1.333, which lands on
+ * 2560×1440; 1.33 would make 2554×1436). "Original" is 1 (enhance only).
* Undefined when the size or the tier is unknown.
*/
export function upscaleFactorFor(resolution: string | undefined, source: { width: number; height: number } | undefined, min = 1, max = 4): number | undefined {
@@ -27,7 +28,7 @@ export function upscaleFactorFor(resolution: string | undefined, source: { width
const target = targetShortEdge(resolution);
const short = source ? Math.min(source.width, source.height) : 0;
if (!target || !(short > 0)) return undefined;
- return Math.round(Math.max(lo, Math.min(max, target / short)) * 100) / 100;
+ return Math.round(Math.max(lo, Math.min(max, target / short)) * 1000) / 1000;
}
/** The size a clip comes out at for `resolution` (its shape kept, even numbers), or undefined when unknown. */
@@ -38,3 +39,40 @@ export function upscaledSize(source: { width: number; height: number } | undefin
const even = (n: number) => Math.max(2, Math.round(n / 2) * 2);
return { width: even(source.width * k), height: even(source.height * k) };
}
+
+/**
+ * Why an upscale to `resolution` would not enlarge a clip whose shorter edge is `short` px (null when it does,
+ * or when the tier is "Original" / unknown): the same words the composer shows and the server refuses with.
+ */
+export function upscaleProblem(resolution: string | undefined, offered: string[] | undefined, short: number): string | null {
+ const target = targetShortEdge(resolution);
+ if (!target || !(short > 0) || target > short) return null;
+ const higher = (offered ?? []).some((r) => (targetShortEdge(r) ?? 0) > short);
+ const original = (offered ?? []).some((r) => r.toLowerCase() === "original");
+ const shrink = target < short ? `: ${resolution} would make it smaller` : "";
+ const next = higher ? " — pick a higher resolution" : " — this model upscales no further";
+ return `This clip is already ${short}p${shrink}${next}${original ? ", or Original to only clean it up" : ""}`;
+}
+
+/**
+ * The tier an upscale runs at for a clip of `source` size: the one asked for when it enlarges the clip. A
+ * tier the model only defaulted to (`picked` false) moves up to the smallest offered tier that does, else to
+ * "Original" (clean-up only) when the model offers it; a tier the caller picked that doesn't is refused.
+ */
+export function upscaleTier(
+ resolution: string | undefined,
+ offered: string[] | undefined,
+ source: { width: number; height: number } | undefined,
+ picked: boolean,
+): { resolution: string | undefined } | { error: string } {
+ const short = source ? Math.min(source.width, source.height) : 0;
+ const problem = upscaleProblem(resolution, offered, short);
+ if (!problem) return { resolution };
+ if (picked) return { error: problem };
+ const up = (offered ?? [])
+ .map((r) => ({ r, edge: targetShortEdge(r) ?? 0 }))
+ .filter((t) => t.edge > short)
+ .sort((a, b) => a.edge - b.edge)[0]?.r;
+ const original = (offered ?? []).find((r) => r.toLowerCase() === "original");
+ return up || original ? { resolution: up ?? original } : { error: problem };
+}
diff --git a/src/lib/catalog/types.ts b/src/lib/catalog/types.ts
index 93e6d57e..c6588bc7 100644
--- a/src/lib/catalog/types.ts
+++ b/src/lib/catalog/types.ts
@@ -425,6 +425,11 @@ export interface ModelRoute {
/** fal endpoint id, replicate "owner/name", or ComfyUI workflow id from the manifest. */
endpoint: string;
map?: FieldMap;
+ /**
+ * The parts of `map` the composer previews a result with ("1920×1080 → 2880×1620", an EXR frame count),
+ * kept by slimModel when it drops the field maps for the browser. The server reads `map`.
+ */
+ preview?: Pick<FieldMap, "upscaleFactor" | "numFrames">;
/** Optional note shown in the UI (e.g. "uses Lightx2v 4-step LoRA"). */
note?: string;
/** Same model with LoRA support (fal's `/lora` variants): used when a trained identity is mentioned. */
diff --git a/src/lib/composer.ts b/src/lib/composer.ts
index 566a0970..aef5e7ab 100644
--- a/src/lib/composer.ts
+++ b/src/lib/composer.ts
@@ -5,7 +5,8 @@
*/
import { FORMAT_INFO } from "./av/formats";
import { fpsPlan, fpsSummary } from "./av/fps";
-import { targetShortEdge, upscaledSize } from "./av/upscale";
+import { targetShortEdge, upscaledSize, upscaleFactorFor, upscaleTier } from "./av/upscale";
+import { wholeClipProblem, wholeClipTool } from "./av/video-finish";
import type { Engine, GenParams, InputSlot, MediaKind, ModelDef, Operation, VideoFormat } from "./catalog/types";
// ---------------------------------------------------------------------------
@@ -104,6 +105,19 @@ export function settingsSummary(shape: SettingsShape, params: GenParams, model?:
return parts;
}
+/**
+ * Whether the composer shows the prompt box: not for a preset or model that takes no prompt; in a studio
+ * that hides it, only for a model that reads an optional prompt when the studio words one (`modelPrompt`).
+ */
+export function showsPrompt(
+ studio: { hidePrompt?: boolean; modelPrompt?: string },
+ options: Pick<ModelDef["options"], "promptless" | "promptOptional"> | undefined,
+ presetPrompt?: "none" | "optional" | "required",
+): boolean {
+ if (presetPrompt === "none" || options?.promptless) return false;
+ return !studio.hidePrompt || (!!studio.modelPrompt && !!options?.promptOptional);
+}
+
/** The output format a request writes: the one picked, else the model's default or first, else the studio's first. */
export function formatOf(params: GenParams, model: Pick<ModelDef, "options" | "defaults"> | undefined, studio: VideoFormat[] = []): VideoFormat | undefined {
return params.format ?? model?.defaults?.format ?? model?.options.formats?.[0] ?? studio[0];
@@ -123,22 +137,39 @@ export function clipOutcome(
op: Operation | undefined,
facts: { width?: number; height?: number; fps?: number; duration?: number } | undefined,
params: GenParams,
- model: Pick<ModelDef, "engine" | "options" | "defaults"> | undefined,
+ model: (Pick<ModelDef, "engine" | "options" | "defaults"> & Partial<Pick<ModelDef, "name" | "routes">>) | undefined,
): string | null {
if (!facts || !model) return null;
const { width, height, fps, duration } = facts;
const size = width && height ? `${width}×${height}` : "";
const length = duration ? clipSeconds(duration) : "";
+ // "LTX 2.3 HDR", not "LTX 2.3 HDR (EXR frames)".
+ const name = model.name?.replace(/\s*\([^)]*\)$/, "");
+ // The route's field-map rules (the browser's catalog keeps them as `preview`).
+ const rules = (o: Operation) => {
+ const r = model.routes?.find((x) => x.op === o);
+ return r?.map ?? r?.preview;
+ };
if (op === "upscale-video") {
if (!size) return null;
const res = params.resolution ?? model.defaults?.resolution;
- const target = targetShortEdge(res);
- const short = Math.min(width!, height!);
const rate = params.targetFps ? ` · ${params.targetFps} fps` : "";
if (res?.toLowerCase() === "original") return `${size}, cleaned up at its own size${rate}`;
- if (target && target <= short) return `This clip is already ${short}p — pick a higher resolution${model.options.resolutions?.some((r) => r.toLowerCase() === "original") ? ", or Original to only clean it up" : ""}`;
- const out = upscaledSize({ width: width!, height: height! }, res);
- return out ? `${size} → ${out.width}×${out.height}${rate}` : null;
+ const short = Math.min(width!, height!);
+ // A tier that wouldn't enlarge the clip: a default moves up (as the server does), a picked one is refused.
+ const tier = upscaleTier(res, model.options.resolutions, { width: width!, height: height! }, params.resolution !== undefined);
+ if ("error" in tier) return tier.error;
+ const moved = tier.resolution !== res ? ` · ${tier.resolution}, as the clip is already ${short}p` : "";
+ if (tier.resolution?.toLowerCase() === "original") return `${size}, cleaned up at its own size${moved}${rate}`;
+ // An API that takes a factor keeps it within its range: say what that makes, not the tier.
+ const range = rules("upscale-video")?.upscaleFactor;
+ const target = targetShortEdge(tier.resolution);
+ const factor = range ? upscaleFactorFor(tier.resolution, { width: width!, height: height! }, range.min, range.max) : undefined;
+ const out = upscaledSize({ width: width!, height: height! }, tier.resolution, factor);
+ if (!out) return null;
+ const clamped = factor !== undefined && target ? Math.abs(factor - target / short) > 0.01 : false;
+ const why = clamped ? ` (${name ?? "this model"} upscales ${factor! > target! / short ? "at least" : "at most"} ${factor}×)` : "";
+ return `${size} → ${out.width}×${out.height}${why}${moved}${rate}`;
}
if (op === "interpolate") {
const slowdown = Math.max(1, params.slowdown ?? 1);
@@ -157,14 +188,47 @@ export function clipOutcome(
if (op === "sdr-to-hdr" || op === "export-video") {
const f = formatOf(params, model);
const info = f ? FORMAT_INFO[f] : undefined;
- const frames = f === "exr" && duration && fps ? ` (${Math.round(duration * fps)} frames)` : "";
const head = [size, length].filter(Boolean).join(" · ");
if (!head) return null;
+ // EXR frames: every frame of the clip, or what a frame-count route renders (LTX 2.3 HDR: 24 fps, 481 at most).
+ let frames = "";
+ const count = rules(op)?.numFrames;
+ if (f === "exr" && duration && count) {
+ const rate = params.fps && params.fps > 0 ? params.fps : count.fps;
+ const want = duration * rate;
+ const n = Math.round(Math.max(count.min ?? 1, Math.min(count.max ?? Infinity, want)));
+ frames = ` (${n} frames at ${rate} fps${n < want - 0.5 ? `: only the first ${clipSeconds(n / rate)}, the most ${name ?? "it"} takes` : ""})`;
+ } else if (f === "exr" && duration && fps) frames = ` (${Math.round(duration * fps)} frames)`;
return info ? `${head} → ${info.short}${frames}, .${info.ext}` : head;
}
return null;
}
+
+/**
+ * What the attached clip's header rules out before Generate, in the server's words (Upscale hub): a tier that
+ * wouldn't enlarge the clip (one picked; a default moves up), or an open tool that holds the whole clip (FPS
+ * Boost, SDR to HDR, EXR export) in more memory than half the ComfyUI's RAM (`ramBytes`, when it said).
+ */
+export function clipBlocker(
+ op: Operation | undefined,
+ facts: { width?: number; height?: number; fps?: number; duration?: number } | undefined,
+ params: GenParams,
+ model: Pick<ModelDef, "engine" | "options" | "defaults"> | undefined,
+ ramBytes: number | undefined,
+): string | null {
+ if (!facts?.width || !facts.height || !model) return null;
+ if (op === "upscale-video") {
+ const tier = upscaleTier(params.resolution ?? model.defaults?.resolution, model.options.resolutions, { width: facts.width, height: facts.height }, params.resolution !== undefined);
+ return "error" in tier ? tier.error : null;
+ }
+ if (model.engine !== "open" || !ramBytes || !facts.duration || !facts.fps) return null;
+ const target = params.targetFps ?? model.defaults?.targetFps;
+ const m = op === "interpolate" && target ? fpsPlan(facts.fps, target, Math.max(1, params.slowdown ?? 1)).multiplier : 1;
+ const tool = wholeClipTool(op, formatOf(params, model), m);
+ return tool ? wholeClipProblem(tool, facts, ramBytes) : null;
+}
+
/** How many settings differ from their defaults beyond what the summary shows (seed, negative prompt, sliders). */
export function hiddenChanges(params: GenParams, negativePrompt: string, model?: Pick<ModelDef, "options">): number {
let n = 0;
diff --git a/src/lib/studio-catalog.ts b/src/lib/studio-catalog.ts
index 6bd9c57a..02c5b42b 100644
--- a/src/lib/studio-catalog.ts
+++ b/src/lib/studio-catalog.ts
@@ -15,13 +15,15 @@ export interface StudioCatalog {
lookup?: ModelDef[];
}
-/** A model without its provider field maps (server-only detail). */
+/** A model without its provider field maps (server-only detail), keeping what the composer previews results with. */
export function slimModel(m: ModelDef): ModelDef {
return {
...m,
routes: m.routes.map((r) => {
const copy = { ...r };
delete copy.map;
+ const { upscaleFactor, numFrames } = r.map ?? {};
+ if (upscaleFactor || numFrames) copy.preview = { ...(upscaleFactor && { upscaleFactor }), ...(numFrames && { numFrames }) };
return copy;
}),
};
diff --git a/src/lib/studios.ts b/src/lib/studios.ts
index 68e76bb0..366a47a7 100644
--- a/src/lib/studios.ts
+++ b/src/lib/studios.ts
@@ -119,6 +119,7 @@ export const UPSCALE_STUDIO: StudioConfig = {
defaultModels: { cloud: "topaz-image", open: "oss-upscale-image" },
promptOptional: true,
hidePrompt: true,
+ modelPrompt: "Optional: details to keep or bring out, e.g. “the lettering on the shop sign”",
controlsTitle: "Options",
};
diff --git a/src/server/generations.ts b/src/server/generations.ts
index e39c6389..3803ded2 100644
--- a/src/server/generations.ts
+++ b/src/server/generations.ts
@@ -7,6 +7,7 @@ import { applyMentions } from "@/lib/catalog/elements";
import { withSignatureWords } from "@/lib/catalog/palettes";
import { applySketch, stripMotionPaths } from "@/lib/catalog/sketch";
import { cueText, type Cue } from "@/lib/cues";
+import { upscaleTier } from "@/lib/av/upscale";
import { estimateCost, planGeneration, routesFor } from "@/lib/catalog/plan";
import {
LAST_FRAME_CHAIN,
@@ -671,6 +672,16 @@ async function submit(
};
// What the caller said about the clip's length wins; the header fills the rest.
Object.assign(input, { ...source, ...(plan.params.sourceDuration !== undefined && { sourceDuration: plan.params.sourceDuration }) });
+ // An upscale that wouldn't enlarge the clip (a 1080p clip at a default 1080p; a 4K clip would even shrink):
+ // a tier the model only defaulted to moves up to the next one it offers, one the caller picked is refused.
+ if (plan.op === "upscale-video" && input.sourceSize) {
+ const tier = upscaleTier(input.resolution, plan.model.options.resolutions, input.sourceSize, req.params?.resolution !== undefined);
+ if ("error" in tier) throw new Error(tier.error);
+ if (tier.resolution !== input.resolution) {
+ input.resolution = tier.resolution;
+ if (providerId !== "mock" && plan.model.engine !== "open") update(id, { cost_usd: estimateCost(plan.model, { ...plan.params, resolution: tier.resolution }, 1, plan.op) });
+ }
+ }
const res = await adapter.submit({ generationId: id, model: plan.model, route, input });
const now = Date.now();
const status = statusOf(id);
diff --git a/src/server/providers/comfyui.ts b/src/server/providers/comfyui.ts
index 74a57a45..5230198b 100644
--- a/src/server/providers/comfyui.ts
+++ b/src/server/providers/comfyui.ts
@@ -522,7 +522,8 @@ function videoFinishValues(manifest: ManifestWorkflow, input: GenInput, clip: Me
values.shortSide = shortSide;
if (b.framesPerBatch && extra.framesPerBatch === undefined) {
const seedvr = /seedvr/i.test(manifest.id);
- values.framesPerBatch = framesPerPass(facts, { shortSide, modelScale: seedvr ? 0 : 4, fourNPlusOne: seedvr, max: seedvr ? 33 : 64, fallback: Number(d.framesPerBatch ?? 16) });
+ // ESRGAN on a big source (1440p → 2160p: about 0.85 GB a frame): down to one frame a pass, to stay near the budget.
+ values.framesPerBatch = framesPerPass(facts, { shortSide, modelScale: seedvr ? 0 : 4, fourNPlusOne: seedvr, min: seedvr ? 5 : 1, max: seedvr ? 33 : 64, fallback: Number(d.framesPerBatch ?? 16) });
}
} else if (b.framesPerBatch && manifest.capability === "export-video" && extra.framesPerBatch === undefined) {
values.framesPerBatch = framesPerPass(facts, { min: 8, max: 256, fallback: Number(d.framesPerBatch ?? 64) });