MMnode/bench/app/pipeline.py
Z User eefca88d35 feat: Moxie bench - standalone python/web harness for the fixed pipeline
- bench/ FastAPI server: fixed 9-stage pipeline parsed from the base
  workflow, serial render jobs, WS progress mirroring ComfyUI's push
  events, /api/view + ComfyUI-compatible /view, /upload/image,
  /easy-media/* aliases for the ported editor
- dual backend: self-contained mock renderer (numpy+ffmpeg, deterministic
  per prompt/seed, native + RTX-upscaled mp4 branches) and a ComfyUI
  bridge (substitutes the plan into base_workflow.json, converts to the
  /prompt API format, polls history, downloads outputs)
- timeline port: frontend/src/bench mounts the unmodified MultiTrack
  editor against a comfyAPI shim (fetchApi/toast/dialog/custom events);
  build.bench.ts emits bench/ui-dist served by the server
- packaging: PyInstaller onedir spec + Tauri2 sidecar docs
- tests: bench/tests contract suite + scripts/test_bench_pipeline.py
  e2e (API+WS+render); prebuilt bench UI committed
2026-09-28 01:42:58 +00:00

51 lines
1.5 KiB
Python

"""Fixed-pipeline executor: binds a PipelineSpec + RenderPlan to a backend."""
from __future__ import annotations
import shutil
from pathlib import Path
from typing import Callable
from .config import BenchConfig
from .tracks import RenderPlan
from .workflow import PipelineSpec
ProgressCb = Callable[[str, float, str, dict | None], None]
def run_pipeline(
spec: PipelineSpec,
plan: RenderPlan,
backend: str,
cfg: BenchConfig,
progress: ProgressCb,
job_dir: Path,
) -> dict:
"""Run all stages; returns {outputs: {...}, console: [...]}."""
job_dir.mkdir(parents=True, exist_ok=True)
if backend == "mock":
from .backends import mock
result = mock.render(plan, job_dir, progress)
elif backend == "comfy":
from .backends import comfy
result = comfy.render(spec, plan, cfg, job_dir, progress)
else:
raise RuntimeError(f"unknown backend {backend!r}")
# Move finished files into the job's outputs folder served by /api/view.
final: dict[str, dict] = {}
for key, out in result.outputs.items():
src = Path(out["path"])
dst = job_dir / src.name
if src.resolve() != dst.resolve():
shutil.move(str(src), str(dst))
out2 = dict(out)
out2["path"] = str(dst)
out2["filename"] = dst.name
out2["url"] = f"/api/view?filename={dst.name}&type=output&job={job_dir.name}"
final[key] = out2
return {"outputs": final, "console": result.console}