File size: 2,993 Bytes
6da4e64 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | """Prepare a scene-independent local WorldStereo experiment, preserving provenance."""
import argparse
import hashlib
import json
from pathlib import Path
import re
import shutil
ROOT = Path(__file__).resolve().parents[1]
def prepare(image, scene, output, reference_memory=False):
if not re.fullmatch(r"[a-z0-9][a-z0-9-]{0,63}", scene):
raise ValueError("Use a safe lowercase scene ID")
if image.suffix.lower() not in {".png", ".jpg", ".jpeg"}:
raise ValueError("Expected a decoded video frame")
with image.open("rb") as stream:
checksum = hashlib.file_digest(stream, "sha256").hexdigest()
name = f"kw-{scene}-{checksum[:16]}{image.suffix.lower()}"
target = ROOT.parent / "tools/ComfyUI/input" / name
if target.exists():
with target.open("rb") as stream:
if hashlib.file_digest(stream, "sha256").hexdigest() != checksum:
raise ValueError("Staged input checksum collision")
output.mkdir(parents=True, exist_ok=False)
if not target.exists():
shutil.copy2(image, target)
workflow = json.loads((ROOT / "runtime/worldstereo-orbit-api.json").read_text())
workflow["1"]["inputs"]["image"] = name
settings = workflow["4"]["inputs"]
settings["prompt"] = (
"A photorealistic multi-view continuation of the provided scene. Preserve visible "
"objects, materials, illumination, proportions and spatial layout across views. "
"Reveal plausible occluded surfaces consistent with the visible scene."
)
settings["negative_prompt"] = "duplicate objects, warped geometry, melting, object drift, text, black void, surreal, illustration"
settings["seed"] = 20260905
settings["enable_reference_memory"] = reference_memory
# Keep uncropped output so edge failures remain visible during evaluation.
settings["crop_generated_edges"] = False
workflow["5"]["inputs"]["filename_prefix"] = f"kineworld/{scene}/generated"
workflow["6"]["inputs"]["filename_prefix"] = f"kineworld/{scene}/cameras"
(output / "workflow.json").write_text(json.dumps(workflow, indent=2), encoding="utf-8")
(output / "input.json").write_text(json.dumps({
"scene": scene, "input_sha256": checksum, "source": str(image.resolve()),
"staged_name": name, "semantic_prompt": "scene-independent",
"provenance": "Generated views are hypotheses, not observed evidence",
"scope": "Local single-anchor completion experiment; not a completed 3D world",
"edge_cropping": False, "reference_memory_requested": reference_memory}, indent=2), encoding="utf-8")
if __name__ == "__main__":
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("image", type=Path)
parser.add_argument("scene")
parser.add_argument("output", type=Path)
parser.add_argument("--reference-memory", action="store_true")
args = parser.parse_args()
prepare(args.image, args.scene, args.output, args.reference_memory)
|