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.

Image to 3D and Elements: a run making the other sides is picked up again when its button comes back

Claude18816166e31f
diff --git a/src/components/model3d/other-sides.tsx b/src/components/model3d/other-sides.tsx
index a3185c70..74cbc96e 100644
--- a/src/components/model3d/other-sides.tsx
+++ b/src/components/model3d/other-sides.tsx
@@ -5,7 +5,7 @@ import { useEffect, useRef, useState } from "react";
import { Button } from "@/components/ui/button";
import { useCreateGeneration, useEngine, useGenerations, useIsVisitor, useModelAccess } from "@/lib/api";
import { IDOL_MODELS } from "@/lib/av/model3d";
-import { IDOL_VIEWS_FEATURE, IDOL_VIEWS_NOTE, idolViewsOf, idolViewsRequest } from "@/lib/av/idol-views";
+import { forgetViewRun, IDOL_VIEWS_FEATURE, IDOL_VIEWS_NOTE, idolViewsOf, idolViewsRequest, rememberViewRun, viewRunFor } from "@/lib/av/idol-views";
import type { ViewSide } from "@/lib/av/model3d";
import { offered } from "@/lib/model-access";
import { toastError } from "@/lib/refusals";
@@ -47,7 +47,10 @@ export function OtherSides({
className?: string;
}) {
const create = useCreateGeneration();
- const [runId, setRunId] = useState<string | null>(null);
+ // The run for this picture lives for the tab (viewRunFor), so it's picked up again if the button comes back mid-run,
+ // and a different front never gets another picture's views.
+ const [, setTick] = useState(0);
+ const runId = viewRunFor(photo) ?? null;
const list = useGenerations({ features: [IDOL_VIEWS_FEATURE], limit: 20 });
const run = runId ? list.data?.find((g) => g.id === runId) : undefined;
const preview = useRunPreview(idolViewsRequest(photo, { asPhoto }));
@@ -62,15 +65,19 @@ export function OtherSides({
if (!run || run.status !== "succeeded" || handed.current === run.id) return;
handed.current = run.id;
made.current(idolViewsOf(run.outputs));
- setRunId(null);
- }, [run]);
+ forgetViewRun(photo, run.id);
+ setTick((t) => t + 1);
+ }, [run, photo]);
const failed = run && (run.status === "failed" || run.status === "canceled") ? run : undefined;
const working = create.isPending || (!!runId && !failed);
useEffect(() => onBusy?.(working), [onBusy, working]);
useEffect(() => () => onBusy?.(false), [onBusy]);
const start = () =>
create.mutate(idolViewsRequest(photo, { asPhoto }), {
- onSuccess: (items) => setRunId(items[0]?.id ?? null),
+ onSuccess: (items) => {
+ if (items[0]?.id) rememberViewRun(photo, items[0].id);
+ setTick((t) => t + 1);
+ },
onError: (e) => toastError(e),
});
return (
diff --git a/src/lib/av/idol-views.ts b/src/lib/av/idol-views.ts
index eccb1420..ee8ea422 100644
--- a/src/lib/av/idol-views.ts
+++ b/src/lib/av/idol-views.ts
@@ -103,3 +103,25 @@ export function fillOtherSides<T>(current: Partial<Record<ViewSide, T | null>>,
export function elementViews(made: Partial<Record<ViewSide, string>>, have: string[] = []): string[] {
return OTHER_SIDES.flatMap((s) => (made[s] && !have.includes(made[s]!) ? [made[s]!] : []));
}
+
+/**
+ * The view run started for each front picture, kept for the tab rather than in the button: the button goes away when the
+ * person switches mode or closes the dialog, and coming back to the same picture picks the run up again instead of
+ * starting (and paying for) a second one. A run belongs to its picture, so a new front never gets the old front's views.
+ */
+const viewRuns = new Map<string, string>();
+
+/** The run making views of this picture, if one was started in this tab and not handed over yet. */
+export function viewRunFor(photo: string): string | undefined {
+ return viewRuns.get(photo);
+}
+
+/** Remembers the run making views of this picture. */
+export function rememberViewRun(photo: string, runId: string): void {
+ viewRuns.set(photo, runId);
+}
+
+/** Forgets the picture's run once its views were handed over (only if it's still that run). */
+export function forgetViewRun(photo: string, runId: string): void {
+ if (viewRuns.get(photo) === runId) viewRuns.delete(photo);
+}
diff --git a/tests/idol-views.test.ts b/tests/idol-views.test.ts
index 51a82bdd..f6203484 100644
--- a/tests/idol-views.test.ts
+++ b/tests/idol-views.test.ts
@@ -257,6 +257,19 @@ describe("the request, the slots and the chain into TRELLIS.2 multi-view", () =>
expect(own.params?.extra).toEqual({ views: ["front", "back"] });
});
+ it("a view run belongs to its front picture for the tab, so the button picks it up again and a new front never gets it", () => {
+ expect(views.viewRunFor("/api/files/front-a.png")).toBeUndefined();
+ views.rememberViewRun("/api/files/front-a.png", "run-1");
+ expect(views.viewRunFor("/api/files/front-a.png")).toBe("run-1");
+ expect(views.viewRunFor("/api/files/front-b.png")).toBeUndefined();
+ // A newer run for the same picture replaces it; an older run's handover doesn't forget the newer one.
+ views.rememberViewRun("/api/files/front-a.png", "run-2");
+ views.forgetViewRun("/api/files/front-a.png", "run-1");
+ expect(views.viewRunFor("/api/files/front-a.png")).toBe("run-2");
+ views.forgetViewRun("/api/files/front-a.png", "run-2");
+ expect(views.viewRunFor("/api/files/front-a.png")).toBeUndefined();
+ });
+
it("an element gets the left, back and right views it hasn't got yet", () => {
const made = { front: "v0", left: "v1", back: "v2", right: "v3" };
expect(views.elementViews(made)).toEqual(["v1", "v2", "v3"]);