diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 183cd045b35979e17e40725743937b43006153e5..0000000000000000000000000000000000000000 --- a/.gitignore +++ /dev/null @@ -1,81 +0,0 @@ -.env -.env.* -!.env.example -*.token -*.secret -secrets/ -weights/ -models/ -checkpoints/ -*.safetensors -*.ckpt -*.pt -*.pth -*.onnx -*.gguf -*.zip -*.7z -*.tar -*.tar.gz -*.mp4 -*.mov -*.wav -*.flac -*.png -*.jpg -*.jpeg -*.webp -*.log - -.venv/ -node_modules/ -.shots/ -VideosExamples/ -*.pdf -__pycache__/ -*.py[cod] -.pytest_cache/ -.mypy_cache/ -.ruff_cache/ -.coverage -htmlcov/ - -benchmarks/results/* -!benchmarks/results/.gitkeep -!benchmarks/results/*.json -!benchmarks/results/*.md - -assets/showcase/* -!assets/showcase/.gitkeep -assets/anchors/generated/* -frontend/.cache/ - -# Showcase reel assets ARE part of the product: pre-rendered by the app's own -# endpoints (scripts/build_*.py), bundled so anon-quota visitors see the full -# experience instantly. Un-ignore them despite the blanket *.webp/*.png. -!frontend/assets/showcase/ -!frontend/assets/showcase/*.webp -!frontend/assets/showcase/*.png -!frontend/assets/showcase/manifest.json -!frontend/assets/corridor/ -!frontend/assets/corridor/*.webp -!frontend/assets/corridor/*.png -!frontend/assets/corridor/manifest.json -!frontend/assets/scroll/ -!frontend/assets/scroll/*.webp -!frontend/assets/scroll/*.png -!frontend/assets/scroll/manifest.json -!frontend/assets/scroll/variants.json -!frontend/assets/scroll/v_*/ -!frontend/assets/scroll/v_*/*.webp -!frontend/assets/scroll/v_*/*.png -!frontend/assets/scroll/v_*/manifest.json - -vonfig.py -lightloom-docs/ - -# Modal LoRA scratch (the harness training/modal_lora/launch.py IS committed; these -# are local run artifacts: downloaded dataset samples, the fetched ref script, logs). -.modal_dataset_sample/ -.train_script_ref.py -.modal_*.log diff --git a/app.py b/app.py index 032f82ac5c1239cffee7ef07498301a4e76ba1d1..d6b57542c5710f448a781c50a20f54070faa2fee 100644 --- a/app.py +++ b/app.py @@ -891,7 +891,7 @@ def _scroll_world(text: str, session: str): "stage": "section", "index": g, "image": f"/frames-scroll/{session}/section-{g}.webp", - "caption": phrase[:160] if k == 0 else "", + "caption": phrase[:160], # every strip carries the caption (onFocus pins it; no flicker) "w": sec.width, } dmap = estimate_depth(depth_pipe, sec) @@ -1049,7 +1049,10 @@ def _depth_global_norm(raw: Any, state: dict[str, Any], out_dir: Path) -> Any: state["depth_lo"], state["depth_hi"] = lo, hi _live_save_state(out_dir, depth_lo=lo, depth_hi=hi) norm = np.clip((raw - lo) / (hi - lo), 0.0, 1.0) - return 1.0 - norm # 1 = near, 0 = far + # raw is DA-V2 DISPARITY (near=HIGH) -> norm already has 1=near/0=far (the renderer convention). + # The old `1.0 - norm` flipped it inside-out (near read as far) -> inverted parallax + aerial on + # the wrong regions + disocclusion streaks. Return norm as-is. + return norm # 1 = near, 0 = far def _scroll_transition_prompt(prev_subject: str, subject: str) -> str: @@ -1208,7 +1211,10 @@ def _scroll_live_phrase(session: str, text: str, audio_b64: str, lang: str): "stage": "section", "index": g, "image": f"/frames-scroll/{session}/section-{g}.webp", - "caption": phrase[:160] if k == 0 else "", + # stamp EVERY strip of the phrase (not just k==0): the caption is shown by onFocus when + # the strip is under the view centre, so a blank on the 2nd strip made the words flicker + # off mid-clause. Same phrase across both strips -> the caption stays pinned. + "caption": phrase[:160], "w": sec.width, } raw_d = estimate_depth(depth_pipe, sec, normalize=False) # RAW disparity (un-scaled) diff --git a/benchmarks/results/g1.json b/benchmarks/results/g1.json new file mode 100644 index 0000000000000000000000000000000000000000..aaaf7202016a09227a1e042f4380be69e6b1fce4 --- /dev/null +++ b/benchmarks/results/g1.json @@ -0,0 +1,153 @@ +{ + "authoritative": true, + "decision": { + "reason": "fp8 unavailable; selected fastest successful dtype", + "resolution": [ + 1024, + 576 + ], + "selected": { + "aot": false, + "authoritative": true, + "compile_mode": "off", + "dtype": "bf16", + "height": 576, + "p50_ms": 646.434, + "p95_ms": 652.067, + "status": "ok", + "timings_ms": [ + 635.961, + 639.458, + 649.857, + 652.067, + 646.434 + ], + "width": 1024 + }, + "status": "pass" + }, + "gate": "G1", + "generated_at": "2026-06-11T20:18:00Z", + "hardware_profile": { + "arch_list": [ + "sm_75", + "sm_80", + "sm_86", + "sm_90", + "sm_100", + "sm_120" + ], + "cuda": "13.0", + "cuda_available": true, + "device": "NVIDIA RTX PRO 6000 Blackwell Server Edition MIG 2g.48gb", + "lightloom_profile": "space", + "platform": "Linux-6.12.80-106.156.amzn2023.x86_64-x86_64-with-glibc2.36", + "space_id": "Efradeca/lightloom-dev", + "torch": "2.11.0+cu130" + }, + "prompt": "cinematic illustrated film still, an old lighthouse at the edge of the world, stormy dusk, warm lantern glow, painterly texture, volumetric light, 2.39:1 frame", + "reps": 5, + "results": [ + { + "aot": false, + "authoritative": true, + "dtype": "fp8", + "error": "load failed: TypeError: couldn't find storage object Float8_e4m3fnStorage", + "height": 432, + "status": "failed", + "width": 768 + }, + { + "aot": true, + "authoritative": true, + "dtype": "fp8", + "error": "load failed: TypeError: couldn't find storage object Float8_e4m3fnStorage", + "height": 432, + "status": "failed", + "width": 768 + }, + { + "aot": false, + "authoritative": true, + "dtype": "fp8", + "error": "load failed: TypeError: couldn't find storage object Float8_e4m3fnStorage", + "height": 576, + "status": "failed", + "width": 1024 + }, + { + "aot": true, + "authoritative": true, + "dtype": "fp8", + "error": "load failed: TypeError: couldn't find storage object Float8_e4m3fnStorage", + "height": 576, + "status": "failed", + "width": 1024 + }, + { + "aot": false, + "authoritative": true, + "compile_mode": "off", + "dtype": "bf16", + "height": 432, + "p50_ms": 546.845, + "p95_ms": 548.098, + "status": "ok", + "timings_ms": [ + 548.098, + 543.092, + 545.796, + 546.845, + 547.591 + ], + "width": 768 + }, + { + "aot": true, + "authoritative": true, + "compile_mode": "torch.compile(reduce-overhead)", + "dtype": "bf16", + "height": 432, + "p50_ms": 463.283, + "p95_ms": 467.914, + "status": "ok", + "timings_ms": [ + 463.283, + 465.276, + 467.914, + 462.731, + 462.571 + ], + "width": 768 + }, + { + "aot": false, + "authoritative": true, + "compile_mode": "off", + "dtype": "bf16", + "height": 576, + "p50_ms": 646.434, + "p95_ms": 652.067, + "status": "ok", + "timings_ms": [ + 635.961, + 639.458, + 649.857, + 652.067, + 646.434 + ], + "width": 1024 + }, + { + "aot": true, + "authoritative": true, + "compile_mode": "torch.compile(reduce-overhead)", + "dtype": "bf16", + "error": "AttributeError: 'function' object has no attribute 'config'", + "height": 576, + "status": "failed", + "width": 1024 + } + ], + "schema_version": 1 +} diff --git a/benchmarks/results/g1.md b/benchmarks/results/g1.md new file mode 100644 index 0000000000000000000000000000000000000000..dfd9a020f35e3eb2a8c4d8311973968bb386abb6 --- /dev/null +++ b/benchmarks/results/g1.md @@ -0,0 +1,17 @@ +# Gate G1 Results + +Authoritative: `True` +Hardware profile: `space` + +| Resolution | dtype | AoT | status | p50 ms | p95 ms | +|---|---|---:|---|---:|---:| +| 768x432 | fp8 | no | failed | | | +| 768x432 | fp8 | yes | failed | | | +| 1024x576 | fp8 | no | failed | | | +| 1024x576 | fp8 | yes | failed | | | +| 768x432 | bf16 | no | ok | 546.845 | 548.098 | +| 768x432 | bf16 | yes | ok | 463.283 | 467.914 | +| 1024x576 | bf16 | no | ok | 646.434 | 652.067 | +| 1024x576 | bf16 | yes | failed | | | + +Decision: `pass` diff --git a/frontend/assets/scroll/section-0-depth.png b/frontend/assets/scroll/section-0-depth.png index de843370957ce985def533b457e5e1ebe0c46092..14270abba07283b1fb10d800e178d436620b2942 100644 Binary files a/frontend/assets/scroll/section-0-depth.png and b/frontend/assets/scroll/section-0-depth.png differ diff --git a/frontend/assets/scroll/section-1-depth.png b/frontend/assets/scroll/section-1-depth.png index 3c89c257e94735e71388ad69b4c5b8fb762ee8d3..409c050be56511ffe674985daa920ccda34c4378 100644 Binary files a/frontend/assets/scroll/section-1-depth.png and b/frontend/assets/scroll/section-1-depth.png differ diff --git a/frontend/assets/scroll/section-2-depth.png b/frontend/assets/scroll/section-2-depth.png index 3fc15189c4080714e25d40a09adacd864cb575b9..b9fb7d22a19fadc005af024b6cebdd9a63d626e2 100644 Binary files a/frontend/assets/scroll/section-2-depth.png and b/frontend/assets/scroll/section-2-depth.png differ diff --git a/frontend/assets/scroll/section-3-depth.png b/frontend/assets/scroll/section-3-depth.png index b20451bef1cb2458bd3b4c89f37a2c2c7d9f4259..f92f48ea36ddf4c663613352f91e948d3aa91568 100644 Binary files a/frontend/assets/scroll/section-3-depth.png and b/frontend/assets/scroll/section-3-depth.png differ diff --git a/frontend/assets/scroll/section-4-depth.png b/frontend/assets/scroll/section-4-depth.png index 5dd9ded600ff8d23cfaa277400c845964259730d..05b7092c69893cba297cf234e1ac61b703f2f5d0 100644 Binary files a/frontend/assets/scroll/section-4-depth.png and b/frontend/assets/scroll/section-4-depth.png differ diff --git a/frontend/assets/scroll/section-5-depth.png b/frontend/assets/scroll/section-5-depth.png index 690e10fe8aa061bebc3500c31154106d0a5d0afd..f16a442c88fbf39068e20b97c25b6a6475627b8b 100644 Binary files a/frontend/assets/scroll/section-5-depth.png and b/frontend/assets/scroll/section-5-depth.png differ diff --git a/frontend/js/controller.js b/frontend/js/controller.js index f8940c57cfd403c7f7f798657e0f4858916403de..7cd13349a313361887cbcb2c6953aa8dd70463bb 100644 --- a/frontend/js/controller.js +++ b/frontend/js/controller.js @@ -269,7 +269,12 @@ const controller = { switch (ev.stage) { case "transcript": // the words you just spoke, becoming the world this._orch("director", true); - this._transcript(ev.text); + // Do NOT write the caption here. The spoken words are buffered ~768px ahead but the strip + // scrolls ~110px/s, so a phrase's IMAGE reaches the view centre seconds AFTER it is spoken. + // Writing the transcript immediately clobbered the onFocus caption and showed words that did + // not match the on-screen scene ("the image has nothing to do with what I said"). The caption + // now comes solely from onFocus (controller.js:45) — the section actually under the centre — + // so caption and image always describe the SAME clause and the words move WITH the scene. this._status(t(COPY.building, this.lang), 0); break; case "silent": // a segment with nothing intelligible — keep listening diff --git a/package-lock.json b/package-lock.json deleted file mode 100644 index 9510620107e57c2d899018274ccff8ad6e78735b..0000000000000000000000000000000000000000 --- a/package-lock.json +++ /dev/null @@ -1,56 +0,0 @@ -{ - "name": "Lightloom", - "lockfileVersion": 3, - "requires": true, - "packages": { - "": { - "dependencies": { - "playwright": "^1.60.0" - } - }, - "node_modules/fsevents": { - "version": "2.3.2", - "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", - "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", - "hasInstallScript": true, - "license": "MIT", - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": "^8.16.0 || ^10.6.0 || >=11.0.0" - } - }, - "node_modules/playwright": { - "version": "1.60.0", - "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.60.0.tgz", - "integrity": "sha512-hheHdokM8cdqCb0lcE3s+zT4t4W+vvjpGxsZlDnikarzx8tSzMebh3UiFtgqwFwnTnjYQcsyMF8ei2mCO/tpeA==", - "license": "Apache-2.0", - "dependencies": { - "playwright-core": "1.60.0" - }, - "bin": { - "playwright": "cli.js" - }, - "engines": { - "node": ">=18" - }, - "optionalDependencies": { - "fsevents": "2.3.2" - } - }, - "node_modules/playwright-core": { - "version": "1.60.0", - "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.60.0.tgz", - "integrity": "sha512-9bW6zvX/m0lEbgTKJ6YppOKx8H3VOPBMOCFh2irXFOT4BbHgrx5hPjwJYLT40Lu+4qtD36qKc/Hn56StUW57IA==", - "license": "Apache-2.0", - "bin": { - "playwright-core": "cli.js" - }, - "engines": { - "node": ">=18" - } - } - } -} diff --git a/package.json b/package.json deleted file mode 100644 index f2eab146a88c37bd2a5b194a12c66df166df261d..0000000000000000000000000000000000000000 --- a/package.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "dependencies": { - "playwright": "^1.60.0" - } -} diff --git a/pyproject.toml b/pyproject.toml deleted file mode 100644 index e13d0ff9ac25445045b0a7a4f58a0dbf0292402c..0000000000000000000000000000000000000000 --- a/pyproject.toml +++ /dev/null @@ -1,21 +0,0 @@ -[build-system] -requires = ["setuptools>=69", "wheel"] -build-backend = "setuptools.build_meta" - -[project] -name = "lightloom" -version = "0.1.0" -description = "Voice-driven live-cinema Gradio app for the Build Small hackathon." -requires-python = ">=3.10" -readme = "README.md" - -[tool.setuptools.packages.find] -where = ["src"] - -[tool.pytest.ini_options] -pythonpath = ["src"] -testpaths = ["tests"] - -[tool.ruff] -line-length = 100 -target-version = "py310" diff --git a/scripts/_debug_asr.py b/scripts/_debug_asr.py deleted file mode 100644 index af5088146572f5591dd4a0eb882e0208aa0bd35b..0000000000000000000000000000000000000000 --- a/scripts/_debug_asr.py +++ /dev/null @@ -1,44 +0,0 @@ -"""Local definitive debug of Cohere Transcribe: does it load all weights, and does -it transcribe the demo clip correctly on CPU? Prints missing/unexpected keys.""" -import os, sys -sys.path.insert(0, "src") -os.environ.setdefault("HF_TOKEN", "") -import torch -from huggingface_hub import hf_hub_download -from transformers import AutoProcessor, AutoModelForSpeechSeq2Seq -from lightloom.audio_in.asr import _patch_keys_to_ignore_coercion - -REPO = "CohereLabs/cohere-transcribe-03-2026" -TOK = os.environ["HF_TOKEN"] -_patch_keys_to_ignore_coercion() -print("loading processor…", flush=True) -proc = AutoProcessor.from_pretrained(REPO, trust_remote_code=True, token=TOK) -print("loading model (fp32, cpu)…", flush=True) -model, info = AutoModelForSpeechSeq2Seq.from_pretrained( - REPO, trust_remote_code=True, token=TOK, output_loading_info=True -) -mk = list(info.get("missing_keys", [])) -uk = list(info.get("unexpected_keys", [])) -print(f"MISSING_KEYS: {len(mk)} (first 10: {mk[:10]})", flush=True) -print(f"UNEXPECTED_KEYS: {len(uk)} (first 10: {uk[:10]})", flush=True) -model.eval() - -wav = hf_hub_download(REPO, "demo/voxpopuli_test_en_demo.wav", token=TOK) -try: - from transformers.audio_utils import load_audio - audio = load_audio(wav, sampling_rate=16000) - print("loaded audio via transformers.audio_utils.load_audio", flush=True) -except Exception as e: - from lightloom.audio_in.asr import read_wav - audio, _sr = read_wav(wav) - print("loaded audio via read_wav:", repr(e)[:80], flush=True) - -inputs = proc(audio, sampling_rate=16000, return_tensors="pt", language="en") -print("processor output keys:", list(inputs.keys()), flush=True) -aci = inputs.get("audio_chunk_index") -with torch.inference_mode(): - out = model.generate(**inputs, max_new_tokens=120) -txt = proc.decode(out, skip_special_tokens=True, audio_chunk_index=aci, language="en") -if isinstance(txt, list): - txt = txt[0] if txt else "" -sys.stdout.buffer.write(("LOCAL_TRANSCRIPT: " + txt[:300] + "\n").encode("utf-8", "replace")) diff --git a/scripts/asr-feasibility.cjs b/scripts/asr-feasibility.cjs deleted file mode 100644 index 631170f5e69449f735ce6dec7b1cc37993ce51ab..0000000000000000000000000000000000000000 --- a/scripts/asr-feasibility.cjs +++ /dev/null @@ -1,12 +0,0 @@ -const { chromium } = require("playwright"); -(async () => { - const browser = await chromium.launch({ headless: false, args: ["--enable-unsafe-webgpu", "--enable-features=Vulkan", "--use-gl=angle", "--use-angle=swiftshader", "--ignore-gpu-blocklist"] }); - const page = await browser.newPage(); - page.on("console", (m) => console.log("PAGE:", m.text().slice(0, 200))); - await page.goto("http://127.0.0.1:8842/scripts/asr-feasibility.html", { waitUntil: "domcontentloaded" }); - for (let i = 0; i < 150; i++) { const done = await page.evaluate(() => window.__done).catch(() => false); if (done) break; await page.waitForTimeout(2000); } - const r = await page.evaluate(() => ({ log: window.__log, device: window.__device, text: window.__text, rt: window.__rt, err: window.__err })); - console.log("=== RESULT ===" + (r.log || "")); - console.log("DEVICE:", r.device, "| RTfactor:", r.rt, "| ERR:", r.err || "none"); - await browser.close(); -})(); diff --git a/scripts/asr-feasibility.html b/scripts/asr-feasibility.html deleted file mode 100644 index 55f9362864399c64b8875ba20acd411558ab41f5..0000000000000000000000000000000000000000 --- a/scripts/asr-feasibility.html +++ /dev/null @@ -1,41 +0,0 @@ -ASR feasibility -
loading…
- diff --git a/scripts/build_corridor_showcase.py b/scripts/build_corridor_showcase.py deleted file mode 100644 index 9fac910e9471aa4215658d9e312476f5ac131428..0000000000000000000000000000000000000000 --- a/scripts/build_corridor_showcase.py +++ /dev/null @@ -1,95 +0,0 @@ -"""Pre-render the corridor Showcase: a vivid, diverse journey generated by the -SAME live /world endpoint, downloaded into frontend/assets/corridor/ with a -manifest. The frontend plays it back instantly (no GPU) so anon-quota judges see -the full immersive experience without waiting. Everything here is produced by the -deployed app itself. Run: HF_READ_TOKEN=... python scripts/build_corridor_showcase.py -""" - -from __future__ import annotations - -import json -import os -import time -import urllib.request -from pathlib import Path - -from gradio_client import Client - -ROOT = Path(__file__).resolve().parents[1] -OUT = ROOT / "frontend" / "assets" / "corridor" -SPACE_ID = os.getenv("LIGHTLOOM_DEV_SPACE_ID", "Efradeca/lightloom-dev") -BASE = os.getenv("SPACE_URL", "https://efradeca-lightloom-dev.hf.space") - -# A vivid, diverse story that shows the full range — fantasy, cyberpunk, serene, -# underwater, cosmic — so the Showcase proves the worlds match what is told. -STORY = ( - "A sleeping dragon curled on a mountain of gold beneath two moons. " - "Far below, a neon city glittered in the falling rain. " - "A child set paper lanterns adrift on a glowing river at dusk. " - "Deep in a coral reef, a great whale drifted through ruins of light. " - "At the edge of the galaxy, a lone ship turned slowly toward home." -) - - -def _token() -> str: - tok = os.getenv("HF_READ_TOKEN") or os.getenv("HF_TOKEN") - if not tok: - raise SystemExit("HF_READ_TOKEN/HF_TOKEN required in env.") - return tok - - -def _dl(rel: str, dst: Path, token: str) -> int: - req = urllib.request.Request(BASE + rel, headers={"Authorization": "Bearer " + token}) - data = urllib.request.urlopen(req, timeout=90).read() - dst.write_bytes(data) - return len(data) - - -def main() -> int: - token = _token() - OUT.mkdir(parents=True, exist_ok=True) - client = Client(SPACE_ID, token=token, verbose=False) - job = client.submit(STORY, "en", api_name="/world") - scenes: dict[int, dict] = {} - t0 = time.time() - for ev in job: - if not isinstance(ev, dict): - continue - st = ev.get("stage") - i = ev.get("index") - if st == "scene": - scenes.setdefault(i, {})["image"] = ev.get("image") - scenes[i]["caption"] = ev.get("caption", "") - print(f"[{time.time()-t0:5.1f}s] scene {i}") - elif st == "depth": - scenes.setdefault(i, {})["depth"] = ev.get("depth") - elif st in ("error", "quota_exceeded", "scene_error"): - print(f" !! {st}: {ev.get('error')}") - elif st == "done": - print(f"[{time.time()-t0:5.1f}s] done ({ev.get('count')} scenes)") - - manifest = [] - for i in sorted(scenes): - s = scenes[i] - if not s.get("image"): - continue - img_name = f"scene-{i}.webp" - depth_name = f"scene-{i}-depth.png" - n1 = _dl(s["image"], OUT / img_name, token) - n2 = _dl(s["depth"], OUT / depth_name, token) if s.get("depth") else 0 - print(f" scene {i}: img={n1}B depth={n2}B {s.get('caption','')[:60]}") - manifest.append( - { - "index": i, - "caption": s.get("caption", ""), - "image": f"/frontend/assets/corridor/{img_name}", - "depth": f"/frontend/assets/corridor/{depth_name}" if s.get("depth") else None, - } - ) - (OUT / "manifest.json").write_text(json.dumps(manifest, indent=2), encoding="utf-8") - print(f"WROTE manifest with {len(manifest)} scenes -> {OUT/'manifest.json'}") - return 0 if manifest else 1 - - -if __name__ == "__main__": - raise SystemExit(main()) diff --git a/scripts/build_scroll_showcase.py b/scripts/build_scroll_showcase.py deleted file mode 100644 index 27c93db78e977629d369c968cfe0d93bb397079d..0000000000000000000000000000000000000000 --- a/scripts/build_scroll_showcase.py +++ /dev/null @@ -1,89 +0,0 @@ -"""Pre-render a continuous SCROLL showcase (sections + depth) so the world flows -behind the intro and during the ~30s model warm-up — the user never sees a black -screen. Generated by the same /scroll endpoint; bundled into frontend/assets/scroll/. -Run: HF_READ_TOKEN=... python scripts/build_scroll_showcase.py -""" - -from __future__ import annotations - -import json -import os -import time -import urllib.request -from pathlib import Path - -from gradio_client import Client - -ROOT = Path(__file__).resolve().parents[1] -OUT = ROOT / "frontend" / "assets" / "scroll" -SPACE_ID = os.getenv("LIGHTLOOM_DEV_SPACE_ID", "Efradeca/lightloom-dev") -BASE = os.getenv("SPACE_URL", "https://efradeca-lightloom-dev.hf.space") - -STORY = ( - "A glowing forest came alive with drifting fireflies. " - "A crystal river wound between the ancient trees. " - "A village of lantern-lit treehouses appeared in the canopy. " - "A great waterfall of light poured into a glowing canyon. " - "A temple floated among luminous clouds. " - "A field of giant bioluminescent flowers stretched to the horizon." -) - - -def _token() -> str: - tok = os.getenv("HF_READ_TOKEN") or os.getenv("HF_TOKEN") - if not tok: - raise SystemExit("HF_READ_TOKEN/HF_TOKEN required.") - return tok - - -def _dl(rel: str, dst: Path, token: str) -> int: - req = urllib.request.Request(BASE + rel, headers={"Authorization": "Bearer " + token}) - data = urllib.request.urlopen(req, timeout=90).read() - dst.write_bytes(data) - return len(data) - - -def main() -> int: - token = _token() - OUT.mkdir(parents=True, exist_ok=True) - client = Client(SPACE_ID, token=token, verbose=False) - job = client.submit(STORY, "en", api_name="/scroll") - secs: dict[int, dict] = {} - t0 = time.time() - for ev in job: - if not isinstance(ev, dict): - continue - st, i = ev.get("stage"), ev.get("index") - if st == "section": - secs.setdefault(i, {})["image"] = ev.get("image") - secs[i]["caption"] = ev.get("caption", "") - print(f"[{time.time()-t0:5.1f}s] section {i}") - elif st == "depth": - secs.setdefault(i, {})["depth"] = ev.get("depth") - elif st in ("error", "quota_exceeded", "section_error"): - print(f" !! {st}: {ev.get('error')}") - - manifest = [] - for i in sorted(secs): - s = secs[i] - if not s.get("image"): - continue - img, dep = f"section-{i}.webp", f"section-{i}-depth.png" - n1 = _dl(s["image"], OUT / img, token) - n2 = _dl(s["depth"], OUT / dep, token) if s.get("depth") else 0 - print(f" section {i}: img={n1}B depth={n2}B {s.get('caption','')[:50]}") - manifest.append( - { - "index": i, - "caption": s.get("caption", ""), - "image": f"/frontend/assets/scroll/{img}", - "depth": f"/frontend/assets/scroll/{dep}" if s.get("depth") else None, - } - ) - (OUT / "manifest.json").write_text(json.dumps(manifest, indent=2), encoding="utf-8") - print(f"WROTE manifest with {len(manifest)} sections -> {OUT/'manifest.json'}") - return 0 if manifest else 1 - - -if __name__ == "__main__": - raise SystemExit(main()) diff --git a/scripts/build_showcase.py b/scripts/build_showcase.py deleted file mode 100644 index db9e1a3fc94f4ad9914e699cef40e6814d960da9..0000000000000000000000000000000000000000 --- a/scripts/build_showcase.py +++ /dev/null @@ -1,91 +0,0 @@ -"""Pre-render the Showcase journey: one immersive world per stanza of the golden -recital, generated by the SAME live pipeline (/panorama on the Space), downloaded -into frontend/assets/showcase/ with a manifest. The frontend plays these back -instantly (no GPU) so anon-quota judges see the full experience immediately. - -Honesty: every asset here is produced by the deployed app's own /panorama -endpoint — nothing hand-painted. Run: python scripts/build_showcase.py -""" - -from __future__ import annotations - -import json -import os -import time -import urllib.request -from pathlib import Path - -from gradio_client import Client - -ROOT = Path(__file__).resolve().parents[1] -OUT = ROOT / "frontend" / "assets" / "showcase" -SPACE_ID = os.getenv("LIGHTLOOM_DEV_SPACE_ID", "Efradeca/lightloom-dev") -BASE = os.getenv("SPACE_URL", "https://efradeca-lightloom-dev.hf.space") - -# The golden recital, one world per stanza — a journey: storm -> intimate -> -# warm market -> cold silence. Title each so the player can subtitle it. -STANZAS = [ - ("An old lighthouse keeper counted the waves at the edge of the world.", "I. The edge of the world"), - ("Every night he climbed the spiral stairs, counting each step like a prayer.", "II. The spiral stairs"), - ("Far away, a market woke under orange awnings and wet stone.", "III. A market wakes"), - ("Years later, the same road lay buried under snow and silence.", "IV. Snow and silence"), -] - - -def _token() -> str: - tok = os.getenv("HF_READ_TOKEN") or os.getenv("HF_TOKEN") - if not tok: - raise SystemExit("HF_READ_TOKEN/HF_TOKEN required in env.") - return tok - - -def _download(rel: str, dst: Path, token: str) -> int: - req = urllib.request.Request(BASE + rel, headers={"Authorization": "Bearer " + token}) - data = urllib.request.urlopen(req, timeout=90).read() - dst.write_bytes(data) - return len(data) - - -def main() -> int: - token = _token() - OUT.mkdir(parents=True, exist_ok=True) - client = Client(SPACE_ID, token=token, verbose=False) - manifest = [] - for i, (stanza, title) in enumerate(STANZAS): - print(f"[{i}] generating: {title!r}") - t0 = time.time() - job = client.submit(stanza, "en", api_name="/panorama") - pano = depth = scene = None - for ev in job: - if isinstance(ev, dict): - if ev.get("scene"): - scene = ev["scene"] - pano = ev.get("panorama") or pano - depth = ev.get("depth") or depth - if ev.get("stage") in ("error", "quota_exceeded"): - print(f" !! {ev.get('stage')}: {ev.get('error')}") - if not pano: - print(f" !! no panorama for stanza {i}; skipping") - continue - pano_name = f"world-{i}.webp" - depth_name = f"world-{i}-depth.png" - n1 = _download(pano, OUT / pano_name, token) - n2 = _download(depth, OUT / depth_name, token) if depth else 0 - print(f" ok in {time.time()-t0:.0f}s pano={n1}B depth={n2}B scene={(scene or '')[:80]}") - manifest.append( - { - "index": i, - "title": title, - "stanza": stanza, - "scene": scene or "", - "panorama": f"/frontend/assets/showcase/{pano_name}", - "depth": f"/frontend/assets/showcase/{depth_name}" if depth else None, - } - ) - (OUT / "manifest.json").write_text(json.dumps(manifest, indent=2), encoding="utf-8") - print(f"WROTE manifest with {len(manifest)} worlds -> {OUT/'manifest.json'}") - return 0 if manifest else 1 - - -if __name__ == "__main__": - raise SystemExit(main()) diff --git a/scripts/deploy_private_space.py b/scripts/deploy_private_space.py deleted file mode 100644 index 6501341a9f0472ba30229e5da34a032e75da3d69..0000000000000000000000000000000000000000 --- a/scripts/deploy_private_space.py +++ /dev/null @@ -1,114 +0,0 @@ -"""Deploy the current private build to the personal Lightloom dev Space. - -Parameter contribution: 0B. This script uses HF_WRITE_TOKEN from the process -environment and never prints token values. -""" - -from __future__ import annotations - -import os -from pathlib import Path -import sys - -from huggingface_hub import HfApi, SpaceHardware - -ROOT = Path(__file__).resolve().parents[1] - - -def _token() -> str: - token = os.getenv("HF_WRITE_TOKEN") or os.getenv("HF_TOKEN") - if not token: - raise SystemExit("HF_WRITE_TOKEN/HF_TOKEN is required in the process environment.") - return token - - -def _read_token() -> str | None: - return os.getenv("HF_READ_TOKEN") or os.getenv("HF_TOKEN") - - -def _space_id(api: HfApi, token: str) -> str: - configured = os.getenv("LIGHTLOOM_DEV_SPACE_ID") - if configured: - return configured - info = api.whoami(token=token) - username = info.get("name") - if not username: - raise SystemExit("Could not infer HF username for personal dev Space.") - return f"{username}/lightloom-dev" - - -def _zero_hardware() -> SpaceHardware | None: - for candidate in SpaceHardware: - if "zero" in str(candidate.value).lower(): - return candidate - return None - - -def main() -> int: - token = _token() - api = HfApi(token=token) - space_id = _space_id(api, token) - api.create_repo( - space_id, - repo_type="space", - private=True, - exist_ok=True, - space_sdk="gradio", - space_hardware=_zero_hardware(), - ) - read_token = _read_token() - if read_token: - api.add_space_secret(space_id, "HF_TOKEN", read_token, token=token) - for key, value in { - "LIGHTLOOM_PROFILE": "space", - "LIGHTLOOM_PRIVACY_MODE": "1", - # OFF in production: this flag gates /internal/* probes AND the legacy /world + /panorama - # generators that load klein-BASE + a 3rd-party 360 LoRA NOT in the runtime ledger. Leaving - # it "1" silently re-enabled those un-ledgered endpoints for any judge -> a ledger/honesty - # contradiction. The live experience (/scroll_live) does not need it. Flip to "1" only for a - # local/offline bench run. - "LIGHTLOOM_ENABLE_INTERNAL_BENCH": os.getenv("LIGHTLOOM_ENABLE_INTERNAL_BENCH", "0"), - "LIGHTLOOM_G1_REPS": os.getenv("LIGHTLOOM_G1_REPS", "5"), - }.items(): - api.add_space_variable(space_id, key, value, token=token) - info = api.upload_folder( - repo_id=space_id, - repo_type="space", - folder_path=ROOT, - commit_message="chore: deploy private lightloom build", - ignore_patterns=[ - ".git/*", - ".venv/*", - ".env", - ".env.*", - "lightloom-docs/*", - "VideosExamples/*", # the user's private screen recordings + audio — NEVER ship - "*.zip", - "*.mp4", - "*.mp3", - "*.mov", - "__pycache__/*", - ".pytest_cache/*", - "node_modules/*", - ".shots/*", - "*.pdf", - "package.json", - "package-lock.json", - "benchmarks/results/g1.json", - "benchmarks/results/g1.md", - # session scratch (Modal renders, PDF page rasters, downloaded samples) — never ship - ".covers_dl/*", ".stylegrid/*", ".stylegrid2/*", ".modal_dataset_sample/*", - ".modal_validate/*", ".tut/*", ".train_script_ref.py", ".modal_*.log", - ".tutorial_text.txt", - ], - # Remove stale paths a previous (pre-ignore) deploy left on the Space — a large - # node_modules tree, a research PDF, and the user's private VideosExamples media. - delete_patterns=["node_modules/*", "*.pdf", "VideosExamples/*", "*.mp4", "*.mp3", "*.mov"], - token=token, - ) - print(f"DEPLOYED {space_id} {info.oid}") - return 0 - - -if __name__ == "__main__": - raise SystemExit(main()) diff --git a/scripts/fetch_gate_g1.py b/scripts/fetch_gate_g1.py deleted file mode 100644 index 3232a51a5c64d3a7aac18e83db1fcdb3a149c1e2..0000000000000000000000000000000000000000 --- a/scripts/fetch_gate_g1.py +++ /dev/null @@ -1,57 +0,0 @@ -"""Run G1 through the private Space endpoint and save returned results locally.""" - -from __future__ import annotations - -import json -import os -from pathlib import Path -import sys -from urllib.request import Request, urlopen - -ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(ROOT)) -OUT = ROOT / "benchmarks" / "results" / "g1.json" - - -def _space_id() -> str: - configured = os.getenv("LIGHTLOOM_DEV_SPACE_ID") - if configured: - return configured - token = os.getenv("HF_WRITE_TOKEN") or os.getenv("HF_TOKEN") - if not token: - raise SystemExit("HF_WRITE_TOKEN/HF_TOKEN is required to infer the Space id.") - from huggingface_hub import HfApi - - info = HfApi(token=token).whoami(token=token) - username = info.get("name") - if not username: - raise SystemExit("Could not infer HF username.") - return f"{username}/lightloom-dev" - - -def _url(space_id: str) -> str: - owner, name = space_id.split("/", 1) - return f"https://{owner}-{name}.hf.space/internal/bench/g1" - - -def main() -> int: - token = os.getenv("HF_WRITE_TOKEN") or os.getenv("HF_TOKEN") - if not token: - raise SystemExit("HF_WRITE_TOKEN/HF_TOKEN is required in the process environment.") - req = Request(_url(_space_id()), method="POST", headers={"Authorization": f"Bearer {token}"}) - with urlopen(req, timeout=int(os.getenv("LIGHTLOOM_G1_TIMEOUT", "1800"))) as response: - payload = json.loads(response.read().decode("utf-8")) - if not payload.get("ok"): - raise SystemExit(f"Space G1 endpoint failed: {payload}") - OUT.parent.mkdir(parents=True, exist_ok=True) - OUT.write_text(json.dumps(payload["data"], indent=2, sort_keys=True) + "\n", encoding="utf-8") - from benchmarks.gate_g1 import DEFAULT_MD, _write_markdown - - _write_markdown(DEFAULT_MD, payload["data"]) - print(f"WROTE {OUT}") - print(f"DECISION {payload['data']['decision']['status']}") - return 0 - - -if __name__ == "__main__": - raise SystemExit(main()) diff --git a/scripts/fetch_gate_g2_g3.py b/scripts/fetch_gate_g2_g3.py deleted file mode 100644 index b1ce112890e24e7d82482e463f1db2a973d19309..0000000000000000000000000000000000000000 --- a/scripts/fetch_gate_g2_g3.py +++ /dev/null @@ -1,52 +0,0 @@ -"""Run G2/G3 through the private Space endpoint and save returned results locally.""" - -from __future__ import annotations - -import json -import os -from pathlib import Path -import sys -from urllib.request import Request, urlopen - -ROOT = Path(__file__).resolve().parents[1] -OUT_DIR = ROOT / "benchmarks" / "results" -sys.path.insert(0, str(ROOT)) - - -def _space_id() -> str: - configured = os.getenv("LIGHTLOOM_DEV_SPACE_ID") - if configured: - return configured - token = os.getenv("HF_WRITE_TOKEN") or os.getenv("HF_TOKEN") - if not token: - raise SystemExit("HF_WRITE_TOKEN/HF_TOKEN is required to infer the Space id.") - from huggingface_hub import HfApi - - info = HfApi(token=token).whoami(token=token) - return f"{info['name']}/lightloom-dev" - - -def main() -> int: - token = os.getenv("HF_WRITE_TOKEN") or os.getenv("HF_TOKEN") - if not token: - raise SystemExit("HF_WRITE_TOKEN/HF_TOKEN is required in the process environment.") - owner, name = _space_id().split("/", 1) - req = Request( - f"https://{owner}-{name}.hf.space/internal/bench/g2-g3", - method="POST", - headers={"Authorization": f"Bearer {token}"}, - ) - with urlopen(req, timeout=int(os.getenv("LIGHTLOOM_G23_TIMEOUT", "1800"))) as response: - payload = json.loads(response.read().decode("utf-8")) - if not payload.get("ok"): - raise SystemExit(f"Space G2/G3 endpoint failed: {payload}") - OUT_DIR.mkdir(parents=True, exist_ok=True) - (OUT_DIR / "g2.json").write_text(json.dumps(payload["g2"], indent=2, sort_keys=True) + "\n", encoding="utf-8") - (OUT_DIR / "g3.json").write_text(json.dumps(payload["g3"], indent=2, sort_keys=True) + "\n", encoding="utf-8") - print(f"G2 {payload['g2']['decision']}") - print(f"G3 {payload['g3']['decision']}") - return 0 - - -if __name__ == "__main__": - raise SystemExit(main()) diff --git a/scripts/preflight.py b/scripts/preflight.py deleted file mode 100644 index 25fd8c2c65be82313a1ce80e2800cf87849f4024..0000000000000000000000000000000000000000 --- a/scripts/preflight.py +++ /dev/null @@ -1,395 +0,0 @@ -"""Lightloom preflight checks. - -Writes benchmarks/results/preflight.json and prints a redacted summary. The -script never prints token values and never persists secrets. -""" - -from __future__ import annotations - -import importlib -import json -import os -from pathlib import Path -import platform -import sys -import time -from typing import Any - -ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(ROOT / "src")) -RESULTS = ROOT / "benchmarks" / "results" -PREFLIGHT_JSON = RESULTS / "preflight.json" -ORG_NAME = os.getenv("LIGHTLOOM_HF_ORG", "build-small-hackathon") -DEV_SPACE_ID = os.getenv("LIGHTLOOM_DEV_SPACE_ID") - - -def _env_present(name: str) -> bool: - return bool(os.getenv(name, "").strip()) - - -def _token() -> str | None: - for name in ("HF_WRITE_TOKEN", "HF_TOKEN"): - value = os.getenv(name, "").strip() - if value: - return value - return None - - -def _missing_token_message() -> str: - return ( - "HF_WRITE_TOKEN/HF_TOKEN is not set in the process environment. " - "Install env vars without writing secrets to files: " - "PowerShell -ExecutionPolicy Bypass -File scripts/set_hf_env.ps1" - ) - - -def _check(name: str, ok: bool, message: str, evidence: dict[str, Any] | None = None) -> dict[str, Any]: - return { - "name": name, - "ok": bool(ok), - "message": message, - "evidence": evidence or {}, - } - - -def _run_python_import(module: str) -> tuple[bool, str | None]: - try: - imported = importlib.import_module(module) - except Exception as exc: # noqa: BLE001 - preflight reports dependency health. - return False, f"{type(exc).__name__}: {exc}" - version = getattr(imported, "__version__", None) - return True, str(version) if version is not None else "installed" - - -def check_p1_org_membership() -> dict[str, Any]: - token = _token() - if token is None: - return _check( - "P1 org membership", - False, - _missing_token_message(), - {"required_org": ORG_NAME}, - ) - try: - from huggingface_hub import HfApi - - info = HfApi(token=token).whoami(token=token) - orgs = [org.get("name") for org in info.get("orgs", [])] - user = info.get("name") or info.get("fullname") or "unknown" - ok = ORG_NAME in orgs - return _check( - "P1 org membership", - ok, - "authenticated user is a member of the hackathon org" - if ok - else "authenticated user is not a member of the hackathon org", - {"user": user, "required_org": ORG_NAME, "org_present": ok}, - ) - except Exception as exc: # noqa: BLE001 - return _check( - "P1 org membership", - False, - f"whoami failed: {type(exc).__name__}", - {"required_org": ORG_NAME}, - ) - - -def check_p2_space() -> dict[str, Any]: - token = _token() - if token is None: - return _check( - "P2 private ZeroGPU Space", - False, - "HF_WRITE_TOKEN/HF_TOKEN is not set; cannot create or inspect private dev Space.", - {"space_id": DEV_SPACE_ID or "unset"}, - ) - try: - from huggingface_hub import HfApi, SpaceHardware - - api = HfApi(token=token) - inferred_space_id = DEV_SPACE_ID - if inferred_space_id is None: - info = api.whoami(token=token) - username = info.get("name") - if not username: - return _check( - "P2 private ZeroGPU Space", - False, - "could not infer personal namespace from whoami", - {"privacy_mode": True}, - ) - inferred_space_id = f"{username}/lightloom-dev" - hardware = None - for candidate in SpaceHardware: - if "zero" in str(candidate.value).lower(): - hardware = candidate - break - api.create_repo( - inferred_space_id, - repo_type="space", - private=True, - exist_ok=True, - space_sdk="gradio", - space_hardware=hardware, - space_secrets=[ - {"key": "HF_TOKEN", "value": os.getenv("HF_READ_TOKEN", os.getenv("HF_TOKEN", ""))} - ] - if (os.getenv("HF_READ_TOKEN") or os.getenv("HF_TOKEN")) - else None, - space_variables=[ - {"key": "LIGHTLOOM_PROFILE", "value": "space"}, - {"key": "LIGHTLOOM_PRIVACY_MODE", "value": "1"}, - ], - ) - runtime = api.get_space_runtime(inferred_space_id, token=token) - runtime_hardware = getattr(runtime, "hardware", None) - requested = getattr(runtime, "requested_hardware", None) - stage = getattr(runtime, "stage", None) - sdk = getattr(runtime, "sdk", None) - zero_gpu = "zero" in str(runtime_hardware or requested or hardware).lower() - ok = zero_gpu and (sdk in {None, "gradio"} or "gradio" in str(sdk).lower()) - return _check( - "P2 private ZeroGPU Space", - ok, - "private dev Space exists and appears to be ZeroGPU/Gradio" - if ok - else "dev Space does not show ZeroGPU/Gradio runtime metadata", - { - "space_id": inferred_space_id, - "privacy": "private", - "hardware": str(runtime_hardware), - "requested_hardware": str(requested), - "created_or_reused": True, - "stage": str(stage), - "sdk": str(sdk), - }, - ) - except Exception as exc: # noqa: BLE001 - return _check( - "P2 private ZeroGPU Space", - False, - f"Space inspection failed: {type(exc).__name__}", - {"space_id": DEV_SPACE_ID}, - ) - - -def check_p3_secrets() -> dict[str, Any]: - return _check( - "P3 runtime secret contract", - _env_present("HF_READ_TOKEN") or _env_present("HF_TOKEN"), - "read token env var is available for configuring the Space secret" - if (_env_present("HF_READ_TOKEN") or _env_present("HF_TOKEN")) - else "HF_READ_TOKEN/HF_TOKEN is not set in this process", - {"secret_names_only": ["HF_TOKEN"]}, - ) - - -def check_p4_local_versions() -> dict[str, Any]: - from lightloom.core.config import CONFIG - - imports = {} - for module in ("gradio", "huggingface_hub", "transformers", "diffusers", "torch", "llama_cpp"): - ok, detail = _run_python_import(module) - imports[module] = {"ok": ok, "detail": detail} - py_ok = sys.version_info >= (3, 10) - missing = [name for name, result in imports.items() if not result["ok"]] - torch_evidence: dict[str, Any] = {} - try: - import torch - - torch_evidence = { - "torch": getattr(torch, "__version__", "unknown"), - "cuda_available": bool(torch.cuda.is_available()), - "cuda_version": getattr(torch.version, "cuda", None), - "arch_list": list(torch.cuda.get_arch_list()) if torch.cuda.is_available() else [], - "sm_120_supported": "sm_120" in ( - torch.cuda.get_arch_list() if torch.cuda.is_available() else [] - ), - "cuda_kernel_smoke": False, - } - if torch.cuda.is_available(): - x = torch.ones((8, 8), device="cuda") - torch_evidence["cuda_kernel_smoke"] = bool((x @ x).sum().item() == 512.0) - except Exception as exc: # noqa: BLE001 - torch_evidence = {"torch_error": f"{type(exc).__name__}: {exc}"} - local_cuda_ok = True - if CONFIG.profile == "local": - local_cuda_ok = bool( - torch_evidence.get("cuda_available") - and torch_evidence.get("sm_120_supported") - and torch_evidence.get("cuda_kernel_smoke") - ) - ok = py_ok and not missing and local_cuda_ok - return _check( - "P4 local versions", - ok, - "Python, required imports, and local CUDA smoke check are available" - if ok - else "missing packages or local CUDA/sm_120 smoke check failed", - { - "python": sys.version, - "executable": sys.executable, - "platform": platform.platform(), - "imports": imports, - "torch": torch_evidence, - "packages_txt_has_ffmpeg": (ROOT / "packages.txt").read_text().strip() == "ffmpeg", - }, - ) - - -def check_p5_models() -> dict[str, Any]: - from lightloom.core.config import CONFIG, MODEL_REFS - - token = _token() - if token is None: - return _check( - "P5 model cards", - False, - "HF_WRITE_TOKEN/HF_TOKEN is not set; cannot verify private/gated model cards.", - { - "profile": CONFIG.profile, - "local_flux_dtype": CONFIG.flux_dtype, - "local_resolution": [CONFIG.width, CONFIG.height], - "local_aot": CONFIG.flux_aot, - "model_count": len(MODEL_REFS), - }, - ) - try: - from huggingface_hub import HfApi - - api = HfApi(token=token) - resolved: dict[str, Any] = {} - failures: dict[str, str] = {} - for key, ref in MODEL_REFS.items(): - if key == "rife": - resolved[key] = { - "repo_id": ref.repo_id, - "license": ref.license, - "note": "GitHub repo; checkpoint license remains VERIFY until selected.", - } - continue - try: - info = api.model_info(ref.repo_id, token=token) - license_name = None - if getattr(info, "card_data", None): - license_name = getattr(info.card_data, "license", None) - resolved[key] = { - "repo_id": ref.repo_id, - "sha": getattr(info, "sha", None), - "license": license_name or ref.license, - "private": bool(getattr(info, "private", False)), - } - except Exception as exc: # noqa: BLE001 - failures[key] = f"{type(exc).__name__}: {exc}" - ok = not failures - return _check( - "P5 model cards", - ok, - "model cards resolved" if ok else "one or more model cards failed to resolve", - { - "profile": CONFIG.profile, - "local_flux_dtype": CONFIG.flux_dtype, - "local_resolution": [CONFIG.width, CONFIG.height], - "local_aot": CONFIG.flux_aot, - "resolved": resolved, - "failures": failures, - }, - ) - except Exception as exc: # noqa: BLE001 - return _check("P5 model cards", False, f"Hub verification failed: {type(exc).__name__}") - - -def check_p6_disk_cache() -> dict[str, Any]: - usage = None - try: - usage = os.statvfs(ROOT) # type: ignore[attr-defined] - free_gb = usage.f_bavail * usage.f_frsize / (1024**3) - except AttributeError: - import shutil - - free_gb = shutil.disk_usage(ROOT).free / (1024**3) - ok = free_gb >= 30 - return _check( - "P6 disk/cache", - ok, - "local disk has room for iterative caches" if ok else "low free disk for model caches", - {"free_gb": round(free_gb, 2), "estimated_runtime_weights_gb": 20}, - ) - - -def check_p7_spaces_import() -> dict[str, Any]: - ok, detail = _run_python_import("spaces") - return _check( - "P7 spaces decorator", - ok, - "spaces package imports" if ok else "spaces package is missing", - {"detail": detail}, - ) - - -def check_secret_scan() -> dict[str, Any]: - token_re = __import__("re").compile(r"hf_[A-Za-z0-9]{20,}") - skip_parts = {".git", ".venv", "__pycache__", ".pytest_cache"} - skip_suffixes = {".zip", ".7z", ".tar", ".gz", ".png", ".jpg", ".jpeg", ".webp", ".mp4", ".wav"} - matches: list[str] = [] - try: - for path in ROOT.rglob("*"): - if any(part in skip_parts for part in path.parts): - continue - if not path.is_file() or path.suffix.lower() in skip_suffixes: - continue - try: - text = path.read_text(encoding="utf-8") - except UnicodeDecodeError: - continue - if token_re.search(text): - matches.append(str(path.relative_to(ROOT))) - except Exception as exc: # noqa: BLE001 - return _check("secret scan", False, f"secret scan failed: {type(exc).__name__}") - ok = not matches - return _check( - "secret scan", - ok, - "no HF token patterns in tracked files" if ok else "possible HF token pattern found", - {"match_files": sorted(set(matches))}, - ) - - -def run() -> dict[str, Any]: - start = time.time() - RESULTS.mkdir(parents=True, exist_ok=True) - checks = [ - check_p1_org_membership(), - check_p2_space(), - check_p3_secrets(), - check_p4_local_versions(), - check_p5_models(), - check_p6_disk_cache(), - check_p7_spaces_import(), - check_secret_scan(), - ] - result = { - "schema_version": 1, - "generated_at": time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime()), - "hardware_profile": os.getenv("LIGHTLOOM_PROFILE", "local"), - "privacy_mode": True, - "all_green": all(check["ok"] for check in checks), - "checks": checks, - "elapsed_s": round(time.time() - start, 3), - } - PREFLIGHT_JSON.write_text(json.dumps(result, indent=2, sort_keys=True) + "\n", encoding="utf-8") - return result - - -def main() -> int: - result = run() - print("LIGHTLOOM PREFLIGHT") - for check in result["checks"]: - status = "PASS" if check["ok"] else "FAIL" - print(f"{status} {check['name']}: {check['message']}") - print(f"RESULT {'ALL GREEN' if result['all_green'] else 'BLOCKED'} -> {PREFLIGHT_JSON}") - return 0 if result["all_green"] else 1 - - -if __name__ == "__main__": - raise SystemExit(main()) diff --git a/scripts/release_check.py b/scripts/release_check.py deleted file mode 100644 index a8fc790b5b946b34dc041a334e371991be703aac..0000000000000000000000000000000000000000 --- a/scripts/release_check.py +++ /dev/null @@ -1,84 +0,0 @@ -"""Release gate for Lightloom. - -This starts strict and becomes stricter through F4/F5. It already enforces the -privacy addendum's no-secret/no-placeholder posture. -""" - -from __future__ import annotations - -import json -from pathlib import Path -import re -import subprocess -import sys - -ROOT = Path(__file__).resolve().parents[1] -TOKEN_RE = re.compile(r"hf_[A-Za-z0-9]{20,}") - - -def fail(message: str) -> str: - return f"FAIL {message}" - - -def ok(message: str) -> str: - return f"PASS {message}" - - -def secret_scan() -> tuple[bool, str]: - tracked = subprocess.run( - ["git", "ls-files"], - cwd=ROOT, - text=True, - capture_output=True, - check=False, - ) - if tracked.returncode != 0: - return False, "git ls-files failed" - offenders: list[str] = [] - for rel in tracked.stdout.splitlines(): - path = ROOT / rel - if not path.is_file(): - continue - try: - text = path.read_text(encoding="utf-8") - except UnicodeDecodeError: - continue - if TOKEN_RE.search(text): - offenders.append(rel) - if offenders: - return False, "token-like secret found in tracked files: " + ", ".join(offenders) - return True, "no token-like secrets in tracked files" - - -def preflight_result() -> tuple[bool, str]: - path = ROOT / "benchmarks" / "results" / "preflight.json" - if not path.exists(): - return False, "benchmarks/results/preflight.json is missing" - data = json.loads(path.read_text(encoding="utf-8")) - if not data.get("all_green"): - return False, "preflight is not ALL GREEN" - return True, "preflight ALL GREEN" - - -def h6_placeholder_gate() -> tuple[bool, str]: - readme = ROOT / "README.md" - if not readme.exists(): - return False, "README.md is missing" - text = readme.read_text(encoding="utf-8") - release_mode = (ROOT / "docs" / "submission" / "H6_GREEN").exists() - if release_mode and "⟦PLACEHOLDER⟧" in text: - return False, "H6 release mode forbids README placeholders" - return True, "README placeholder state accepted for current private mode" - - -def main() -> int: - checks = [secret_scan(), preflight_result(), h6_placeholder_gate()] - for passed, message in checks: - print(ok(message) if passed else fail(message)) - all_green = all(passed for passed, _ in checks) - print("RESULT " + ("ALL GREEN" if all_green else "BLOCKED")) - return 0 if all_green else 1 - - -if __name__ == "__main__": - raise SystemExit(main()) diff --git a/scripts/set_hf_env.ps1 b/scripts/set_hf_env.ps1 deleted file mode 100644 index 1cca89b03ff5b5cdde04d11d37cea61431116aa2..0000000000000000000000000000000000000000 --- a/scripts/set_hf_env.ps1 +++ /dev/null @@ -1,55 +0,0 @@ -param( - [switch]$PersistUser = $true, - [string]$DevSpaceId = "" -) - -$ErrorActionPreference = "Stop" - -function Read-SecretPlainText { - param([Parameter(Mandatory = $true)][string]$Name) - $secure = Read-Host -Prompt "Enter $Name" -AsSecureString - $bstr = [Runtime.InteropServices.Marshal]::SecureStringToBSTR($secure) - try { - return [Runtime.InteropServices.Marshal]::PtrToStringBSTR($bstr) - } - finally { - if ($bstr -ne [IntPtr]::Zero) { - [Runtime.InteropServices.Marshal]::ZeroFreeBSTR($bstr) - } - } -} - -function Set-EnvValue { - param( - [Parameter(Mandatory = $true)][string]$Name, - [Parameter(Mandatory = $true)][string]$Value - ) - Set-Item -Path "Env:$Name" -Value $Value - if ($PersistUser) { - [Environment]::SetEnvironmentVariable($Name, $Value, "User") - } -} - -$writeToken = Read-SecretPlainText -Name "HF_WRITE_TOKEN" -$readToken = Read-SecretPlainText -Name "HF_READ_TOKEN" - -if (-not $writeToken.StartsWith("hf_")) { - throw "HF_WRITE_TOKEN must look like a Hugging Face token." -} -if (-not $readToken.StartsWith("hf_")) { - throw "HF_READ_TOKEN must look like a Hugging Face token." -} - -Set-EnvValue -Name "HF_WRITE_TOKEN" -Value $writeToken -Set-EnvValue -Name "HF_READ_TOKEN" -Value $readToken -Set-EnvValue -Name "HF_TOKEN" -Value $readToken - -if ($DevSpaceId.Trim().Length -gt 0) { - Set-EnvValue -Name "LIGHTLOOM_DEV_SPACE_ID" -Value $DevSpaceId.Trim() -} - -Set-EnvValue -Name "LIGHTLOOM_PROFILE" -Value "local" -Set-EnvValue -Name "LIGHTLOOM_HF_ORG" -Value "build-small-hackathon" - -Write-Host "HF environment variables installed. Token values were not printed." -Write-Host "Restart the terminal or launch Codex from this shell for persisted user env changes to apply." diff --git a/scripts/shoot-app.cjs b/scripts/shoot-app.cjs deleted file mode 100644 index 9ff0b0ecc69bf9845b1ccdace9b429f585533b6f..0000000000000000000000000000000000000000 --- a/scripts/shoot-app.cjs +++ /dev/null @@ -1,90 +0,0 @@ -// Full-app visual validation: load the REAL index.html (real stage.js controller -// + LL.pano), stub LL.api.streamPanorama with the downloaded REAL panorama+depth, -// fire "Roll", and screenshot the immersive world inside the real app shell. This -// exercises the entire controller wiring end-to-end without spending GPU/quota. -// Usage: node scripts/shoot-app.cjs -const { chromium } = require("playwright"); -const http = require("http"); -const fs = require("fs"); -const path = require("path"); - -const ROOT = process.cwd(); -const PORT = 8802; -const CT = { - ".html": "text/html", ".js": "application/javascript", ".mjs": "application/javascript", - ".css": "text/css", ".woff2": "font/woff2", ".webp": "image/webp", ".png": "image/png", - ".json": "application/json", ".svg": "image/svg+xml", -}; - -const server = http.createServer((req, res) => { - let p = decodeURIComponent(req.url.split("?")[0]); - if (p === "/") p = "/frontend/index.html"; - if (p.startsWith("/shots/")) p = "/.shots/" + p.slice(7); // downloaded real assets - const file = path.join(ROOT, p); - fs.readFile(file, (err, data) => { - if (err) { res.writeHead(404); res.end("not found"); return; } - res.writeHead(200, { "content-type": CT[path.extname(file)] || "application/octet-stream" }); - res.end(data); - }); -}); - -(async () => { - const SHOTS = path.join(ROOT, ".shots"); - fs.mkdirSync(SHOTS, { recursive: true }); - const shot = (n) => path.join(SHOTS, n); - await new Promise((r) => server.listen(PORT, r)); - const browser = await chromium.launch({ - args: ["--use-gl=angle", "--use-angle=swiftshader", "--ignore-gpu-blocklist", "--enable-webgl"], - }); - const page = await browser.newPage({ viewport: { width: 1680, height: 820 }, deviceScaleFactor: 1 }); - const errs = []; - page.on("console", (m) => { if (m.type() === "error") errs.push(m.text().slice(0, 200)); }); - page.on("pageerror", (e) => errs.push("PAGEERROR: " + e.message.slice(0, 200))); - - await page.goto(`http://localhost:${PORT}/frontend/index.html`, { waitUntil: "networkidle", timeout: 25000 }).catch((e) => errs.push("goto: " + e.message)); - await page.waitForTimeout(1500); - await page.screenshot({ path: shot("app-lobby.png") }); - - // Stub the GPU stream with the REAL downloaded world, then fire a Roll exactly - // as a user would (controller.startRecital reads #recital-text + drives LL.pano). - const started = await page.evaluate(async () => { - const LL = window.LL; - if (!LL || !LL.api || !LL.controller) return { ok: false, why: "LL.api/controller missing" }; - const sleep = (ms) => new Promise((r) => setTimeout(r, ms)); - LL.api.streamPanorama = async (text, lang, onEvent) => { - onEvent({ stage: "warming" }); - await sleep(60); - onEvent({ stage: "directed", shot: { shot_type: "wide", lighting: "stormy dusk", camera_move: "drift" }, scene: "an old lighthouse keeper at the edge of the world, stormy dusk" }); - onEvent({ stage: "painting" }); - await sleep(60); - onEvent({ stage: "painted", panorama: "/shots/real-pano.webp" }); - await sleep(80); - onEvent({ stage: "depth", depth: "/shots/real-depth.png" }); - onEvent({ stage: "done", session: "harness" }); - return { session: "harness", done: true, cancelled: false }; - }; - const ta = document.getElementById("recital-text"); - if (ta) ta.value = "An old lighthouse keeper counted the waves at the edge of the world."; - LL.controller.startRecital(); - return { ok: true, pano: typeof (LL.pano && LL.pano.show), ready: LL.pano && LL.pano.ready }; - }).catch((e) => ({ ok: false, why: "evaluate: " + e.message })); - - // Nudge a resize so LL.pano sizes its buffer to the now-visible #set canvas. - await page.waitForTimeout(400); - await page.evaluate(() => window.dispatchEvent(new Event("resize"))); - await page.waitForTimeout(1600); - await page.screenshot({ path: shot("app-world-1.png") }); - await page.waitForTimeout(2600); // let the camera drift to a new angle - await page.screenshot({ path: shot("app-world-2.png") }); - - const st = await page.evaluate(() => ({ - state: window.LL.controller.state, - activeScreen: [...document.querySelectorAll(".screen.is-active")].map((s) => s.id), - panoReady: window.LL.pano && window.LL.pano.ready, - })); - console.log("STARTED:", JSON.stringify(started)); - console.log("STATE:", JSON.stringify(st)); - console.log("JS_ERRORS:", JSON.stringify(errs.slice(0, 12))); - await browser.close(); - server.close(); -})().catch((e) => { console.error("HARNESS ERROR:", e.message); process.exit(1); }); diff --git a/scripts/shoot-corridor.cjs b/scripts/shoot-corridor.cjs deleted file mode 100644 index 0f8129c822aebb6345c639dace9f66a4dbba4ab6..0000000000000000000000000000000000000000 --- a/scripts/shoot-corridor.cjs +++ /dev/null @@ -1,57 +0,0 @@ -// Validate the 3D corridor renderer (stage-corridor.js): feed the 4 existing -// showcase worlds as streamed scenes and screenshot the camera flying forward -// through the growing corridor. Usage: node scripts/shoot-corridor.cjs -const { chromium } = require("playwright"); -const http = require("http"); -const fs = require("fs"); -const path = require("path"); -const ROOT = process.cwd(); -const PORT = 8805; -const CT = { ".html": "text/html", ".js": "application/javascript", ".css": "text/css", ".woff2": "font/woff2", ".webp": "image/webp", ".png": "image/png" }; - -const TEST_HTML = ` - - - -`; - -const server = http.createServer((req, res) => { - let p = decodeURIComponent(req.url.split("?")[0]); - if (p === "/_corridor.html") { res.writeHead(200, { "content-type": "text/html" }); res.end(TEST_HTML); return; } - if (p.startsWith("/shots/")) p = "/.shots/" + p.slice(7); - const file = path.join(ROOT, p); - fs.readFile(file, (e, d) => { if (e) { res.writeHead(404); res.end("nf"); } else { res.writeHead(200, { "content-type": CT[path.extname(file)] || "application/octet-stream" }); res.end(d); } }); -}); - -(async () => { - const SHOTS = path.join(ROOT, ".shots"); fs.mkdirSync(SHOTS, { recursive: true }); - await new Promise((r) => server.listen(PORT, r)); - const browser = await chromium.launch({ args: ["--use-gl=angle", "--use-angle=swiftshader", "--ignore-gpu-blocklist", "--enable-webgl"] }); - const page = await browser.newPage({ viewport: { width: 1280, height: 720 } }); - const errs = []; page.on("pageerror", (e) => errs.push(e.message.slice(0, 200))); - page.on("console", (m) => { if (m.type() === "error") errs.push(m.text().slice(0, 200)); }); - await page.goto(`http://localhost:${PORT}/_corridor.html`, { waitUntil: "networkidle", timeout: 25000 }).catch((e) => errs.push("goto:" + e.message)); - // capture across the fly-through (scenes stream every 1.8s; camera advances) - const caps = [2500, 6500, 10500, 14500, 18500]; - let prev = 0; - for (let i = 0; i < caps.length; i++) { - await page.waitForTimeout(caps[i] - prev); prev = caps[i]; - await page.screenshot({ path: path.join(SHOTS, `corridor-${i}.png`) }); - } - const st = await page.evaluate(() => ({ ready: window.LL.corridor.ready, count: window.LL.corridor.count, added: window.__added })); - console.log("CORRIDOR:", JSON.stringify(st), "ERRS:", JSON.stringify(errs.slice(0, 8))); - await browser.close(); server.close(); -})().catch((e) => { console.error("ERR:", e.message); process.exit(1); }); diff --git a/scripts/shoot-immersive.cjs b/scripts/shoot-immersive.cjs deleted file mode 100644 index 3319e8fa32e330a819a604cc159117524aab8bfb..0000000000000000000000000000000000000000 --- a/scripts/shoot-immersive.cjs +++ /dev/null @@ -1,68 +0,0 @@ -// Validate the new immersive frontend: the intro (hero mic), then a stubbed -// streamWorld feeding the 4 real generated scenes into the corridor while the HUD -// orchestra lights up. Usage: node scripts/shoot-immersive.cjs -const { chromium } = require("playwright"); -const http = require("http"); -const fs = require("fs"); -const path = require("path"); -const ROOT = process.cwd(); -const PORT = 8806; -const CT = { ".html": "text/html", ".js": "application/javascript", ".css": "text/css", ".woff2": "font/woff2", ".webp": "image/webp", ".png": "image/png", ".svg": "image/svg+xml" }; - -const server = http.createServer((req, res) => { - let p = decodeURIComponent(req.url.split("?")[0]); - if (p === "/") p = "/frontend/index.html"; - if (p.startsWith("/shots/")) p = "/.shots/" + p.slice(7); - const file = path.join(ROOT, p); - fs.readFile(file, (e, d) => { if (e) { res.writeHead(404); res.end("nf"); } else { res.writeHead(200, { "content-type": CT[path.extname(file)] || "application/octet-stream" }); res.end(d); } }); -}); - -(async () => { - const SHOTS = path.join(ROOT, ".shots"); fs.mkdirSync(SHOTS, { recursive: true }); - const shot = (n) => path.join(SHOTS, n); - await new Promise((r) => server.listen(PORT, r)); - const browser = await chromium.launch({ args: ["--use-gl=angle", "--use-angle=swiftshader", "--ignore-gpu-blocklist", "--enable-webgl"] }); - const page = await browser.newPage({ viewport: { width: 1680, height: 900 } }); - const errs = []; page.on("pageerror", (e) => errs.push("PE:" + e.message.slice(0, 200))); - page.on("console", (m) => { if (m.type() === "error") errs.push(m.text().slice(0, 200)); }); - - await page.goto(`http://localhost:${PORT}/frontend/index.html`, { waitUntil: "networkidle", timeout: 25000 }).catch((e) => errs.push("goto:" + e.message)); - await page.waitForTimeout(1400); - await page.screenshot({ path: shot("imm-intro.png") }); - - // Stub streamWorld to feed the 4 real scenes, then start a world. - const started = await page.evaluate(async () => { - const LL = window.LL; - if (!LL || !LL.controller) return { ok: false, why: "no controller" }; - const sleep = (ms) => new Promise((r) => setTimeout(r, ms)); - const captions = ["A lighthouse keeper watched the waves at the edge of the world.", "Far away, a market woke under orange awnings.", "A child ran through a garden of impossible glowing flowers.", "Then snow buried the quiet road in silence."]; - LL.api.streamScroll = async (text, lang, onEvent) => { - onEvent({ stage: "warming", sections: 4 }); - await sleep(120); - for (let i = 0; i < 4; i++) { - onEvent({ stage: "directing", index: i, text: captions[i] }); - await sleep(120); - onEvent({ stage: "painting", index: i }); - await sleep(120); - onEvent({ stage: "section", index: i, image: "/shots/world/w-" + i + ".webp", caption: captions[i], w: 1024 }); - onEvent({ stage: "depth", index: i, depth: "/shots/world/w-" + i + "-depth.png" }); - await sleep(2600); - } - onEvent({ stage: "done", session: "imm", count: 4 }); - return { session: "imm", done: true, cancelled: false }; - }; - LL.controller.startWorld("An old lighthouse keeper counted the waves..."); - return { ok: true }; - }).catch((e) => ({ ok: false, why: String(e).slice(0, 160) })); - - await page.waitForTimeout(700); - await page.evaluate(() => window.dispatchEvent(new Event("resize"))); - const caps = [1800, 4600, 7600, 10600]; - let prev = 0; - for (let i = 0; i < caps.length; i++) { await page.waitForTimeout(caps[i] - prev); prev = caps[i]; await page.screenshot({ path: shot("imm-world-" + i + ".png") }); } - - const st = await page.evaluate(() => ({ corridorReady: window.LL.corridor && window.LL.corridor.ready, count: window.LL.corridor && window.LL.corridor.count, inWorld: document.body.classList.contains("in-world") })); - console.log("STARTED:", JSON.stringify(started), "STATE:", JSON.stringify(st)); - console.log("JS_ERRORS:", JSON.stringify(errs.slice(0, 10))); - await browser.close(); server.close(); -})().catch((e) => { console.error("ERR:", e.message); process.exit(1); }); diff --git a/scripts/shoot-intro-local.cjs b/scripts/shoot-intro-local.cjs deleted file mode 100644 index 67bf060ed1f58e60965b9ed191611038778d7220..0000000000000000000000000000000000000000 --- a/scripts/shoot-intro-local.cjs +++ /dev/null @@ -1,68 +0,0 @@ -// LOCAL intro/ambient check (no backend, no GPU): serves nothing itself — point it -// at a static server rooted at the repo (python -m http.server). Verifies the cleaned -// intro overlay + that the ambient world FLOWS behind it (the void-fix gap-filler) and -// that the JS modules load with no errors. The live mic/GPU path is NOT exercised here -// (that needs the Space); this is purely the visual regression for intro + flow. -// Usage: BASE=http://127.0.0.1:8842 node scripts/shoot-intro-local.cjs -const { chromium } = require("playwright"); -const path = require("path"); -const fs = require("fs"); - -const BASE = process.env.BASE || "http://127.0.0.1:8842"; - -(async () => { - const SHOTS = path.join(process.cwd(), ".shots"); - fs.mkdirSync(SHOTS, { recursive: true }); - const shot = (n) => path.join(SHOTS, n); - const browser = await chromium.launch({ args: ["--use-gl=angle", "--use-angle=swiftshader", "--ignore-gpu-blocklist", "--enable-webgl"] }); - const ctx = await browser.newContext({ viewport: { width: 1680, height: 900 } }); - const page = await ctx.newPage(); - const errs = []; - page.on("console", (m) => { if (m.type() === "error") errs.push(m.text().slice(0, 200)); }); - page.on("pageerror", (e) => errs.push("PE:" + e.message.slice(0, 200))); - - await page.goto(BASE + "/frontend/index.html", { waitUntil: "networkidle", timeout: 30000 }).catch((e) => errs.push("goto:" + e.message)); - await page.waitForTimeout(2500); // let the ambient prime the strip - await page.screenshot({ path: shot("intro-clean-1.png") }); - - // sample the scroll state to prove the world is FLOWING + the gap-filler is feeding it - const s1 = await page.evaluate(() => { - const c = window.LL && window.LL.controller; - const sc = window.LL && window.LL.scroll; - return { - hasController: !!c, hasScroll: !!(sc && sc.ready), - pendingAhead: sc ? Math.round(sc.pendingAhead) : null, - introVisible: !document.getElementById("intro").classList.contains("is-gone"), - titleGone: !document.querySelector(".intro__title"), - }; - }).catch((e) => ({ err: String(e).slice(0, 160) })); - - const d1 = await page.evaluate(() => window.LL.scroll.debug).catch(() => ({})); - await page.waitForTimeout(4500); // let it scroll ~0.5s*9 -> content should advance - await page.screenshot({ path: shot("intro-clean-2.png") }); - const s2 = await page.evaluate(() => { - const sc = window.LL && window.LL.scroll; - return { pendingAhead: sc ? Math.round(sc.pendingAhead) : null }; - }).catch(() => ({})); - const d2 = await page.evaluate(() => window.LL.scroll.debug).catch(() => ({})); - // sample the strip canvas at the window centre: fill (~11,13,18) => not painted there; - // colourful => canvas painted but the texture isn't reaching the shader. - const px2 = await page.evaluate(() => { - const sc = window.LL.scroll, d = sc.debug; - return { center: sc.pixelAt(d.scrollX + d.viewPx / 2), left: sc.pixelAt(d.scrollX + 20), right: sc.pixelAt(d.scrollX + d.viewPx - 20) }; - }).catch((e) => ({ err: String(e).slice(0, 120) })); - - console.log("STATE1", JSON.stringify(s1)); - console.log("DEBUG1", JSON.stringify(d1)); - console.log("STATE2", JSON.stringify(s2)); - console.log("DEBUG2", JSON.stringify(d2)); - console.log("PIXELS2", JSON.stringify(px2)); - const scan = await page.evaluate(() => { - const sc = window.LL.scroll; - const xs = [100, 400, 700, 760, 820, 900, 1100, 1400, 1800, 2400, 2500]; - return xs.map((x) => [x, sc.pixelAt(x)]); - }).catch((e) => ({ err: String(e).slice(0, 120) })); - console.log("SCAN", JSON.stringify(scan)); - console.log("JS_ERRORS", JSON.stringify(errs)); - await browser.close(); -})(); diff --git a/scripts/shoot-live-phrases.cjs b/scripts/shoot-live-phrases.cjs deleted file mode 100644 index 90f5534b02b365062ef231840d3e24bd64905c62..0000000000000000000000000000000000000000 --- a/scripts/shoot-live-phrases.cjs +++ /dev/null @@ -1,72 +0,0 @@ -// Phase A — backend per-phrase continuity for the LIVE narration endpoint. -// Opens the real (private) Space in a browser, then uses the SAME @gradio/client the -// app uses to submit /scroll_live three times with DIFFERENT text phrases but ONE -// session. Asserts the section indices grow monotonically across the three calls — -// i.e. the server kept the panorama context (_LIVE_SESS) across separate GPU calls, -// so each spoken phrase CONTINUES the world instead of restarting it. -// Usage: PANO_TOKEN=hf_xxx node scripts/shoot-live-phrases.cjs -const { chromium } = require("playwright"); - -const SPACE = process.env.SPACE_URL || "https://efradeca-lightloom-dev.hf.space"; -const TOKEN = process.env.PANO_TOKEN || ""; - -(async () => { - if (!TOKEN) { console.error("PANO_TOKEN env required"); process.exit(2); } - const browser = await chromium.launch(); - const ctx = await browser.newContext(); - await ctx.route("**/*", (route) => { - const url = route.request().url(); - if (url.startsWith(SPACE)) { - return route.continue({ headers: { ...route.request().headers(), authorization: "Bearer " + TOKEN } }); - } - return route.continue(); - }); - const page = await ctx.newPage(); - const errs = []; - page.on("pageerror", (e) => errs.push("PE:" + e.message.slice(0, 200))); - await page.goto(SPACE + "/", { waitUntil: "networkidle", timeout: 30000 }).catch((e) => errs.push("goto:" + e.message)); - await page.waitForTimeout(1500); - - const phrases = [ - "A glowing forest came alive with drifting fireflies.", - "A crystal river wound between the ancient trees.", - "A village of lantern-lit treehouses appeared in the canopy.", - ]; - - const result = await page.evaluate(async ({ phrases }) => { - const session = "feed0001"; - const client = await window.LL.api.connect(); - const out = []; - for (const text of phrases) { - const ev = { phrase: text, transcript: null, scene: null, sections: [], depths: [], stages: [], error: null }; - try { - const job = client.submit("/scroll_live", { session, text, audio_b64: "", lang: "en" }); - for await (const msg of job) { - if (!msg || msg.type !== "data") continue; - const d = Array.isArray(msg.data) ? msg.data[0] : msg.data; - if (!d || typeof d !== "object") continue; - ev.stages.push(d.stage); - if (d.stage === "transcript") ev.transcript = d.text; - if (d.stage === "painting") ev.scene = d.scene; - if (d.stage === "section") ev.sections.push(d.index); - if (d.stage === "depth") ev.depths.push(d.index); - if (d.stage === "error" || d.stage === "quota_exceeded") ev.error = d.error || d.stage; - } - } catch (e) { ev.error = String(e).slice(0, 160); } - out.push(ev); - } - return out; - }, { phrases }).catch((e) => ({ err: String(e).slice(0, 200) })); - - console.log("RESULT", JSON.stringify(result, null, 2)); - console.log("JS_ERRORS", JSON.stringify(errs)); - - // continuity assertion - if (Array.isArray(result)) { - const allSections = result.flatMap((r) => r.sections); - const monotonic = allSections.every((v, i) => i === 0 || v === allSections[i - 1] + 1); - const contiguousStart = allSections.length > 0 && allSections[0] === 0; - console.log("CONTINUITY", JSON.stringify({ allSections, monotonic, contiguousStart, count: allSections.length })); - } - await browser.close(); -})(); diff --git a/scripts/shoot-live.cjs b/scripts/shoot-live.cjs deleted file mode 100644 index 3f7821b001467e979826a8c1bf637a18c65faeb0..0000000000000000000000000000000000000000 --- a/scripts/shoot-live.cjs +++ /dev/null @@ -1,65 +0,0 @@ -// Live end-to-end: drive the REAL deployed (private) Space — the immersive -// corridor — in a real browser via @gradio/client. Loads with an HF Bearer header -// (Space-origin only, so the @gradio/client CDN isn't CORS-poisoned), starts a -// world (text), waits for scenes to stream into the corridor, and screenshots it. -// Usage: PANO_TOKEN=hf_xxx [MODE=world|showcase] node scripts/shoot-live.cjs -const { chromium } = require("playwright"); -const path = require("path"); -const fs = require("fs"); - -const SPACE = process.env.SPACE_URL || "https://efradeca-lightloom-dev.hf.space"; -const TOKEN = process.env.PANO_TOKEN || ""; -const MODE = process.env.MODE || "world"; - -(async () => { - if (!TOKEN) { console.error("PANO_TOKEN env required"); process.exit(2); } - const SHOTS = path.join(process.cwd(), ".shots"); - fs.mkdirSync(SHOTS, { recursive: true }); - const shot = (n) => path.join(SHOTS, n); - const browser = await chromium.launch({ args: ["--use-gl=angle", "--use-angle=swiftshader", "--ignore-gpu-blocklist", "--enable-webgl"] }); - const ctx = await browser.newContext({ viewport: { width: 1680, height: 900 } }); - await ctx.route("**/*", (route) => { - const url = route.request().url(); - if (url.startsWith(SPACE)) { - const headers = { ...route.request().headers(), authorization: "Bearer " + TOKEN }; - return route.continue({ headers }); - } - return route.continue(); - }); - const page = await ctx.newPage(); - const errs = []; - page.on("console", (m) => { if (m.type() === "error") errs.push(m.text().slice(0, 200)); }); - page.on("pageerror", (e) => errs.push("PE:" + e.message.slice(0, 200))); - - await page.goto(SPACE + "/", { waitUntil: "networkidle", timeout: 30000 }).catch((e) => errs.push("goto:" + e.message)); - await page.waitForTimeout(1800); - await page.screenshot({ path: shot("live-intro.png") }); - - const started = await page.evaluate((mode) => { - const LL = window.LL; - if (!LL || !LL.controller) return { ok: false, why: "no controller" }; - if (mode === "showcase") { LL.controller.playShowcase(); return { ok: true, mode }; } - LL.controller.startWorld("A glowing forest came alive with drifting fireflies. A crystal river wound between the ancient trees. A village of lantern-lit treehouses appeared. A great waterfall of light poured into a glowing canyon. A temple floated among luminous clouds."); - return { ok: true, mode }; - }, MODE).catch((e) => ({ ok: false, why: String(e).slice(0, 160) })); - - // Wait up to ~120s for the first scene (cold start loads models ~30s). - let scenes = 0; - for (let i = 0; i < 70; i++) { - const c = await page.evaluate(() => (window.LL.scroll && window.LL.controller._count) || 0).catch(() => 0); - if (c > scenes) { scenes = c; } - if (scenes >= 1 && i > 4) { - await page.screenshot({ path: shot("live-world-" + Math.min(scenes, 4) + ".png") }); - } - if (scenes >= 3) break; - await page.waitForTimeout(2500); - } - await page.waitForTimeout(2500); - await page.screenshot({ path: shot("live-world-final.png") }); - - const final = await page.evaluate(() => ({ count: window.LL.scroll && window.LL.controller._count, inWorld: document.body.classList.contains("in-world") })); - console.log("STARTED:", JSON.stringify(started), "SCENES_SEEN:", scenes); - console.log("FINAL:", JSON.stringify(final)); - console.log("JS_ERRORS:", JSON.stringify(errs.slice(0, 12))); - await browser.close(); -})().catch((e) => { console.error("HARNESS ERROR:", e.message); process.exit(1); }); diff --git a/scripts/shoot-mic-live.cjs b/scripts/shoot-mic-live.cjs deleted file mode 100644 index 5430bc45abd088a978372f18312cb9bb84a6f353..0000000000000000000000000000000000000000 --- a/scripts/shoot-mic-live.cjs +++ /dev/null @@ -1,115 +0,0 @@ -// Phase B — the REAL live-narration experience, end to end. Chromium is fed a TTS -// narration WAV as a fake microphone; we tap the mic and let it "speak". This exercises -// the whole stack: Web-Audio VAD phrase-cutting -> /scroll_live (Whisper + Director + -// klein paint) -> sections appended to the SAME continuous scroll, building as you talk. -// Asserts: phrases get transcribed, sections keep appending (continuity), the world -// FILLS + FLOWS (debug pixel scan), and there are no JS errors. -// Usage: PANO_TOKEN=hf_xxx WAV=.shots\narration.wav node scripts/shoot-mic-live.cjs -const { chromium } = require("playwright"); -const path = require("path"); -const fs = require("fs"); - -const SPACE = process.env.SPACE_URL || "https://efradeca-lightloom-dev.hf.space"; -const TOKEN = process.env.PANO_TOKEN || ""; -const WAV = path.resolve(process.env.WAV || ".shots/narration.wav"); - -(async () => { - if (!TOKEN) { console.error("PANO_TOKEN env required"); process.exit(2); } - if (!fs.existsSync(WAV)) { console.error("WAV not found: " + WAV); process.exit(2); } - const SHOTS = path.join(process.cwd(), ".shots"); - const shot = (n) => path.join(SHOTS, n); - const browser = await chromium.launch({ - args: [ - "--use-fake-device-for-media-stream", - "--use-file-for-fake-audio-capture=" + WAV, // looped by default -> sustained narration - "--use-fake-ui-for-media-stream", - "--autoplay-policy=no-user-gesture-required", - "--use-gl=angle", "--use-angle=swiftshader", "--ignore-gpu-blocklist", "--enable-webgl", - ], - }); - const ctx = await browser.newContext({ viewport: { width: 1680, height: 900 }, permissions: ["microphone"] }); - await ctx.grantPermissions(["microphone"], { origin: SPACE }); - await ctx.route("**/*", (route) => { - const url = route.request().url(); - if (url.startsWith(SPACE)) return route.continue({ headers: { ...route.request().headers(), authorization: "Bearer " + TOKEN } }); - return route.continue(); - }); - const page = await ctx.newPage(); - const errs = []; - page.on("console", (m) => { if (m.type() === "error") errs.push(m.text().slice(0, 200)); }); - page.on("pageerror", (e) => errs.push("PE:" + e.message.slice(0, 200))); - - await page.goto(SPACE + "/", { waitUntil: "networkidle", timeout: 30000 }).catch((e) => errs.push("goto:" + e.message)); - await page.waitForTimeout(1500); - - // instrument the live event stream so we can see transcripts + sections as they arrive - await page.evaluate(() => { - window.__ev = []; - const c = window.LL.controller; - const orig = c._onEvent.bind(c); - c._onEvent = (ev) => { try { window.__ev.push({ s: ev.stage, i: ev.index, t: ev.text, sc: ev.scene, img: ev.image, session: ev.session, at: performance.now() }); } catch (_) {} return orig(ev); }; - }); - - // tap the mic — start live narration - await page.click("#mic-btn").catch((e) => errs.push("click:" + e.message)); - await page.evaluate(() => { window.__t0 = performance.now(); }); - - let lastCount = 0; - for (let i = 0; i < 60; i++) { // ~120s: cold warm (~30s) + the whole 39s audio + paints - await page.waitForTimeout(2000); - const st = await page.evaluate(() => { - const c = window.LL.controller, sc = window.LL.scroll; - const evs = window.__ev || []; - return { - count: c._count || 0, - transcripts: evs.filter((e) => e.s === "transcript").map((e) => e.t), - sections: evs.filter((e) => e.s === "section").map((e) => e.i), - pendingAhead: sc ? Math.round(sc.pendingAhead) : null, - dbg: sc ? sc.debug : null, - }; - }).catch(() => ({})); - if ((st.count || 0) > lastCount) { - lastCount = st.count; - await page.screenshot({ path: shot("mic-live-" + Math.min(lastCount, 9) + ".png") }); - } - if (i % 4 === 0) console.log("t=" + (i * 2 + 1) + "s", JSON.stringify({ count: st.count, sections: (st.sections||[]).length, pendingAhead: st.pendingAhead })); - if (lastCount >= (parseInt(process.env.TARGET || "15", 10))) break; - } - - // stop narration - await page.click("#mic-btn").catch(() => {}); - await page.waitForTimeout(1500); - await page.screenshot({ path: shot("mic-live-final.png") }); - - // final canvas paint check at the window centre (fill ~[11,13,18] => void; colourful => painted) - const probe = await page.evaluate(() => { - const sc = window.LL.scroll, d = sc.debug; - const xs = [d.scrollX + 40, d.scrollX + d.viewPx / 2, d.scrollX + d.viewPx - 40]; - return { dbg: d, px: xs.map((x) => [Math.round(x), sc.pixelAt(x)]) }; - }).catch((e) => ({ err: String(e).slice(0, 160) })); - - const evs = await page.evaluate(() => window.__ev || []); - const transcripts = evs.filter((e) => e.s === "transcript").map((e) => e.t); - const sections = evs.filter((e) => e.s === "section").map((e) => e.i); - const session = (evs.find((e) => e.session) || {}).session || null; - const images = evs.filter((e) => e.s === "section" && e.img).map((e) => e.img); - console.log("TRANSCRIPTS", JSON.stringify(transcripts)); - console.log("SECTIONS", JSON.stringify(sections)); - console.log("SESSION", JSON.stringify(session)); - console.log("IMAGES", JSON.stringify(images)); - // timing: warm (tap -> first section) and the cadence between sections + transcripts - const timing = await page.evaluate(() => { - const t0 = window.__t0 || 0, evs = window.__ev || []; - const secs = evs.filter((e) => e.s === "section"); - const trs = evs.filter((e) => e.s === "transcript"); - const firstSec = secs.length ? Math.round(secs[0].at - t0) : null; - const firstTr = trs.length ? Math.round(trs[0].at - t0) : null; - const deltas = secs.slice(1).map((e, i) => Math.round(e.at - secs[i].at)); - const avg = deltas.length ? Math.round(deltas.reduce((a, b) => a + b, 0) / deltas.length) : null; - return { firstTranscript_ms: firstTr, firstSection_ms: firstSec, sectionCount: secs.length, avgSectionGap_ms: avg, gaps: deltas }; - }).catch(() => ({})); - console.log("TIMING", JSON.stringify(timing)); - console.log("PAINT_PROBE", JSON.stringify(probe)); - console.log("JS_ERRORS", JSON.stringify(errs)); - await browser.close(); -})(); diff --git a/scripts/shoot-motion.cjs b/scripts/shoot-motion.cjs deleted file mode 100644 index 5d3420ee6ab9bef90d1886ab72f775276f23ce74..0000000000000000000000000000000000000000 --- a/scripts/shoot-motion.cjs +++ /dev/null @@ -1,36 +0,0 @@ -// Prove the cinematic motion: load ONE scene and capture it at two moments ~4s -// apart so the lateral ken-burns glide + depth parallax + forward zoom are visible -// as a real difference. Usage: node scripts/shoot-motion.cjs -const { chromium } = require("playwright"); -const http = require("http"); -const fs = require("fs"); -const path = require("path"); -const ROOT = process.cwd(); -const PORT = 8807; -const CT = { ".html": "text/html", ".js": "application/javascript", ".webp": "image/webp", ".png": "image/png" }; -const HTML = ` - - -`; -const server = http.createServer((req, res) => { - let p = decodeURIComponent(req.url.split("?")[0]); - if (p === "/_m.html") { res.writeHead(200, { "content-type": "text/html" }); res.end(HTML); return; } - if (p.startsWith("/shots/")) p = "/.shots/" + p.slice(7); - fs.readFile(path.join(ROOT, p), (e, d) => { if (e) { res.writeHead(404); res.end("x"); } else { res.writeHead(200, { "content-type": CT[path.extname(p)] || "application/octet-stream" }); res.end(d); } }); -}); -(async () => { - await new Promise((r) => server.listen(PORT, r)); - const b = await chromium.launch({ args: ["--use-gl=angle", "--use-angle=swiftshader", "--ignore-gpu-blocklist"] }); - const pg = await b.newPage({ viewport: { width: 1280, height: 720 } }); - await pg.goto(`http://localhost:${PORT}/_m.html`, { waitUntil: "networkidle" }).catch(() => {}); - await pg.waitForTimeout(900); - await pg.screenshot({ path: path.join(ROOT, ".shots", "motion-a.png") }); - await pg.waitForTimeout(4200); - await pg.screenshot({ path: path.join(ROOT, ".shots", "motion-b.png") }); - console.log("motion frames captured"); - await b.close(); server.close(); -})().catch((e) => { console.error(e.message); process.exit(1); }); diff --git a/scripts/shoot-pano.cjs b/scripts/shoot-pano.cjs deleted file mode 100644 index abe5fbac3e48ff0b1f4328d332db1ea3c423c5d7..0000000000000000000000000000000000000000 --- a/scripts/shoot-pano.cjs +++ /dev/null @@ -1,58 +0,0 @@ -// Visual test for the immersive panorama renderer (stage-pano.js): drive LL.pano -// with a synthetic equirectangular panorama + depth and screenshot the sphere view. -const { chromium } = require("playwright"); -const http = require("http"); -const fs = require("fs"); -const path = require("path"); -const ROOT = process.cwd(); -const PORT = 8801; -const CT = { ".html": "text/html", ".js": "application/javascript", ".css": "text/css", ".woff2": "font/woff2", ".webp": "image/webp", ".png": "image/png" }; - -const TEST_HTML = ` - - - -`; - -const server = http.createServer((req, res) => { - let p = decodeURIComponent(req.url.split("?")[0]); - if (p === "/_panotest.html") { res.writeHead(200, { "content-type": "text/html" }); res.end(TEST_HTML); return; } - if (p.startsWith("/shots/")) p = "/.shots/" + p.slice(7); // serve the downloaded real panorama - const file = path.join(ROOT, p); - fs.readFile(file, (e, d) => { if (e) { res.writeHead(404); res.end("nf"); } else { res.writeHead(200, { "content-type": CT[path.extname(file)] || "application/octet-stream" }); res.end(d); } }); -}); - -(async () => { - const SHOTS = path.join(ROOT, ".shots"); fs.mkdirSync(SHOTS, { recursive: true }); - await new Promise((r) => server.listen(PORT, r)); - const browser = await chromium.launch({ args: ["--use-gl=angle", "--use-angle=swiftshader", "--ignore-gpu-blocklist"] }); - const page = await browser.newPage({ viewport: { width: 1340, height: 620 } }); - if (process.env.REAL) await page.addInitScript(() => { window.__panoUrl = "/shots/real-pano.webp"; window.__depthUrl = "/shots/real-depth.png"; }); - const errs = []; page.on("pageerror", (e) => errs.push(e.message.slice(0, 200))); - page.on("console", (m) => { if (m.type() === "error") errs.push(m.text().slice(0, 200)); }); - await page.goto(`http://localhost:${PORT}/_panotest.html`, { waitUntil: "networkidle", timeout: 25000 }).catch((e) => errs.push("goto:" + e.message)); - await page.waitForFunction(() => window.__ok || window.__err, { timeout: 12000 }).catch(() => {}); - await page.waitForTimeout(1500); - await page.screenshot({ path: path.join(SHOTS, "pano-1.png") }); - await page.waitForTimeout(2500); // let the camera drift to a new angle - await page.screenshot({ path: path.join(SHOTS, "pano-2.png") }); - const st = await page.evaluate(() => ({ ok: window.__ok, err: window.__err, ready: window.LL && window.LL.pano && window.LL.pano.ready })); - console.log("PANO:", JSON.stringify(st), "ERRS:", JSON.stringify(errs.slice(0, 8))); - await browser.close(); server.close(); -})().catch((e) => { console.error("ERR:", e.message); process.exit(1); }); diff --git a/scripts/shoot-scroll.cjs b/scripts/shoot-scroll.cjs deleted file mode 100644 index b208a51dbd90846bf6279a11cc31f767a1e2bfc5..0000000000000000000000000000000000000000 --- a/scripts/shoot-scroll.cjs +++ /dev/null @@ -1,45 +0,0 @@ -// Validate the scrolling depth-parallax renderer (stage-scroll.js): feed the test -// strip + its depth and capture frames as the window scrolls left, to confirm the -// continuous flow + 2.5D parallax. Usage: node scripts/shoot-scroll.cjs -const { chromium } = require("playwright"); -const http = require("http"); -const fs = require("fs"); -const path = require("path"); -const ROOT = process.cwd(); -const PORT = 8808; -const CT = { ".html": "text/html", ".js": "application/javascript", ".webp": "image/webp", ".png": "image/png" }; -const HTML = ` - - -`; -const server = http.createServer((req, res) => { - let p = decodeURIComponent(req.url.split("?")[0]); - if (p === "/_s.html") { res.writeHead(200, { "content-type": "text/html" }); res.end(HTML); return; } - if (p.startsWith("/shots/")) p = "/.shots/" + p.slice(7); - fs.readFile(path.join(ROOT, p), (e, d) => { if (e) { res.writeHead(404); res.end("x"); } else { res.writeHead(200, { "content-type": CT[path.extname(p)] || "application/octet-stream" }); res.end(d); } }); -}); -(async () => { - await new Promise((r) => server.listen(PORT, r)); - const b = await chromium.launch({ args: ["--use-gl=angle", "--use-angle=swiftshader", "--ignore-gpu-blocklist"] }); - const pg = await b.newPage({ viewport: { width: 1280, height: 540 } }); - const errs = []; pg.on("pageerror", (e) => errs.push(e.message.slice(0, 200))); - pg.on("console", (m) => { if (m.type() === "error") errs.push(m.text().slice(0, 160)); }); - await pg.goto(`http://localhost:${PORT}/_s.html`, { waitUntil: "networkidle" }).catch((e) => errs.push("goto:" + e.message)); - await pg.waitForTimeout(800); - for (const [i, ms] of [[0, 600], [1, 3000], [2, 3000], [3, 3000]]) { - await pg.waitForTimeout(ms); - await pg.screenshot({ path: path.join(ROOT, ".shots", "scroll-" + i + ".png") }); - } - const st = await pg.evaluate(() => ({ ready: window.LL.scroll.ready })); - console.log("SCROLL:", JSON.stringify(st), "ERRS:", JSON.stringify(errs.slice(0, 6))); - await b.close(); server.close(); -})().catch((e) => { console.error(e.message); process.exit(1); }); diff --git a/scripts/shoot-showcase.cjs b/scripts/shoot-showcase.cjs deleted file mode 100644 index 82849f2013c6fc344f40e8401333a085b9914e00..0000000000000000000000000000000000000000 --- a/scripts/shoot-showcase.cjs +++ /dev/null @@ -1,72 +0,0 @@ -// Validate the Showcase reel: load the real app, trigger the pre-rendered -// journey (btn-showcase -> controller.startShowcase), and screenshot several -// worlds as the reel cross-fades through them. Usage: node scripts/shoot-showcase.cjs -const { chromium } = require("playwright"); -const http = require("http"); -const fs = require("fs"); -const path = require("path"); - -const ROOT = process.cwd(); -const PORT = 8803; -const CT = { - ".html": "text/html", ".js": "application/javascript", ".mjs": "application/javascript", - ".css": "text/css", ".woff2": "font/woff2", ".webp": "image/webp", ".png": "image/png", - ".json": "application/json", ".svg": "image/svg+xml", -}; - -const server = http.createServer((req, res) => { - let p = decodeURIComponent(req.url.split("?")[0]); - if (p === "/") p = "/frontend/index.html"; - const file = path.join(ROOT, p); - fs.readFile(file, (err, data) => { - if (err) { res.writeHead(404); res.end("not found"); return; } - res.writeHead(200, { "content-type": CT[path.extname(file)] || "application/octet-stream" }); - res.end(data); - }); -}); - -(async () => { - const SHOTS = path.join(ROOT, ".shots"); - fs.mkdirSync(SHOTS, { recursive: true }); - const shot = (n) => path.join(SHOTS, n); - await new Promise((r) => server.listen(PORT, r)); - const browser = await chromium.launch({ - args: ["--use-gl=angle", "--use-angle=swiftshader", "--ignore-gpu-blocklist", "--enable-webgl"], - }); - const page = await browser.newPage({ viewport: { width: 1680, height: 820 } }); - const errs = []; - page.on("console", (m) => { if (m.type() === "error") errs.push(m.text().slice(0, 200)); }); - page.on("pageerror", (e) => errs.push("PAGEERROR: " + e.message.slice(0, 200))); - - await page.goto(`http://localhost:${PORT}/frontend/index.html`, { waitUntil: "networkidle", timeout: 25000 }).catch((e) => errs.push("goto:" + e.message)); - await page.waitForTimeout(1200); - - const started = await page.evaluate(() => { - const b = document.getElementById("btn-showcase"); - if (b) { b.click(); return { ok: true, clicked: true }; } - if (window.LL && window.LL.controller) { window.LL.controller.startShowcase(); return { ok: true, called: true }; } - return { ok: false }; - }).catch((e) => ({ ok: false, why: String(e).slice(0, 160) })); - - // Capture worlds across the reel (dwell ~7s/world). Resize once it's in #set. - await page.waitForTimeout(900); - await page.evaluate(() => window.dispatchEvent(new Event("resize"))); - const caps = [2500, 9000, 17000, 25000]; - let prev = 0; - for (let i = 0; i < caps.length; i++) { - await page.waitForTimeout(caps[i] - prev); prev = caps[i]; - await page.screenshot({ path: shot(`sc-reel-${i}.png`) }); - } - - const st = await page.evaluate(() => ({ - running: window.LL.controller.running, - playing: window.LL.controller._showcasePlaying, - activeScreen: [...document.querySelectorAll(".screen.is-active")].map((s) => s.id), - badge: !!document.getElementById("ll-showcase-badge"), - })); - console.log("STARTED:", JSON.stringify(started)); - console.log("STATE:", JSON.stringify(st)); - console.log("JS_ERRORS:", JSON.stringify(errs.slice(0, 12))); - await browser.close(); - server.close(); -})().catch((e) => { console.error("HARNESS ERROR:", e.message); process.exit(1); }); diff --git a/scripts/shoot-voice-live.cjs b/scripts/shoot-voice-live.cjs deleted file mode 100644 index 6940a2796918b91b641428d0f34040b10f4428c2..0000000000000000000000000000000000000000 --- a/scripts/shoot-voice-live.cjs +++ /dev/null @@ -1,65 +0,0 @@ -// Live VOICE end-to-end on the deployed Space: a fake mic plays a real speech WAV -// into the browser recorder, which encodes a 16 kHz WAV and sends it to the real -// /transcribe (Cohere); the transcript starts a real /world; scenes stream into -// the corridor. Proves mic -> ASR -> world on the live Space. -// Usage: PANO_TOKEN=hf_xxx node scripts/shoot-voice-live.cjs -const { chromium } = require("playwright"); -const path = require("path"); -const fs = require("fs"); - -const SPACE = process.env.SPACE_URL || "https://efradeca-lightloom-dev.hf.space"; -const TOKEN = process.env.PANO_TOKEN || ""; -const WAV = path.join(process.cwd(), ".shots", "test-voice.wav"); - -(async () => { - if (!TOKEN) { console.error("PANO_TOKEN required"); process.exit(2); } - if (!fs.existsSync(WAV)) { console.error("missing " + WAV); process.exit(2); } - const SHOTS = path.join(process.cwd(), ".shots"); - const shot = (n) => path.join(SHOTS, n); - const browser = await chromium.launch({ - args: [ - "--use-gl=angle", "--use-angle=swiftshader", "--ignore-gpu-blocklist", "--enable-webgl", - "--use-fake-device-for-media-stream", "--use-fake-ui-for-media-stream", - "--use-file-for-fake-audio-capture=" + WAV, - ], - }); - const ctx = await browser.newContext({ viewport: { width: 1680, height: 900 }, permissions: ["microphone"] }); - await ctx.route("**/*", (route) => { - const url = route.request().url(); - if (url.startsWith(SPACE)) return route.continue({ headers: { ...route.request().headers(), authorization: "Bearer " + TOKEN } }); - return route.continue(); - }); - const page = await ctx.newPage(); - const errs = []; - page.on("console", (m) => { if (m.type() === "error") errs.push(m.text().slice(0, 200)); }); - page.on("pageerror", (e) => errs.push("PE:" + e.message.slice(0, 200))); - - await page.goto(SPACE + "/", { waitUntil: "networkidle", timeout: 30000 }).catch((e) => errs.push("goto:" + e.message)); - await page.waitForTimeout(1500); - - // Capture the transcript the recorder produces. - await page.evaluate(() => { - const c = window.LL.controller; const orig = c.startWorld.bind(c); - window.__story = null; - c.startWorld = (t) => { window.__story = t; return orig(t); }; - }); - - await page.click("#mic-btn").catch((e) => errs.push("mic1:" + e.message)); - await page.waitForTimeout(8000); // record the fake speech - await page.click("#mic-btn").catch((e) => errs.push("mic2:" + e.message)); - - // Wait for transcript -> world. - let scenes = 0, story = null; - for (let i = 0; i < 70; i++) { - const r = await page.evaluate(() => ({ story: window.__story, count: (window.LL.corridor && window.LL.corridor.count) || 0 })).catch(() => ({})); - if (r.story && !story) { story = r.story; console.log("TRANSCRIPT:", JSON.stringify(story).slice(0, 200)); } - if ((r.count || 0) > scenes) scenes = r.count; - if (scenes >= 2) break; - await page.waitForTimeout(2500); - } - await page.waitForTimeout(2500); - await page.screenshot({ path: shot("voice-live.png") }); - console.log("STORY_SET:", !!story, "SCENES:", scenes); - console.log("JS_ERRORS:", JSON.stringify(errs.slice(0, 10))); - await browser.close(); -})().catch((e) => { console.error("ERR:", e.message); process.exit(1); }); diff --git a/scripts/shoot-voice.cjs b/scripts/shoot-voice.cjs deleted file mode 100644 index 8c4f7745e83f3c307bc4a8d01c539f1ca9ae619d..0000000000000000000000000000000000000000 --- a/scripts/shoot-voice.cjs +++ /dev/null @@ -1,96 +0,0 @@ -// Validate the voice wiring locally: fake mic -> LL.recorder captures + encodes a -// WAV -> (stubbed) LL.api.transcribe -> transcript fills the recital -> (stubbed) -// streamPanorama reveals the world. Proves the recorder graph + flow without the -// real ASR endpoint. Usage: node scripts/shoot-voice.cjs -const { chromium } = require("playwright"); -const http = require("http"); -const fs = require("fs"); -const path = require("path"); - -const ROOT = process.cwd(); -const PORT = 8804; -const CT = { - ".html": "text/html", ".js": "application/javascript", ".mjs": "application/javascript", - ".css": "text/css", ".woff2": "font/woff2", ".webp": "image/webp", ".png": "image/png", - ".json": "application/json", ".svg": "image/svg+xml", -}; - -const server = http.createServer((req, res) => { - let p = decodeURIComponent(req.url.split("?")[0]); - if (p === "/") p = "/frontend/index.html"; - if (p.startsWith("/shots/")) p = "/.shots/" + p.slice(7); - const file = path.join(ROOT, p); - fs.readFile(file, (err, data) => { - if (err) { res.writeHead(404); res.end("nf"); return; } - res.writeHead(200, { "content-type": CT[path.extname(file)] || "application/octet-stream" }); - res.end(data); - }); -}); - -(async () => { - await new Promise((r) => server.listen(PORT, r)); - const browser = await chromium.launch({ - args: [ - "--use-gl=angle", "--use-angle=swiftshader", "--ignore-gpu-blocklist", "--enable-webgl", - "--use-fake-device-for-media-stream", "--use-fake-ui-for-media-stream", - ], - }); - const ctx = await browser.newContext({ viewport: { width: 1680, height: 820 }, permissions: ["microphone"] }); - const page = await ctx.newPage(); - const errs = []; - page.on("console", (m) => { if (m.type() === "error") errs.push(m.text().slice(0, 200)); }); - page.on("pageerror", (e) => errs.push("PAGEERROR: " + e.message.slice(0, 200))); - - await page.goto(`http://localhost:${PORT}/frontend/index.html`, { waitUntil: "networkidle", timeout: 25000 }).catch((e) => errs.push("goto:" + e.message)); - await page.waitForTimeout(1000); - - // Stub the network bits: transcribe returns a known line; panorama reveals a real world. - await page.evaluate(() => { - const LL = window.LL; - const sleep = (ms) => new Promise((r) => setTimeout(r, ms)); - window.__transcribeCalled = false; - window.__wavBytes = 0; - LL.api.transcribe = async (b64) => { - window.__transcribeCalled = true; - window.__wavBytes = (b64 || "").length; - return { text: "An old lighthouse keeper counted the waves at the edge of the world.", error: null }; - }; - LL.api.streamPanorama = async (text, lang, onEvent) => { - window.__panoText = text; - onEvent({ stage: "warming" }); - await sleep(40); - onEvent({ stage: "painted", panorama: "/shots/real-pano.webp" }); - await sleep(60); - onEvent({ stage: "depth", depth: "/shots/real-depth.png" }); - onEvent({ stage: "done", session: "voice" }); - return { session: "voice", done: true, cancelled: false }; - }; - return { supported: LL.recorder && LL.recorder.supported }; - }); - - // Click Narrate (start recording) -> wait (capture fake audio) -> click again (stop). - const sup = await page.evaluate(() => window.LL.recorder && window.LL.recorder.supported); - await page.click("#btn-narrate").catch(() => {}); - await page.waitForTimeout(1500); - const recState = await page.evaluate(() => window.LL.recorder.state); - await page.click("#btn-narrate").catch(() => {}); - // Wait for transcribe -> recital -> world reveal. - await page.waitForFunction(() => window.LL.controller && window.LL.controller._worldShown, { timeout: 8000 }).catch(() => {}); - await page.evaluate(() => window.dispatchEvent(new Event("resize"))); - await page.waitForTimeout(1500); - await page.screenshot({ path: path.join(ROOT, ".shots", "voice-world.png") }); - - const st = await page.evaluate(() => ({ - supported: window.LL.recorder.supported, - transcribeCalled: window.__transcribeCalled, - wavLen: window.__wavBytes, - panoText: window.__panoText, - worldShown: window.LL.controller._worldShown, - activeScreen: [...document.querySelectorAll(".screen.is-active")].map((s) => s.id), - })); - console.log("SUPPORTED:", sup, "REC_STATE_WHILE_RECORDING:", recState); - console.log("RESULT:", JSON.stringify(st)); - console.log("JS_ERRORS:", JSON.stringify(errs.slice(0, 10))); - await browser.close(); - server.close(); -})().catch((e) => { console.error("HARNESS ERROR:", e.message); process.exit(1); }); diff --git a/scripts/shoot.cjs b/scripts/shoot.cjs deleted file mode 100644 index eda269ac74520a650ebe5c955786eda6f02d66f7..0000000000000000000000000000000000000000 --- a/scripts/shoot.cjs +++ /dev/null @@ -1,88 +0,0 @@ -// Visual-validation harness: serve the frontend locally + headless Chromium (WebGL -// via swiftshader) + screenshot the lobby and the 3D stage driven with a test -// image+depth. Lets Claude actually SEE the rendered UI. Usage: node scripts/shoot.cjs -const { chromium } = require("playwright"); -const http = require("http"); -const fs = require("fs"); -const path = require("path"); - -const ROOT = process.cwd(); -const PORT = 8799; -const CT = { - ".html": "text/html", ".js": "application/javascript", ".mjs": "application/javascript", - ".css": "text/css", ".woff2": "font/woff2", ".webp": "image/webp", ".png": "image/png", - ".json": "application/json", ".svg": "image/svg+xml", -}; - -const server = http.createServer((req, res) => { - let p = decodeURIComponent(req.url.split("?")[0]); - if (p === "/") p = "/frontend/index.html"; - const file = path.join(ROOT, p); - fs.readFile(file, (err, data) => { - if (err) { res.writeHead(404); res.end("not found"); return; } - res.writeHead(200, { "content-type": CT[path.extname(file)] || "application/octet-stream" }); - res.end(data); - }); -}); - -(async () => { - const SHOTS = path.join(ROOT, ".shots"); - fs.mkdirSync(SHOTS, { recursive: true }); - const shot = (n) => path.join(SHOTS, n); - await new Promise((r) => server.listen(PORT, r)); - const browser = await chromium.launch({ - args: ["--use-gl=angle", "--use-angle=swiftshader", "--ignore-gpu-blocklist", "--enable-webgl"], - }); - const page = await browser.newPage({ viewport: { width: 1680, height: 800 }, deviceScaleFactor: 1 }); - const errs = []; - page.on("console", (m) => { if (m.type() === "error") errs.push(m.text().slice(0, 200)); }); - page.on("pageerror", (e) => errs.push("PAGEERROR: " + e.message.slice(0, 200))); - - await page.goto(`http://localhost:${PORT}/frontend/index.html`, { waitUntil: "networkidle", timeout: 25000 }).catch((e) => errs.push("goto: " + e.message)); - await page.waitForTimeout(2000); - await page.screenshot({ path: shot("lobby.png") }); - - // Reveal the recital composer (so the lobby looks like a judge would see it). - await page.evaluate(() => { const b = document.getElementById("btn-recital"); if (b) b.click(); }).catch(() => {}); - await page.waitForTimeout(600); - await page.screenshot({ path: shot("lobby-recital.png") }); - - // Drive the 3D stage directly with a test color image + radial depth (data URLs), - // so we can SEE the renderer without the GPU backend. - const driven = await page.evaluate(async () => { - function makeImg(draw) { - const c = document.createElement("canvas"); c.width = 1024; c.height = 576; - const g = c.getContext("2d"); draw(g, c.width, c.height); return c.toDataURL("image/png"); - } - const img = makeImg((g, w, h) => { - const grad = g.createLinearGradient(0, 0, 0, h); - grad.addColorStop(0, "#e8a33d"); grad.addColorStop(0.5, "#c25a2a"); grad.addColorStop(1, "#1b2a3a"); - g.fillStyle = grad; g.fillRect(0, 0, w, h); - g.fillStyle = "#f5efe6"; g.beginPath(); g.arc(w * 0.5, h * 0.55, 90, 0, 7); g.fill(); // a "sun" - g.fillStyle = "#0a0a0c"; g.fillRect(w * 0.7, h * 0.4, 70, h * 0.6); // a "tower" - }); - const depth = makeImg((g, w, h) => { - const rad = g.createRadialGradient(w * 0.72, h * 0.5, 10, w * 0.72, h * 0.5, 400); - rad.addColorStop(0, "#ffffff"); rad.addColorStop(1, "#202020"); // tower=near(white), rest far - g.fillStyle = rad; g.fillRect(0, 0, w, h); - }); - document.querySelectorAll(".screen").forEach((s) => s.classList.remove("is-active")); - const set = document.getElementById("set"); if (set) set.classList.add("is-active"); - const canvas = document.getElementById("stage-canvas"); - if (!window.LL || !window.LL.stage) return { ok: false, why: "LL.stage missing", stageType: typeof (window.LL && window.LL.stage) }; - try { window.LL.stage.init(canvas); } catch (e) { return { ok: false, why: "init: " + e.message }; } - try { - await window.LL.stage.revealBeat({ imageUrl: img, depthUrl: depth, cameraMove: "dolly_in", transition: "crossfade", reducedMotion: false }); - } catch (e) { return { ok: false, why: "revealBeat: " + e.message }; } - const hasLL = Object.keys(window.LL || {}); - return { ok: true, hasLL }; - }).catch((e) => ({ ok: false, why: "evaluate: " + e.message })); - - await page.waitForTimeout(1200); - await page.screenshot({ path: shot("stage.png") }); - - console.log("DRIVEN:", JSON.stringify(driven)); - console.log("JS_ERRORS:", JSON.stringify(errs.slice(0, 12))); - await browser.close(); - server.close(); -})().catch((e) => { console.error("HARNESS ERROR:", e.message); process.exit(1); }); diff --git a/src/lightloom/depth/depth.py b/src/lightloom/depth/depth.py index 4bcb66f95b7335b98e1c833e62153ab5d69c3071..ec69c3cf020b89465e01fb7953068815aea8539d 100644 --- a/src/lightloom/depth/depth.py +++ b/src/lightloom/depth/depth.py @@ -14,10 +14,12 @@ import numpy as np from lightloom.core.config import MODEL_REFS -def normalize_depth(raw: np.ndarray, invert: bool = True) -> np.ndarray: - """Min-max normalize a raw depth map to [0,1]. With ``invert`` the result has - 1 = near, 0 = far (the convention the parallax shader expects). A flat map - returns zeros instead of dividing by zero.""" +def normalize_depth(raw: np.ndarray, invert: bool = False) -> np.ndarray: + """Min-max normalize a raw depth map to [0,1]. The parallax shader wants 1 = near, 0 = far. + Depth-Anything-V2 emits DISPARITY (near = HIGH value), so plain min-max ALREADY yields 1=near/0=far + -> the default is ``invert=False``. Pass ``invert=True`` ONLY for a TRUE-depth source (near = LOW). + Applying invert to a disparity map flips it inside-out (near reads as far) -> inverted parallax + + aerial on the wrong regions + disocclusion streaks. A flat map returns zeros (no divide-by-zero).""" raw = raw.astype("float32") lo = float(raw.min()) hi = float(raw.max()) @@ -44,11 +46,13 @@ def load_depth_pipeline(device: str = "cuda") -> Any: ) -def estimate_depth(depth_pipeline: Any, image: Any, invert: bool = True, normalize: bool = True) -> np.ndarray: - """Run depth estimation on a PIL image. With ``normalize`` (default) returns a per-image [0,1] - map (legacy). With ``normalize=False`` returns the RAW model disparity (un-scaled) so the caller - can apply ONE session-global scale across all strips — the only way adjacent strips share a depth - scale (per-strip min-max makes 'near' mean a different thing every section -> seams + flatness).""" +def estimate_depth(depth_pipeline: Any, image: Any, invert: bool = False, normalize: bool = True) -> np.ndarray: + """Run depth estimation on a PIL image. DA-V2 emits DISPARITY (near=HIGH); with ``normalize`` + (default) plain min-max yields 1=near/0=far (the shader convention) — so ``invert`` defaults to + False (do NOT flip a disparity map). With ``normalize=False`` returns the RAW model disparity + (un-scaled) so the caller can apply ONE session-global scale across all strips — the only way + adjacent strips share a depth scale (per-strip min-max makes 'near' mean a different thing every + section -> seams + flatness).""" out = depth_pipeline(image) predicted = out["predicted_depth"] array = predicted.detach().cpu().numpy() if hasattr(predicted, "detach") else np.asarray(predicted) diff --git a/src/lightloom/paint/scroll.py b/src/lightloom/paint/scroll.py index 0b1ca1904ca2cef8fc31b5f9e381070acc48c77d..96978311bb1c248988e6f85db1dbd2347d559dcc 100644 --- a/src/lightloom/paint/scroll.py +++ b/src/lightloom/paint/scroll.py @@ -4,8 +4,10 @@ Instead of discrete images, the world is ONE horizontal panorama that keeps extending to the right as the narration flows: each step OUTPAINTS the right edge, conditioned on an overlap strip carried over from the previous section, so the new content continues the old SEAMLESSLY. The browser scrolls left through the strip -with a depth parallax. Reuses the klein-base inpaint pipeline + the 360 ERP outpaint -LoRA (which is, precisely, a horizontal-outpainting model). +with a depth parallax. Uses the live painter — the DISTILLED FLUX.2-klein-4B inpaint +pipeline (4-step, CFG-free) — for a fast masked right-edge outpaint; no 360 LoRA is +loaded (see ``load_fast_pipeline``). The only adapter fused is the painterly STYLE +LoRA at warm-up, which is in the runtime ledger. """ from __future__ import annotations diff --git a/tests/test_audio.py b/tests/test_audio.py deleted file mode 100644 index d93c37b73dfde7df4b0376e22d05c21abd6da733..0000000000000000000000000000000000000000 --- a/tests/test_audio.py +++ /dev/null @@ -1,18 +0,0 @@ -"""Tests for the ambient ducking law (docs/02 §2.7).""" - -from __future__ import annotations - -from lightloom.sound.ambient import BED_DB, duck_gain_db - - -def test_bed_sits_at_minus_16_when_silent() -> None: - assert duck_gain_db(False) == BED_DB == -16.0 - - -def test_bed_ducks_6db_when_voice_active() -> None: - assert duck_gain_db(True) == -22.0 - - -def test_custom_levels() -> None: - assert duck_gain_db(True, bed_db=-12.0, duck_db=8.0) == -20.0 - assert duck_gain_db(False, bed_db=-12.0, duck_db=8.0) == -12.0 diff --git a/tests/test_beats.py b/tests/test_beats.py deleted file mode 100644 index b3a621cc25adf440a3fab9366ec7c2a976f2cf74..0000000000000000000000000000000000000000 --- a/tests/test_beats.py +++ /dev/null @@ -1,57 +0,0 @@ -"""Contract tests for VAD beat segmentation (docs/02 §2.1, docs/06 §2). - -Hysteresis: enter speech at p>0.6, leave at p<0.35 sustained >=0.6 s. A beat is -emitted only if its duration is in [1.2 s, 12 s]; longer speech is split at T_max. -""" - -from __future__ import annotations - -from lightloom.core.beats import WINDOW_S, segment_beats - - -def seg(prob: float, seconds: float, window_s: float = WINDOW_S) -> list[float]: - return [prob] * round(seconds / window_s) - - -def test_silence_gap_over_tau_splits_into_two_beats() -> None: - probs = seg(0.9, 2.0) + seg(0.0, 1.5) + seg(0.9, 2.0) - beats = segment_beats(probs) - assert len(beats) == 2 - for start, end in beats: - assert 1.8 <= (end - start) <= 2.2 - - -def test_short_silence_under_tau_keeps_single_beat() -> None: - # 0.3 s gap is below the 0.6 s silence threshold -> one continuous beat. - probs = seg(0.9, 2.0) + seg(0.0, 0.3) + seg(0.9, 2.0) - beats = segment_beats(probs) - assert len(beats) == 1 - start, end = beats[0] - assert (end - start) >= 4.0 - - -def test_sub_t_min_utterance_is_dropped() -> None: - probs = seg(0.9, 0.5) + seg(0.0, 1.0) - assert segment_beats(probs) == [] - - -def test_hysteresis_dip_above_theta_off_does_not_close() -> None: - # Dips to 0.4 (between theta_off=0.35 and theta_on=0.6) must not end the beat. - probs = seg(0.9, 1.0) + seg(0.4, 1.0) + seg(0.9, 1.0) + seg(0.0, 1.0) - beats = segment_beats(probs) - assert len(beats) == 1 - start, end = beats[0] - assert (end - start) >= 2.9 # ~3 s minus window quantization (0.03 s) - - -def test_long_speech_is_split_at_t_max() -> None: - probs = seg(0.9, 15.0) + seg(0.0, 1.0) - beats = segment_beats(probs) - assert len(beats) == 2 - assert beats[0][1] - beats[0][0] <= 12.0 + 1e-6 - assert beats[0][1] - beats[0][0] >= 11.5 - - -def test_low_prob_below_theta_on_never_starts() -> None: - probs = seg(0.5, 5.0) - assert segment_beats(probs) == [] diff --git a/tests/test_budget.py b/tests/test_budget.py deleted file mode 100644 index 7e36e08d8ec49d9bf0be6bf198f40f4d9d0e79ad..0000000000000000000000000000000000000000 --- a/tests/test_budget.py +++ /dev/null @@ -1,48 +0,0 @@ -"""Contract tests for the per-session GPU-second budget and quota guard. - -docs/01 §4, docs/04 §2: warn at 70 %, offer Replay/Export at exhaustion, and never -start a beat that cannot finish within the remaining budget. -""" - -from __future__ import annotations - -from lightloom.core.budget import GpuBudget - - -def test_fresh_budget_is_ok_and_full() -> None: - b = GpuBudget(total_s=90.0) - assert b.spent_s == 0.0 - assert b.remaining_s == 90.0 - assert b.status() == "ok" - assert b.can_start_beat(2.5) is True - - -def test_warn_threshold_at_70_percent() -> None: - b = GpuBudget(total_s=10.0) - b.add(6.9) - assert b.status() == "ok" - b.add(0.2) # 7.1 / 10 -> over 70 % - assert b.status() == "warn" - - -def test_exhaustion_blocks_new_beats() -> None: - b = GpuBudget(total_s=10.0) - b.add(10.0) - assert b.status() == "exhausted" - assert b.remaining_s == 0.0 - assert b.can_start_beat(0.1) is False - - -def test_remaining_never_negative_and_negatives_ignored() -> None: - b = GpuBudget(total_s=5.0) - b.add(8.0) - assert b.remaining_s == 0.0 - b.add(-3.0) # ignored, cannot refund - assert b.spent_s == 8.0 - - -def test_cannot_start_beat_that_would_overrun() -> None: - b = GpuBudget(total_s=10.0) - b.add(8.0) # 2 s left - assert b.can_start_beat(2.5) is False - assert b.can_start_beat(1.5) is True diff --git a/tests/test_compliance.py b/tests/test_compliance.py deleted file mode 100644 index 01014f2b17fd5b0093faff4e7794fdf78d6f2215..0000000000000000000000000000000000000000 --- a/tests/test_compliance.py +++ /dev/null @@ -1,53 +0,0 @@ -from __future__ import annotations - -from pathlib import Path -import re - -ROOT = Path(__file__).resolve().parents[1] -RUNTIME_DIRS = [ROOT / "src", ROOT / "frontend", ROOT / "app.py"] - -FORBIDDEN = [ - "api.openai.com", - "api.cohere", - "bfl.ai/api", - "InferenceClient", - "huggingface_hub.InferenceApi", -] - -TOKEN_RE = re.compile(r"hf_[A-Za-z0-9]{20,}") - - -def _runtime_files() -> list[Path]: - files: list[Path] = [] - for root in RUNTIME_DIRS: - if root.is_file(): - files.append(root) - elif root.exists(): - files.extend(path for path in root.rglob("*") if path.is_file()) - return files - - -def test_no_cloud_api_literals_in_runtime() -> None: - offenders: list[str] = [] - for path in _runtime_files(): - text = path.read_text(encoding="utf-8", errors="ignore") - for pattern in FORBIDDEN: - if pattern in text: - offenders.append(f"{path.relative_to(ROOT)}:{pattern}") - assert offenders == [] - - -def test_no_hf_tokens_in_repo_text_files() -> None: - offenders: list[str] = [] - for path in ROOT.rglob("*"): - if ".git" in path.parts or ".venv" in path.parts: - continue - if not path.is_file(): - continue - try: - text = path.read_text(encoding="utf-8") - except UnicodeDecodeError: - continue - if TOKEN_RE.search(text): - offenders.append(str(path.relative_to(ROOT))) - assert offenders == [] diff --git a/tests/test_depth.py b/tests/test_depth.py deleted file mode 100644 index 9349a75ed2756bcaf89fdc55f8a1535ba2f95bc1..0000000000000000000000000000000000000000 --- a/tests/test_depth.py +++ /dev/null @@ -1,31 +0,0 @@ -"""Tests for depth normalization (docs/02 §2.5). The map fed to the parallax -shader is in [0,1] with 1 = near; model loading/inference is GPU-only and untested -here.""" - -from __future__ import annotations - -import numpy as np - -from lightloom.depth.depth import normalize_depth - - -def test_normalizes_to_unit_range() -> None: - raw = np.array([[10.0, 20.0], [30.0, 40.0]], dtype="float32") - out = normalize_depth(raw, invert=False) - assert out.min() == 0.0 - assert out.max() == 1.0 - - -def test_invert_makes_one_equal_near() -> None: - raw = np.array([[0.0, 1.0]], dtype="float32") - out = normalize_depth(raw, invert=True) - # raw min -> 1.0 (near), raw max -> 0.0 (far) - assert out[0, 0] == 1.0 - assert out[0, 1] == 0.0 - - -def test_constant_map_does_not_divide_by_zero() -> None: - raw = np.full((3, 3), 0.5, dtype="float32") - out = normalize_depth(raw, invert=False) - assert np.all(out == 0.0) - assert out.shape == (3, 3) diff --git a/tests/test_director_parse.py b/tests/test_director_parse.py deleted file mode 100644 index 47797cb58f7b00aeaac2257a2ca81776d5640e56..0000000000000000000000000000000000000000 --- a/tests/test_director_parse.py +++ /dev/null @@ -1,68 +0,0 @@ -"""Tests for the tolerant Director parser (_coerce_shot) — CPU only, no model. - -These pin the salvage behavior that keeps the GPU Director's JSON-validity high -without a grammar (transformers 5.x is incompatible with lm-format-enforcer). -""" - -from __future__ import annotations - -import json - -from lightloom.director.director import _coerce_shot - -GOLD = { - "decision": "continuity", - "shot_scale": "MS", - "camera_move": "tilt_up", - "lighting": "stormy dusk", - "palette": ["#1B2A3A", "#C9A227", "#6E7B8B"], - "setting": "inside the lighthouse", - "characters": ["an old lighthouse keeper"], - "image_prompt_en": "a keeper climbs the stairs", - "ambient_prompt_en": "rain on glass, wind", - "transition": "crossfade", -} - - -def test_valid_passes_uncoerced() -> None: - shot, coerced = _coerce_shot(json.dumps(GOLD)) - assert not coerced - assert shot.transition == "crossfade" - - -def test_missing_transition_is_repaired_by_decision() -> None: - cut = {**GOLD, "decision": "cut"} - del cut["transition"] - shot, coerced = _coerce_shot(json.dumps(cut)) - assert coerced and shot.transition == "hard_cut" - - cont = dict(GOLD) - del cont["transition"] - shot2, _ = _coerce_shot(json.dumps(cont)) - assert shot2.transition == "crossfade" - - -def test_transition_as_list_takes_first_valid() -> None: - payload = {**GOLD, "transition": ["wipe_left", "hard_cut"]} - shot, coerced = _coerce_shot(json.dumps(payload)) - assert coerced and shot.transition == "wipe_left" - - -def test_overlong_ambient_is_clamped() -> None: - payload = {**GOLD, "ambient_prompt_en": "rain " * 60} - shot, coerced = _coerce_shot(json.dumps(payload)) - assert coerced and len(shot.ambient_prompt_en) <= 160 - - -def test_camera_synonym_is_mapped() -> None: - shot, coerced = _coerce_shot(json.dumps({**GOLD, "camera_move": "zoom_in"})) - assert coerced and shot.camera_move == "dolly_in" - - -def test_unknown_enums_fall_back_to_defaults() -> None: - payload = {**GOLD, "camera_move": "orbit", "shot_scale": "HUGE", "decision": "maybe"} - shot, coerced = _coerce_shot(json.dumps(payload)) - assert coerced - assert shot.camera_move == "static" - assert shot.shot_scale == "MS" - assert shot.decision == "continuity" diff --git a/tests/test_gate_g1.py b/tests/test_gate_g1.py deleted file mode 100644 index a0316a70c5cee01d848ffbd28f14e5f850953d4c..0000000000000000000000000000000000000000 --- a/tests/test_gate_g1.py +++ /dev/null @@ -1,21 +0,0 @@ -from __future__ import annotations - -import json -from pathlib import Path - -import benchmarks.gate_g1 as gate_g1 - - -def test_g1_dry_run_writes_non_authoritative_results(tmp_path, monkeypatch) -> None: - json_path = tmp_path / "g1.json" - md_path = tmp_path / "g1.md" - monkeypatch.setattr(gate_g1, "DEFAULT_JSON", json_path) - monkeypatch.setattr(gate_g1, "DEFAULT_MD", md_path) - data = gate_g1.run(dry_run=True, reps=2, allow_local=False) - assert data["authoritative"] is False - assert data["decision"]["status"] == "blocked" - assert json_path.exists() - assert md_path.exists() - saved = json.loads(Path(json_path).read_text(encoding="utf-8")) - assert saved["results"] - assert all(item["status"] == "dry_run" for item in saved["results"]) diff --git a/tests/test_gate_g2_g3.py b/tests/test_gate_g2_g3.py deleted file mode 100644 index 9d8d8402aaf76c1fbc42c0eb884bdf897b133704..0000000000000000000000000000000000000000 --- a/tests/test_gate_g2_g3.py +++ /dev/null @@ -1,19 +0,0 @@ -from __future__ import annotations - -import json - -import benchmarks.gate_g2_g3 as gate_g2_g3 - - -def test_g2_g3_dry_run_writes_temp_results(tmp_path, monkeypatch) -> None: - g2_path = tmp_path / "g2.json" - g3_path = tmp_path / "g3.json" - monkeypatch.setattr(gate_g2_g3, "G2_JSON", g2_path) - monkeypatch.setattr(gate_g2_g3, "G3_JSON", g3_path) - g2, g3 = gate_g2_g3.run(dry_run=True) - assert g2["authoritative"] is False - assert g3["authoritative"] is False - assert g2_path.exists() - assert g3_path.exists() - assert json.loads(g2_path.read_text(encoding="utf-8"))["decision"] == "dry_run" - assert json.loads(g3_path.read_text(encoding="utf-8"))["decision"] == "dry_run" diff --git a/tests/test_grammar.py b/tests/test_grammar.py deleted file mode 100644 index f631c5c4f9b7fb79e19bc340a81e2a1c10ab993a..0000000000000000000000000000000000000000 --- a/tests/test_grammar.py +++ /dev/null @@ -1,86 +0,0 @@ -from __future__ import annotations - -import json -from pathlib import Path -import re - -import pytest -from pydantic import ValidationError - -from lightloom.director.schema import ( - CAMERA_MOVES, - DECISIONS, - SHOT_FIELDS, - SHOT_SCALES, - TRANSITIONS, - Shot, -) - -ROOT = Path(__file__).resolve().parents[1] -GRAMMAR = ROOT / "src" / "lightloom" / "director" / "grammar.gbnf" - -GOLDEN_SHOT = { - "decision": "continuity", - "shot_scale": "MS", - "camera_move": "tilt_up", - "lighting": "stormy dusk", - "palette": ["#1B2A3A", "#C9A227", "#6E7B8B"], - "setting": "inside the lighthouse spiral staircase", - "characters": ["an old lighthouse keeper, white beard, yellow raincoat"], - "image_prompt_en": ( - "An old lighthouse keeper in a yellow raincoat climbs a worn spiral staircase, " - "lantern light flickering on stone walls, rain streaking a small window" - ), - "ambient_prompt_en": "rain on glass, wind gusts, creaking wooden steps", - "transition": "crossfade", -} - - -def _grammar_text() -> str: - return GRAMMAR.read_text(encoding="utf-8") - - -def _grammar_fields() -> tuple[str, ...]: - return tuple(re.findall(r'\\"([a-z_]+)\\""\s+ws\s+":"', _grammar_text())) - - -def test_schema_sync() -> None: - text = _grammar_text() - assert _grammar_fields() == SHOT_FIELDS - for value in DECISIONS + SHOT_SCALES + CAMERA_MOVES + TRANSITIONS: - assert f'"\\"{value}\\""' in text - - -def test_llama_cpp_loads_grammar() -> None: - from llama_cpp import LlamaGrammar - - grammar = LlamaGrammar.from_file(GRAMMAR, verbose=False) - assert grammar is not None - - -def test_golden_shot_validates() -> None: - shot = Shot.model_validate_json(json.dumps(GOLDEN_SHOT)) - assert shot.decision == "continuity" - assert shot.palette == ("#1B2A3A", "#C9A227", "#6E7B8B") - - -@pytest.mark.parametrize( - ("field", "value"), - [ - ("decision", "zoom"), - ("shot_scale", "MEDIUM"), - ("camera_move", "orbit"), - ("transition", "fade_to_black"), - ("palette", ["#123456", "#ABCDEF"]), - ("palette", ["123456", "#ABCDEF", "#000000"]), - ("lighting", ""), - ("setting", ""), - ("image_prompt_en", ""), - ("ambient_prompt_en", ""), - ], -) -def test_malformed_shots_rejected(field: str, value) -> None: - payload = dict(GOLDEN_SHOT) - payload[field] = value - with pytest.raises((ValidationError, ValueError)): - Shot.model_validate(payload) diff --git a/tests/test_klein_policy.py b/tests/test_klein_policy.py deleted file mode 100644 index dbf70595c39cbdbca6a9f5999840e199ea86073e..0000000000000000000000000000000000000000 --- a/tests/test_klein_policy.py +++ /dev/null @@ -1,29 +0,0 @@ -"""Reference-policy tests for the continuity engine (docs/02 §2.3). - -This is the project's #1 differentiator (O2) and part of the MUST-set, so the -policy logic is pinned by tests. GPU rendering is not exercised here. -""" - -from __future__ import annotations - -from lightloom.paint.klein import select_references - -ANCHOR = "assets/anchors/style.webp" -PREV = "frames/beat_4.webp" - - -def test_continuity_uses_prev_then_anchor() -> None: - assert select_references("continuity", PREV, ANCHOR) == [PREV, ANCHOR] - - -def test_cut_drops_prev_keeps_anchor() -> None: - assert select_references("cut", PREV, ANCHOR) == [ANCHOR] - - -def test_continuity_first_beat_has_no_prev() -> None: - assert select_references("continuity", None, ANCHOR) == [ANCHOR] - - -def test_no_anchor_still_works() -> None: - assert select_references("continuity", PREV, None) == [PREV] - assert select_references("cut", PREV, None) == [] diff --git a/tests/test_ledger.py b/tests/test_ledger.py deleted file mode 100644 index 4e451c721cd1eda4644b2a9ad4f79a2a8a63dbde..0000000000000000000000000000000000000000 --- a/tests/test_ledger.py +++ /dev/null @@ -1,19 +0,0 @@ -from lightloom.compliance.params_ledger import PARAMETER_LIMIT, runtime_entries, total_runtime_params -from lightloom.core.config import CONFIG - - -def test_runtime_params_under_32b() -> None: - assert total_runtime_params() <= PARAMETER_LIMIT - - -def test_runtime_entries_are_positive_and_licensed() -> None: - for entry in runtime_entries(): - assert entry.params > 0 - assert entry.license - - -def test_local_profile_is_5070_safe() -> None: - if CONFIG.profile == "local": - assert CONFIG.flux_dtype == "fp8" - assert (CONFIG.width, CONFIG.height) == (768, 432) - assert CONFIG.flux_aot is False diff --git a/tests/test_pipeline.py b/tests/test_pipeline.py deleted file mode 100644 index 4c20448dad01f2f72d4b45259e09d3359a05ff4e..0000000000000000000000000000000000000000 --- a/tests/test_pipeline.py +++ /dev/null @@ -1,59 +0,0 @@ -"""Tests for beat planning (state threading, per-scene seed, reference policy).""" - -from __future__ import annotations - -from lightloom.core.pipeline import plan_shot, refined_transition -from lightloom.director.schema import Shot -from lightloom.director.state import initial_state - -ANCHOR = "assets/anchors/style.webp" -PREV = "frames/beat_3.webp" - - -def make_shot(decision: str) -> Shot: - return Shot( - decision=decision, - shot_scale="MS", - camera_move="static", - lighting="noon sun", - palette=("#101010", "#202020", "#303030"), - setting="a place", - characters=["a keeper"], - image_prompt_en="a keeper looks out to sea", - ambient_prompt_en="soft wind", - transition="crossfade" if decision == "continuity" else "hard_cut", - ) - - -def test_continuity_plan_uses_prev_and_conserves_palette() -> None: - state = initial_state() - plan = plan_shot(state, make_shot("continuity"), prev_frame=PREV, anchor=ANCHOR) - assert plan.references == [PREV, ANCHOR] - assert plan.new_state.palette == state.palette # conserved - assert plan.seed == 1901 + state.scene_id # same scene - assert "lghtlm style" not in plan.prompt # LoRA off - - -def test_cut_changes_seed_and_drops_prev() -> None: - state = initial_state() - cont = plan_shot(state, make_shot("continuity"), prev_frame=PREV, anchor=ANCHOR) - cut = plan_shot(state, make_shot("cut"), prev_frame=PREV, anchor=ANCHOR) - assert cut.references == [ANCHOR] - assert cut.seed != cont.seed # new scene -> new seed - assert cut.new_state.scene_id == state.scene_id + 1 - - -def test_lora_trigger_when_loaded() -> None: - plan = plan_shot(initial_state(), make_shot("continuity"), anchor=ANCHOR, lora_loaded=True) - assert plan.prompt.startswith("lghtlm style") - - -def test_continuity_hard_cut_is_softened_to_crossfade() -> None: - assert refined_transition("continuity", "hard_cut") == "crossfade" - assert refined_transition("continuity", "iris") == "iris" # respected - assert refined_transition("cut", "hard_cut") == "hard_cut" # cuts keep hard_cut - - -def test_plan_exposes_refined_transition() -> None: - plan = plan_shot(initial_state(), make_shot("continuity")) # make_shot uses hard_cut for... - assert plan.transition in {"crossfade", "hard_cut", "wipe_left", "iris"} diff --git a/tests/test_prompt_compose.py b/tests/test_prompt_compose.py deleted file mode 100644 index 0579ef0757d244a87b7d079d3615977c94d55eb0..0000000000000000000000000000000000000000 --- a/tests/test_prompt_compose.py +++ /dev/null @@ -1,75 +0,0 @@ -"""Contract tests for image-prompt composition (docs/03 §C, docs/06 §2). - -The template never duplicates style words, never emits the LoRA trigger when the -LoRA is off, and stays within the length budget. -""" - -from __future__ import annotations - -from lightloom.director.schema import Shot -from lightloom.paint.prompt import ( - LORA_TRIGGER, - MAX_PROMPT_CHARS, - compose_image_prompt, - sanitize_image_prompt, -) - - -def make_shot(image_prompt_en: str, shot_scale: str = "MS") -> Shot: - return Shot( - decision="continuity", - shot_scale=shot_scale, - camera_move="static", - lighting="stormy dusk", - palette=("#1B2A3A", "#C9A227", "#6E7B8B"), - setting="a lighthouse", - characters=["a keeper"], - image_prompt_en=image_prompt_en, - ambient_prompt_en="soft wind", - transition="crossfade", - ) - - -def test_trigger_present_only_when_lora_loaded() -> None: - shot = make_shot("a keeper climbs a staircase") - assert LORA_TRIGGER not in compose_image_prompt(shot, lora_loaded=False) - assert compose_image_prompt(shot, lora_loaded=True).startswith(LORA_TRIGGER) - - -def test_no_duplicated_style_words() -> None: - # Director leaked a style word it was told to avoid; the composer must not add a second. - shot = make_shot("a painterly cinematic film still of a keeper on the stairs") - prompt = compose_image_prompt(shot).lower() - assert prompt.count("cinematic illustrated film still") <= 1 - assert prompt.count("painterly texture") <= 1 - assert prompt.count("volumetric light") <= 1 - - -def test_includes_scale_phrase_and_palette() -> None: - shot = make_shot("a keeper on the stairs", shot_scale="EWS") - prompt = compose_image_prompt(shot) - assert "extreme wide establishing shot" in prompt - assert "#1B2A3A" in prompt and "#C9A227" in prompt and "#6E7B8B" in prompt - assert "2.39:1 frame" in prompt - - -def test_sanitizer_strips_non_visual_leakage() -> None: - out = sanitize_image_prompt("an old keeper on the stairs, distant echoes and silence, lantern glow") - assert "echoes" not in out and "silence" not in out - assert "keeper" in out and "lantern" in out - assert ",," not in out and " ," not in out - - -def test_compose_drops_leaked_sound_words() -> None: - shot = make_shot("a market wakes, distant chatter and murmurs, orange awnings") - prompt = compose_image_prompt(shot) - assert "chatter" not in prompt and "murmurs" not in prompt - assert "awnings" in prompt - - -def test_length_within_budget() -> None: - body = ("a keeper climbs the worn spiral staircase " * 10)[:420] # schema max - shot = make_shot(body) - assert len(compose_image_prompt(shot)) <= MAX_PROMPT_CHARS - # a tight explicit budget exercises the truncation path - assert len(compose_image_prompt(shot, max_chars=120)) <= 120 diff --git a/tests/test_recital.py b/tests/test_recital.py deleted file mode 100644 index 2ea4eeb0fa68459230b789fc8d1415bf9c89af53..0000000000000000000000000000000000000000 --- a/tests/test_recital.py +++ /dev/null @@ -1,39 +0,0 @@ -"""Tests for Recital segmentation (docs/04 F-B).""" - -from __future__ import annotations - -from lightloom.core.recital import split_recital - -POEM = """Había una vez un faro al borde del mundo, -y un viejo que contaba las olas. - -Cada noche subía la escalera en espiral, -contando cada peldaño como una oración. - -Pero lejos de allí, un mercado despertaba.""" - - -def test_stanzas_become_beats() -> None: - beats = split_recital(POEM) - assert len(beats) == 3 - assert beats[0].startswith("Había una vez") - assert "\n" in beats[0] # internal line breaks are preserved - - -def test_extra_blank_lines_do_not_make_empty_beats() -> None: - beats = split_recital("uno\n\n\n\ndos\n\n\n") - assert beats == ["uno", "dos"] - - -def test_single_prose_block_splits_by_sentence() -> None: - beats = split_recital("Había una vez. El faro brillaba. Llegó el alba.") - assert beats == ["Había una vez.", "El faro brillaba.", "Llegó el alba."] - - -def test_empty_text_yields_no_beats() -> None: - assert split_recital(" \n \n") == [] - - -def test_max_beats_caps_session() -> None: - many = "\n\n".join(f"beat {i}" for i in range(40)) - assert len(split_recital(many, max_beats=12)) == 12 diff --git a/tests/test_session.py b/tests/test_session.py deleted file mode 100644 index ae9000d6d2fe762c670dfe9edc1f8c6435cc8220..0000000000000000000000000000000000000000 --- a/tests/test_session.py +++ /dev/null @@ -1,31 +0,0 @@ -"""Privacy contract for published traces: Film.to_traces() drops user audio.""" - -from __future__ import annotations - -from lightloom.core.session import Beat, Film, Frame - - -def make_film() -> Film: - return Film( - session_id="s1", - lang="es", - beats=[Beat(id=1, t_start=0.0, t_end=2.0, audio_path="/tmp/u/beat1.wav", text_raw="hola")], - frames=[Frame(beat_id=1, image_path="/tmp/f1.webp", seed=1901)], - narration_audio_path="/tmp/u/narration.wav", - ) - - -def test_traces_strip_user_audio() -> None: - traces = make_film().to_traces() - assert traces["narration_audio_path"] is None - assert all(beat["audio_path"] is None for beat in traces["beats"]) - # our generated direction survives - assert traces["beats"][0]["text_raw"] == "hola" - assert traces["frames"][0]["image_path"] == "/tmp/f1.webp" - - -def test_to_traces_does_not_mutate_original() -> None: - film = make_film() - film.to_traces() - assert film.narration_audio_path == "/tmp/u/narration.wav" - assert film.beats[0].audio_path == "/tmp/u/beat1.wav" diff --git a/tests/test_state.py b/tests/test_state.py deleted file mode 100644 index 68b7006bac49275c35777ff97d81bd644edc8732..0000000000000000000000000000000000000000 --- a/tests/test_state.py +++ /dev/null @@ -1,110 +0,0 @@ -"""Contract tests for the SceneState reducer (docs/01 §3, docs/02 §2.4, docs/06 §2). - -Conservation property: under `continuity` the palette is preserved and characters -are merged without duplicates; a `cut` opens a new scene and adopts the Shot. -""" - -from __future__ import annotations - -from lightloom.director.schema import Shot -from lightloom.director.state import SceneState, initial_state, reduce - - -def make_shot( - decision: str, - *, - palette=("#101010", "#202020", "#303030"), - characters=None, - lighting="noon sun", - setting="a new place", -) -> Shot: - return Shot( - decision=decision, - shot_scale="MS", - camera_move="static", - lighting=lighting, - palette=palette, - setting=setting, - characters=characters if characters is not None else [], - image_prompt_en="a concrete visual sentence", - ambient_prompt_en="soft wind", - transition="crossfade" if decision == "continuity" else "hard_cut", - ) - - -def base_state() -> SceneState: - return SceneState( - scene_id=1, - characters=["an old lighthouse keeper, white beard"], - setting="a lighthouse on a cliff", - lighting="stormy dusk", - palette=("#1B2A3A", "#C9A227", "#6E7B8B"), - mood="solitary", - ) - - -def test_continuity_conserves_palette() -> None: - state = base_state() - shot = make_shot("continuity", palette=("#FF0000", "#00FF00", "#0000FF")) - out = reduce(state, shot) - assert out.palette == state.palette # Shot's drifted palette is suppressed - assert out.scene_id == state.scene_id - - -def test_continuity_merges_characters_without_duplicates() -> None: - state = base_state() - shot = make_shot( - "continuity", - characters=[ - "an old lighthouse keeper, white beard", # already present - "AN OLD LIGHTHOUSE KEEPER, WHITE BEARD", # case-variant duplicate - "a young sailor in a blue coat", # new - ], - ) - out = reduce(state, shot) - assert out.characters == [ - "an old lighthouse keeper, white beard", - "a young sailor in a blue coat", - ] - - -def test_continuity_refines_setting_but_keeps_scene() -> None: - state = base_state() - shot = make_shot("continuity", setting="inside the lighthouse spiral staircase") - out = reduce(state, shot) - assert out.setting == "inside the lighthouse spiral staircase" - assert out.scene_id == 1 - - -def test_cut_opens_new_scene_and_adopts_shot() -> None: - state = base_state() - shot = make_shot( - "cut", - palette=("#FF0000", "#00FF00", "#0000FF"), - characters=["a market vendor under orange awnings"], - lighting="orange dawn", - setting="a market at dawn", - ) - out = reduce(state, shot) - assert out.scene_id == 2 - assert out.palette == ("#FF0000", "#00FF00", "#0000FF") - assert out.lighting == "orange dawn" - assert out.setting == "a market at dawn" - # characters reset to the new scene's cast, not merged with the old one - assert out.characters == ["a market vendor under orange awnings"] - - -def test_cut_then_continuity_chain_preserves_new_palette() -> None: - state = base_state() - after_cut = reduce(state, make_shot("cut", palette=("#AA0000", "#00AA00", "#0000AA"))) - drift = make_shot("continuity", palette=("#111111", "#222222", "#333333")) - after_cont = reduce(after_cut, drift) - assert after_cont.palette == ("#AA0000", "#00AA00", "#0000AA") - assert after_cont.scene_id == 2 - - -def test_initial_state_is_valid() -> None: - state = initial_state() - assert state.scene_id == 1 - assert len(state.palette) == 3 - assert state.characters diff --git a/tests/test_storyboard.py b/tests/test_storyboard.py deleted file mode 100644 index 911ae1c2bd044783f6e08cadf7af6df758ac0737..0000000000000000000000000000000000000000 --- a/tests/test_storyboard.py +++ /dev/null @@ -1,23 +0,0 @@ -"""Tests for the storyboard strip composer.""" - -from __future__ import annotations - -from PIL import Image - -from lightloom.export.storyboard import make_storyboard - - -def _frames(n: int, size=(1024, 576)): - return [Image.new("RGB", size, (i * 20 % 255, 40, 60)) for i in range(n)] - - -def test_strip_dimensions_for_three_frames() -> None: - board = make_storyboard(_frames(3), tile_height=180, gap=8, pad=12) - # each 1024x576 tile -> width round(1024*180/576)=320; 3 tiles + 2 gaps + 2 pad - assert board.height == 180 + 12 * 2 - assert board.width == 12 * 2 + 320 * 3 + 8 * 2 - - -def test_empty_film_returns_padded_canvas() -> None: - board = make_storyboard([], tile_height=180, pad=12) - assert board.size == (24, 204) diff --git a/training/modal_lora/launch.py b/training/modal_lora/launch.py deleted file mode 100644 index aac52990481ddb42181d8801104c2d59ec4e4bdf..0000000000000000000000000000000000000000 --- a/training/modal_lora/launch.py +++ /dev/null @@ -1,319 +0,0 @@ -"""Lightloom — painterly STYLE LoRA for FLUX.2-klein, trained on Modal. - -Self-distils a small painterly dataset from our OWN distilled klein-4B (one fixed style -suffix over diverse subjects → variety in content, consistency in style — license-clean, -our own Apache-2.0 outputs), then LoRA-fine-tunes FLUX.2-klein-BASE-4B (rank-16) and pushes -the adapter to the Hub. Intended to be fused into the live painter at warm-up (once validated) for -one cohesive hand-painted look (a second-axis smoothness fix: scene changes read as the same world). - -Usage (CLAUDE.md rule 3 — kick off + poll, never block a session): - modal run training/modal_lora/launch.py --step gen # render the dataset (~3 min) - modal run training/modal_lora/launch.py --step train # train + push the LoRA (~1 h) -""" - -import modal - -app = modal.App("lightloom-style-lora") -vol = modal.Volume.from_name("lightloom-lora", create_if_missing=True) -VOL = "/vol" - -image = ( - modal.Image.debian_slim(python_version="3.11") - .apt_install("git") - .pip_install( - "torch==2.6.0", - "torchvision==0.21.0", - "git+https://github.com/huggingface/diffusers.git", - "transformers>=4.49", - "peft>=0.14", - "accelerate>=1.2", - "safetensors", - "sentencepiece", - "pillow", - "datasets", - "hf_transfer", - "bitsandbytes", - "prodigyopt", - ) - .env({"HF_HUB_ENABLE_HF_TRANSFER": "1", "HF_HOME": f"{VOL}/hf"}) -) - -PAINTER = "black-forest-labs/FLUX.2-klein-4B" # distilled — renders the dataset -PAINTER_REV = "e7b7dc27f91deacad38e78976d1f2b499d76a294" # pin == config.MODEL_REFS["painter"] -BASE = "black-forest-labs/FLUX.2-klein-base-4B" # LoRA train target -BASE_REV = "a3b4f4849157f664bdbc776fd7453c2783562f4d" # pin == config.MODEL_REFS["painter_base_train"] -HUB_REPO = "Efradeca/lightloom-style-lora" # private adapter repo -TRIGGER = "lghtlm style" -STYLE = ("soft impasto oil painting, luminous diffuse light, muted teal-amber palette, " - "visible brushwork, painterly matte, cinematic") -SUBJECTS = [ - "an ancient forest of giant gnarled trees", "a quiet harbor at dawn", "a desert of rolling dunes", - "a neon-lit rainy city street at night", "a misty mountain valley", "a coral reef underwater", - "a lone figure on a cliff over the sea", "a market square under warm lanterns", "a snowy pine forest", - "a field of glowing wildflowers", "a waterfall into a green canyon", "a starry night over hills", - "an old stone bridge over a river", "a cozy library interior", "a meadow at golden hour", - "a stormy coastline with crashing waves", "a temple among clouds", "a frozen lake at dusk", - "a jungle clearing with shafts of light", "a portrait of a weathered traveler", "a sunflower field", - "a cobblestone alley in an old town", "rolling vineyards at sunset", "a lighthouse in fog", -] - - -@app.function(image=image, gpu="L40S", volumes={VOL: vol}, secrets=[modal.Secret.from_name("lightloom-hf")], timeout=3600) -def gen_dataset(): - """Render the style dataset with our distilled klein (the proven inpaint-full-mask path).""" - import os - from pathlib import Path - - import torch - from diffusers import Flux2KleinInpaintPipeline - from PIL import Image - - out = Path(VOL) / "dataset" - out.mkdir(parents=True, exist_ok=True) - pipe = Flux2KleinInpaintPipeline.from_pretrained(PAINTER, revision=PAINTER_REV, torch_dtype=torch.bfloat16, token=os.environ["HF_TOKEN"]).to("cuda") - n = 0 - for i, subj in enumerate(SUBJECTS): - canvas = Image.new("RGB", (1024, 1024), (128, 128, 128)) - mask = Image.new("L", (1024, 1024), 255) - gen = torch.Generator(device="cuda").manual_seed(7 * i + 3) - img = pipe(prompt=f"{subj}, {STYLE}", image=canvas, mask_image=mask, width=1024, height=1024, - num_inference_steps=4, strength=1.0, generator=gen).images[0] - img.save(out / f"{i:02d}.png") - (out / f"{i:02d}.txt").write_text(f"{TRIGGER}, {subj}") # content-only caption + trigger - n += 1 - vol.commit() - print(f"[gen] wrote {n} images + captions to {out}") - return n - - -@app.function(image=image, gpu="L40S", volumes={VOL: vol}, secrets=[modal.Secret.from_name("lightloom-hf")], timeout=10800) -def train(push: bool = False): - """LoRA-fine-tune klein-base on the rendered dataset via the diffusers FLUX.2 trainer. - Saves the adapter to the Modal volume (/vol/lora_out). Pushes to the Hub only when - ``push=True`` AND the HF token has write scope (klein downloads publicly, so training - itself needs no valid token — only the optional Hub push does).""" - import os - import subprocess - import urllib.request - from pathlib import Path - - data = Path(VOL) / "dataset" - outdir = Path(VOL) / "lora_out" - outdir.mkdir(parents=True, exist_ok=True) - script = Path(VOL) / "train_dreambooth_lora_flux2_klein.py" - if not script.exists(): - url = "https://raw.githubusercontent.com/huggingface/diffusers/main/examples/dreambooth/train_dreambooth_lora_flux2_klein.py" - urllib.request.urlretrieve(url, script) - - # Per-image content captions (the trigger carries ONLY the style) = clean style - # disentanglement. Build the imagefolder metadata.jsonl the trainer reads from the - # .txt files gen_dataset wrote, then point --caption_column at it. - import json - meta = data / "metadata.jsonl" - rows = [] - for txt in sorted(data.glob("*.txt")): - png = txt.with_suffix(".png") - if png.exists(): - rows.append({"file_name": png.name, "prompt": txt.read_text().strip()}) - meta.write_text("\n".join(json.dumps(r) for r in rows)) - # The trainer's imagefolder loader globs the dir; remove the now-redundant .txt - # caption files (their text is in metadata.jsonl) so nothing tries to open them as images. - for txt in data.glob("*.txt"): - txt.unlink() - print(f"[train] wrote {len(rows)} caption rows -> {meta}; pruned loose .txt") - cmd = [ - "accelerate", "launch", str(script), - "--pretrained_model_name_or_path", BASE, - "--revision", BASE_REV, - "--dataset_name", str(data), # local imagefolder + metadata.jsonl (per-image captions); - "--instance_prompt", TRIGGER, # NOT --instance_data_dir (line 738: mutually exclusive) - "--caption_column", "prompt", - "--output_dir", str(outdir), - "--mixed_precision", "bf16", - "--resolution", "1024", - "--train_batch_size", "1", - "--gradient_accumulation_steps", "4", - "--gradient_checkpointing", - "--rank", "16", - "--learning_rate", "1e-4", - "--lr_scheduler", "constant", - "--lr_warmup_steps", "0", - "--max_train_steps", "1500", - "--checkpointing_steps", "500", - "--seed", "0", - ] - if push: - cmd += ["--push_to_hub", "--hub_model_id", HUB_REPO] - env = {**os.environ, "HF_TOKEN": os.environ["HF_TOKEN"], "HUGGING_FACE_HUB_TOKEN": os.environ["HF_TOKEN"]} - print("[train] launching:", " ".join(cmd)) - subprocess.run(cmd, check=True, env=env) - vol.commit() - weights = sorted(str(p) for p in outdir.rglob("*.safetensors")) - print(f"[train] done -> saved to {outdir}; adapters: {weights}") - if push: - print(f"[train] pushed to {HUB_REPO}") - - -@app.function(image=image, gpu="L40S", volumes={VOL: vol}, secrets=[modal.Secret.from_name("lightloom-hf")], timeout=3600) -def validate(): - """Render the SAME scenes with the DISTILLED klein (the live painter) WITHOUT vs WITH the - trained LoRA fused — validates both the style quality AND that load_lora_weights/fuse_lora - works on the distilled inpaint pipeline (the actual integration path).""" - import os - from pathlib import Path - - import torch - from diffusers import Flux2KleinInpaintPipeline - from PIL import Image - - out = Path(VOL) / "validate" - out.mkdir(parents=True, exist_ok=True) - scenes = [ - "an ancient forest of giant gnarled trees, shafts of light", - "a quiet harbor at dawn, boats on still water", - "a lone figure on a cliff over a stormy sea", - "a cobblestone alley in an old town at dusk", - ] - tok = os.environ["HF_TOKEN"] - - def render(pipe, prompt, seed): - canvas = Image.new("RGB", (1024, 1024), (128, 128, 128)) - mask = Image.new("L", (1024, 1024), 255) - gen = torch.Generator(device="cuda").manual_seed(seed) - return pipe(prompt=prompt, image=canvas, mask_image=mask, width=1024, height=1024, - num_inference_steps=4, strength=1.0, generator=gen).images[0] - - pipe = Flux2KleinInpaintPipeline.from_pretrained(PAINTER, revision=PAINTER_REV, torch_dtype=torch.bfloat16, token=tok).to("cuda") - for i, s in enumerate(scenes): # BASE (no LoRA) - render(pipe, s, 100 + i).save(out / f"{i:02d}_base.png") - pipe.load_lora_weights(HUB_REPO, weight_name="pytorch_lora_weights.safetensors", token=tok) - pipe.fuse_lora() - for i, s in enumerate(scenes): # WITH LoRA (same seed) + trigger - render(pipe, f"{TRIGGER}, {s}", 100 + i).save(out / f"{i:02d}_lora.png") - vol.commit() - print(f"[validate] wrote {2 * len(scenes)} images (base vs lora) to {out}") - return len(scenes) - - -@app.function(image=image, gpu="L40S", volumes={VOL: vol}, secrets=[modal.Secret.from_name("lightloom-hf")], timeout=3600) -def stylegrid(): - """Render 10 diverse story-scenes, each in the art style the Director would pick for it, WITH the - LoRA fused at full scale (exactly the live path: `lghtlm style, `). Visual - proof that the styles look genuinely different and the LoRA doesn't flatten them.""" - import os - from pathlib import Path - - import torch - from diffusers import Flux2KleinInpaintPipeline - from PIL import Image - - out = Path(VOL) / "stylegrid" - out.mkdir(parents=True, exist_ok=True) - tok = os.environ["HF_TOKEN"] - scenes = [ - ("pixelart", "an 8-bit hero jumps across floating platforms collecting coins", ", 16-bit pixel art, crisp blocky pixels, limited retro palette, dithering, game sprite"), - ("retro", "a vintage 1950s diner on a sunny route 66 road trip", ", vintage retro illustration, aged muted tones, halftone grain, mid-century travel-poster feel"), - ("comic", "a caped superhero smashes through a wall to save the city", ", bold comic-book pop-art, thick black ink outlines, halftone Ben-Day dots, dynamic panel"), - ("ukiyoe", "a great wave curls over fishing boats beneath Mount Fuji", ", ukiyo-e Japanese woodblock print, flat bold colour, strong outlines, Edo-period, Hokusai"), - ("gothic", "a haunted vampire castle on a stormy moonlit cliff", ", dark gothic art, ornate and dramatic, candle-lit chiaroscuro, baroque gloom, haunting"), - ("artdeco", "a glamorous 1920s gatsby ballroom of gold and crystal", ", art deco, geometric gold-and-black elegance, 1920s glamour, symmetrical, sleek"), - ("claymation", "a cute clay puppet bakes a tiny cake in a cozy kitchen", ", claymation stop-motion, soft sculpted clay textures, handcrafted, tactile, charming"), - ("charcoal", "a dramatic portrait of an old weathered fisherman's face", ", expressive charcoal drawing, smudged deep blacks, dramatic monochrome, rough paper grain"), - ("modern", "a clean minimalist city skyline at sunset", ", modern flat-design illustration, bold simple shapes, clean vector look, minimal palette"), - ("scifi", "a sleek chrome starship docks at a futuristic space station", ", sleek futuristic sci-fi concept art, chrome, holographic glass, clean hard-surface design"), - ] - pipe = Flux2KleinInpaintPipeline.from_pretrained(PAINTER, revision=PAINTER_REV, torch_dtype=torch.bfloat16, token=tok).to("cuda") - pipe.load_lora_weights(HUB_REPO, weight_name="pytorch_lora_weights.safetensors", token=tok) - pipe.fuse_lora() - for i, (label, subj, suffix) in enumerate(scenes): - canvas = Image.new("RGB", (1024, 1024), (128, 128, 128)) - mask = Image.new("L", (1024, 1024), 255) - gen = torch.Generator(device="cuda").manual_seed(50 + i) - img = pipe(prompt=f"{TRIGGER}, {subj}{suffix}", image=canvas, mask_image=mask, width=1024, height=1024, - num_inference_steps=4, strength=1.0, generator=gen).images[0] - img.save(out / f"{i:02d}_{label}.png") - vol.commit() - print(f"[stylegrid] wrote {len(scenes)} style images to {out}") - return [s[0] for s in scenes] - - -@app.function(image=image, gpu="L40S", volumes={VOL: vol}, secrets=[modal.Secret.from_name("lightloom-hf")], timeout=3600) -def covers(): - """Pre-render the ambient/cold-start COVER panorama in several DISTINCT styles (+ depth), so the - frontend can pick one at random — the world looks different from the very first frame, not just - once live strips arrive. Same 6 showcase scenes, each rendered in N styles with the LoRA fused.""" - import json - import os - from pathlib import Path - - import numpy as np - import torch - from diffusers import Flux2KleinInpaintPipeline - from PIL import Image - from transformers import pipeline as hf_pipeline - - out = Path(VOL) / "covers" - out.mkdir(parents=True, exist_ok=True) - tok = os.environ["HF_TOKEN"] - subjects = [ - ("A glowing forest came alive with drifting fireflies.", "a glowing enchanted forest alive with drifting fireflies"), - ("A crystal river wound between the ancient trees.", "a crystal river winding between ancient towering trees"), - ("A village of lantern-lit treehouses appeared in the canopy.", "a village of lantern-lit treehouses in the forest canopy"), - ("A great waterfall of light poured into a glowing canyon.", "a great waterfall of light pouring into a glowing canyon"), - ("A temple floated among luminous clouds.", "a serene temple floating among luminous golden clouds"), - ("A field of giant bioluminescent flowers stretched to the horizon.", "a vast field of giant bioluminescent flowers to the horizon"), - ] - styles = { - "ghibli": ", Studio Ghibli style, hand-painted watercolour backgrounds, soft gentle light, lush whimsical nature", - "oil": ", classical oil painting, old-master chiaroscuro, rich varnished colour, baroque drama", - "anime": ", anime cel-shaded illustration, crisp clean linework, vibrant saturated colour, Makoto Shinkai luminous skies", - "synthwave": ", synthwave retro-futurism, neon magenta-and-cyan grids, chrome, 80s sci-fi glow", - "watercolour": ", delicate watercolour wash, soft bleeding pigments, luminous paper-white, airy", - "ukiyoe": ", ukiyo-e Japanese woodblock print, flat bold colour, strong outlines, Edo-period, Hokusai", - } - pipe = Flux2KleinInpaintPipeline.from_pretrained(PAINTER, revision=PAINTER_REV, torch_dtype=torch.bfloat16, token=tok).to("cuda") - pipe.load_lora_weights(HUB_REPO, weight_name="pytorch_lora_weights.safetensors", token=tok) - pipe.fuse_lora() - depth = hf_pipeline("depth-estimation", model="depth-anything/Depth-Anything-V2-Small-hf", device=0) - variants = list(styles.keys()) - for vi, vkey in enumerate(variants): - vdir = out / f"v_{vkey}" - vdir.mkdir(parents=True, exist_ok=True) - man = [] - for i, (caption, subj) in enumerate(subjects): - canvas = Image.new("RGB", (1024, 1024), (128, 128, 128)) - mask = Image.new("L", (1024, 1024), 255) - gen = torch.Generator(device="cuda").manual_seed(900 + vi * 10 + i) - img = pipe(prompt=f"{TRIGGER}, {subj}{styles[vkey]}", image=canvas, mask_image=mask, - width=1024, height=1024, num_inference_steps=4, strength=1.0, generator=gen).images[0] - img.save(vdir / f"section-{i}.webp", "WEBP", quality=88) - dimg = depth(img)["depth"] - da = np.asarray(dimg, dtype=np.float32) - lo, hi = float(np.percentile(da, 2)), float(np.percentile(da, 98)) - da = np.clip((da - lo) / (hi - lo + 1e-6), 0.0, 1.0) if hi > lo else np.full_like(da, 0.5) - Image.fromarray((da * 255).astype("uint8")).save(vdir / f"section-{i}-depth.png") - man.append({"index": i, "caption": caption, - "image": f"/frontend/assets/scroll/v_{vkey}/section-{i}.webp", - "depth": f"/frontend/assets/scroll/v_{vkey}/section-{i}-depth.png"}) - (vdir / "manifest.json").write_text(json.dumps(man, indent=2)) - (out / "variants.json").write_text(json.dumps([f"v_{v}" for v in variants])) - vol.commit() - print(f"[covers] wrote {len(variants)} cover variants: {variants}") - return variants - - -@app.local_entrypoint() -def main(step: str = "gen"): - if step == "gen": - print("dataset images:", gen_dataset.remote()) - elif step == "train": - train.remote(push=True) - print("training kicked off") - elif step == "validate": - print("validation images:", validate.remote()) - elif step == "stylegrid": - print("style images:", stylegrid.remote()) - elif step == "covers": - print("cover variants:", covers.remote()) - else: - print("unknown step; use --step gen | train | validate")