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.

Translate & dub: an account with a key and no GPU dubs in one shot

Adarshd38e555fc225
diff --git a/src/components/dub/dub-studio.tsx b/src/components/dub/dub-studio.tsx
index a3100d2e..4c6b176d 100644
--- a/src/components/dub/dub-studio.tsx
+++ b/src/components/dub/dub-studio.tsx
@@ -16,7 +16,7 @@ import { SourceLanguageSelect, TargetLanguages } from "@/components/av/language-
import { MediaDrop } from "@/components/av/media-drop";
import { StepList, type StepRow } from "@/components/av/step-list";
import { Panel, ToolHero, ToolShell } from "@/components/av/tool-shell";
-import { useEngine, useIsOwner, useModelAccess } from "@/lib/api";
+import { CONNECT_GPU_EVENT, useEngine, useIsOwner, useModelAccess, useStatus, type ConnectGpuDetail } from "@/lib/api";
import { isPlaceholder } from "@/lib/demo-mode";
import { keepOffered, offered } from "@/lib/model-access";
import { cueProblems } from "@/lib/av/cue-edit";
@@ -31,6 +31,7 @@ import {
ONE_SHOT_MODELS,
priceLine,
reviewCues,
+ stepsNeedGpu,
takeLines,
translateKey,
VOICE_SPLIT_IDS,
@@ -120,13 +121,17 @@ export function DubStudio() {
}
function NewDub({ onStarted }: { onStarted: (id: string) => void }) {
- const [engine, , engineMode] = useEngine();
+ const [engine, setEngine, engineMode] = useEngine();
// The note about DBS on your GPU is for the studio's own install with both engines.
const owner = useIsOwner();
const { create } = useDubActions();
const [video, setVideo] = useState<SlotValue | null>(null);
const [duration, setDuration] = useState<number | undefined>(undefined);
- const [mode, setMode] = useState<"steps" | "oneshot">("steps");
+ // An account with its key and no GPU starts on One shot: the review's translation runs on its GPU (stepsNeedGpu).
+ const keyOnly = stepsNeedGpu(useStatus().data?.viewer);
+ const cloudOffered = engineMode !== "open";
+ const [pickedMode, setMode] = useState<"steps" | "oneshot" | null>(null);
+ const mode = pickedMode ?? (keyOnly && cloudOffered ? "oneshot" : "steps");
const [picked, setModel] = useState<OneShotModel>("heygen-translate");
// One-shot dubbing models switched off in Settings → Models & licences leave the menu; the pick falls back to one that is on.
const access = useModelAccess();
@@ -145,9 +150,16 @@ function NewDub({ onStarted }: { onStarted: (id: string) => void }) {
const l = languageByCode(c);
return l && supportsTarget(route, l);
});
+ // "Review the script first" for that account: One shot on its key, or its GPU connected, instead of a Translate that can't run.
+ const needsGpu = keyOnly && !oneShot;
+ const pickOneShot = () => {
+ if (engine === "open") setEngine("cloud");
+ setMode("oneshot");
+ };
+ const connectGpu = () => window.dispatchEvent(new CustomEvent<ConnectGpuDetail>(CONNECT_GPU_EVENT, { detail: { gpuOnly: true, needs: "gpu" } }));
const blocker = !video ? "Add the video to translate" : video.uploading ? "Uploading…" : !usable.length ? "Pick a language to dub into" : null;
const body =
- video && !video.uploading && usable.length
+ video && !video.uploading && usable.length && !needsGpu
? { engine, mode: oneShot ? ("oneshot" as const) : ("steps" as const), model: oneShot ? model : undefined, video: video.ref, source, targets: usable, duration, ...(engine === "open" && { voiceSplit: split }) }
: null;
const price = useDubPrice(body);
@@ -187,7 +199,19 @@ function NewDub({ onStarted }: { onStarted: (id: string) => void }) {
</div>
<Panel title="How">
<div role="radiogroup" aria-label="How to dub" className="grid gap-2 sm:grid-cols-2">
- <ModeCard on={!oneShot} icon={<Languages className="size-4" />} title="Review the script first" onClick={() => setMode("steps")} note={engineMode === "open" ? "Transcribe and translate, edit every line, then voice it." : "Transcribe and translate, edit every line, then voice it. Cloud and open source."} />
+ <ModeCard
+ on={!oneShot}
+ icon={<Languages className="size-4" />}
+ title="Review the script first"
+ onClick={() => setMode("steps")}
+ note={
+ keyOnly
+ ? "Transcribe and translate, edit every line, then voice it. The translation runs on your GPU."
+ : engineMode === "open"
+ ? "Transcribe and translate, edit every line, then voice it."
+ : "Transcribe and translate, edit every line, then voice it. Cloud and open source."
+ }
+ />
{/* One shot is cloud only: an open-source-only studio doesn't offer it (nobody here can switch the engine). */}
{engineMode !== "open" && (
<ModeCard
@@ -280,18 +304,38 @@ function NewDub({ onStarted }: { onStarted: (id: string) => void }) {
</div>
</div>
</Panel>
- <div className="flex flex-col gap-3 pt-1 sm:flex-row sm:items-center">
- <p className="flex-1 text-[12px] leading-relaxed text-muted-foreground">
- {oneShot ? `${ONE_SHOT[model].name} returns the finished video for each language.` : engine === "open" ? ROUTE_LINE.open(split) : ROUTE_LINE.cloud(owner)}
- </p>
- <div className="flex shrink-0 items-center gap-3 self-end sm:self-auto">
- <PriceNote price={price.data} loading={price.isFetching && !price.data} error={price.error as Error | null} hint={oneShot ? undefined : "Translating costs little; you'll see the voice's price before it speaks"} />
- <Button size="lg" className={cn("shrink-0 rounded-full", blocker && "bg-muted text-muted-foreground hover:bg-muted")} onClick={start} disabled={create.isPending} aria-describedby={blocker ? "dub-blocker" : undefined}>
- {create.isPending ? <Loader2 className="size-4 animate-spin" /> : <Sparkles className="size-4" />}
- {oneShot ? "Dub it" : "Translate"}
- </Button>
+ {needsGpu ? (
+ <div className="flex flex-col gap-3 pt-1 sm:flex-row sm:items-center">
+ <p className="flex-1 text-[12px] leading-relaxed text-muted-foreground">
+ {cloudOffered ? "Reviewing the script translates every line on your GPU. On your key, One shot dubs the whole video in one go." : "Reviewing the script translates every line on your GPU."}
+ </p>
+ <div className="flex shrink-0 flex-wrap items-center justify-end gap-2 self-end sm:self-auto">
+ <Button size="lg" variant={cloudOffered ? "outline" : "default"} className="shrink-0 rounded-full" onClick={connectGpu}>
+ <Cpu className="size-4" />
+ Connect your GPU
+ </Button>
+ {cloudOffered && (
+ <Button size="lg" className="shrink-0 rounded-full" onClick={pickOneShot}>
+ <Wand2 className="size-4" />
+ Use One shot
+ </Button>
+ )}
+ </div>
</div>
- </div>
+ ) : (
+ <div className="flex flex-col gap-3 pt-1 sm:flex-row sm:items-center">
+ <p className="flex-1 text-[12px] leading-relaxed text-muted-foreground">
+ {oneShot ? `${ONE_SHOT[model].name} returns the finished video for each language.` : engine === "open" ? ROUTE_LINE.open(split) : ROUTE_LINE.cloud(owner)}
+ </p>
+ <div className="flex shrink-0 items-center gap-3 self-end sm:self-auto">
+ <PriceNote price={price.data} loading={price.isFetching && !price.data} error={price.error as Error | null} hint={oneShot ? undefined : "Translating costs little; you'll see the voice's price before it speaks"} />
+ <Button size="lg" className={cn("shrink-0 rounded-full", blocker && "bg-muted text-muted-foreground hover:bg-muted")} onClick={start} disabled={create.isPending} aria-describedby={blocker ? "dub-blocker" : undefined}>
+ {create.isPending ? <Loader2 className="size-4 animate-spin" /> : <Sparkles className="size-4" />}
+ {oneShot ? "Dub it" : "Translate"}
+ </Button>
+ </div>
+ </div>
+ )}
{blocker && (
<p id="dub-blocker" className="sr-only">
{blocker}
diff --git a/src/lib/av/dub.ts b/src/lib/av/dub.ts
index 6e9ac473..c6bc7567 100644
--- a/src/lib/av/dub.ts
+++ b/src/lib/av/dub.ts
@@ -178,6 +178,23 @@ export function gpuTranslateTokens(seconds?: number): number {
return Math.min(16_384, Math.max(2048, Math.ceil(seconds * 10)));
}
+/** Who is looking, as the studio's status says it (useStatus().data?.viewer): its own GPU and keys. */
+export interface DubViewer {
+ kind: "guest" | "account";
+ gpu?: { connected: boolean };
+ keys?: readonly string[];
+}
+
+/**
+ * Whether "Review the script first" waits for the viewer's own GPU: a signed-in account's translations run there
+ * (GPU_TRANSLATE_MODEL; no fal.ai or Replicate model translates text), so an account with a key and no GPU dubs in one
+ * shot on its key instead, or connects its GPU for the review. False for the owner, a guest (asked to sign up first) and
+ * an account with neither (asked to connect before its video is added).
+ */
+export function stepsNeedGpu(viewer: DubViewer | undefined): boolean {
+ return viewer?.kind === "account" && !viewer.gpu?.connected && !!viewer.keys?.length;
+}
+
/** Step 1 (both engines): the voice to clone, the timed transcript and one translation per target language. */
export function prepareSteps(o: PrepareInput): DubStep[] {
const targets = targetsFor(o.engine === "open" ? "open" : "cloud-steps", o.targets);
diff --git a/tests/av-dub.test.ts b/tests/av-dub.test.ts
index d1475bb2..244fd8cf 100644
--- a/tests/av-dub.test.ts
+++ b/tests/av-dub.test.ts
@@ -22,6 +22,7 @@ import {
priceLine,
reviewCues,
spokenText,
+ stepsNeedGpu,
takeLines,
VOICE_SPLITS,
voiceOnly,
@@ -31,7 +32,7 @@ import {
} from "@/lib/av/dub";
import { timelineFor, timelineTracks } from "@/lib/av/timeline";
import { DUB_LANGUAGES, supportsTarget } from "@/lib/av/languages";
-import { getModel } from "@/lib/catalog";
+import { getModel, MODELS } from "@/lib/catalog";
import { buildPayload } from "@/lib/catalog/payload";
import { tempDir } from "./helpers/temp-dir";
@@ -122,6 +123,23 @@ describe("dub pipeline DAGs", () => {
]);
});
+ it("an account's cloud review: only the translations need its GPU, so an account with a key and no GPU is offered One shot", () => {
+ const steps = prepareSteps({ engine: "cloud", video, targets: ["fr", "de"], translator: "gpu", seconds: 30 });
+ const providers = (id: string) => new Set(getModel(id)?.routes.map((r) => r.provider));
+ const onGpu = steps.filter((s) => providers(s.request.modelId).has("comfyui")).map((s) => s.key);
+ expect(onGpu).toEqual(["translate:fr", "translate:de"]);
+ expect(steps.filter((s) => !onGpu.includes(s.key)).every((s) => providers(s.request.modelId).has("fal"))).toBe(true);
+ // No fal.ai or Replicate model translates text, so the review can't move to the key.
+ expect(MODELS.some((m) => m.routes.some((r) => r.op === "translate" && (r.provider === "fal" || r.provider === "replicate")))).toBe(false);
+ // Who waits for a GPU: an account with a key and no GPU; never the owner, a guest, an account with its GPU, or one with neither.
+ expect(stepsNeedGpu({ kind: "account", gpu: { connected: false }, keys: ["fal"] })).toBe(true);
+ expect(stepsNeedGpu({ kind: "account", gpu: { connected: false }, keys: ["replicate"] })).toBe(true);
+ expect(stepsNeedGpu({ kind: "account", gpu: { connected: true }, keys: ["fal"] })).toBe(false);
+ expect(stepsNeedGpu({ kind: "account", gpu: { connected: false }, keys: [] })).toBe(false);
+ expect(stepsNeedGpu({ kind: "guest", gpu: { connected: false } })).toBe(false);
+ expect(stepsNeedGpu(undefined)).toBe(false);
+ });
+
it("open: the Voice split picks the first step's model (MelBand RoFormer by default, or DBS); nothing after it changes", () => {
const keys = (steps: ReturnType<typeof prepareSteps>) => steps.map((s) => [s.key, s.request.modelId, s.request.op, s.after ?? null]);
const melband = prepareSteps({ engine: "open", video, source: "en", targets: ["es"] });