"""Build the Space's example gallery: videos + posters under static/examples/, metadata in static/examples.json, and the benchmark table in static/benchmark.json. The examples are the v2 blog post's demos, with the blog's web encodes (ambient-website public/assets/blog/video-chunker). Outputs: - WGO-Bench clips: the released run 1 of Tempora-1 (thinking on, PPT prompt), from the release repo, uncorrected. (The blog shows hand-corrected tracks for some of these; the Space shows what the model returned.) - general clips: example_outputs/.json when present (written by run_examples.py through the live Space, release config); otherwise the output shown in the blog post, marked as an earlier run. python3 app/space/build_examples.py --site ../ambient-website/site --release ../video-chunker-27b """ import argparse import json import os import shutil import subprocess import sys HERE = os.path.dirname(os.path.abspath(__file__)) OUT = os.path.join(HERE, "static", "examples") CORE = {"start", "end", "label", "metadata"} PICK_PLACE = "Separate segments for picking up and for placing each object." GENERAL = [ # id, data.json key, file, tag, title, instruction, fields [(name, description)], poster t, note, credit ("talk", "talk", "talk.mp4", "Rich metadata", "Chapters and speakers in a 16-minute talk", "Segment by the talk sections", [("person_speaking", "name of the person speaking"), ("speaker_dress", "detailed description of speaker dress in 10 words"), ("speaker_demography", "detailed description of speaker demography - age, sex and ethiniciy")], 60.0, "A conference talk with two speakers and no chapter markers: ten topical sections, speaker hand-offs read from " "the on-screen title card, and the three fields filled for every section.", "Talk: 'Don't build agents, build skills instead', Barry Zhang and Mahesh Murag, AI Engineer Code Summit."), ("ads", "ads", "f1_banners.mp4", "Inclusion filter", "Trackside brand banners in race highlights", "segment only sections where you see brand advertisement or banner at the trackside", [("brand_name", ""), ("placement", "")], 30.0, "Only stretches with a trackside banner in view are returned; pit-lane shots, onboard cameras and close-ups stay " "unlabelled. 25 intervals: a frame check found 22 brands right and 3 boards misread.", "Footage: F1 race highlights."), ("crowd", "crowd", "ncaa_1963.mp4", "Exclusion filter", "Audience cutaways in a 1963 newsreel", "segment only portion where the game play is not shown , only audience or cheerleaders are shown", [("description", "")], 10.0, "Gameplay is skipped and only audience or cheerleader cutaways are marked: nine short intervals, several of them " "1.2 to 1.5 seconds, each with a one-sentence description.", "Footage: 1963 NCAA Men's Division I Basketball Championship newsreel (Loyola vs. Cincinnati)."), ("steps", "steps", "cappuccino.mp4", "Procedure", "Recipe steps from a coffee tutorial", "segment by finer steps", [("detailed_step_instruction", "")], 20.0, "17 steps: the 23-second milk-steaming stretch stays one segment while 2 to 4 second actions such as tamping and " "pouring get their own.", "Video: 'How to make a cappuccino', Pact Coffee."), ("presenter", "presenter", "presenter_tips.mp4", "Fine granularity", "Presenter-only segments in a product walkthrough", "segment only the portion showing presenter, keep the segments finer", [("detailed_step_instruction", "")], 8.0, "A visual filter and a granularity constraint together: full-screen title cards and UI animations are skipped, " "and presenter stretches are split into 24 fine intervals (talking, looking at the phone, typing).", "Video: '3 ChatGPT Tips to Save Money', OpenAI."), ] WGO = [ # id, file, tag, title, poster t, note ("galaxea_009", "galaxea_009.mp4", "Robot · dual arm", "Sorting seven items with two arms", 4.0, "A Galaxea R1 Lite, a robot the model never saw in training: food goes in the right basket, everything else in " "the left, and the two arms take turns."), ("galaxea_002", "galaxea_002.mp4", "Robot · dual arm", "Spelling a word with craft sticks", 6.0, "The robot rearranges coloured craft sticks to spell BRAIN: the left arm works the left side of the word, then " "the right arm takes over."), ("galaxea_073", "galaxea_073.mp4", "Robot · dual arm", "Open and close a drawer", 3.0, "Not every event is a pick or a place: with the same instruction, opening and closing the drawer are the two " "events."), ("robointer_droid_000024", "robointer_droid_000024.mp4", "Robot · single arm", "Tomato into a bowl", 6.0, "A DROID episode from a third-person camera at 320×180, split into the pick and the place."), ("robointer_droid_000006", "robointer_droid_000006.mp4", "Robot · single arm", "Pen out of a mug", 4.0, "The pick ends once the pen is clear of the mug; the place covers the carry and the release on the table."), ("homer_59", "homer_59.mp4", "First person", "Shelving books, one stack at a time", 12.0, "First-person household video: the camera moves with the head and hands come in and out of view."), ("homer_12", "homer_12.mp4", "First person", "Two minutes of dense manipulation", 20.0, "Opening, checking and closing nine containers: many short events in a row."), ("homer_5", "homer_5.mp4", "First person", "Dusting a two-level shelf", 10.0, "Long continuous actions: each wiping pass is one segment."), ] WGO_CREDIT = "Clip: WGO-Bench (CC BY-NC-SA 4.0)." def chunk_rows(chunks): rows = [] for c in chunks: meta = dict(c.get("metadata") or {}) meta.update({k: v for k, v in c.items() if k not in CORE}) rows.append({"start": float(c["start"]), "end": float(c["end"]), "label": str(c.get("label", "")), "metadata": {k: (v[0] if isinstance(v, list) and len(v) == 1 else v) for k, v in meta.items()}}) return rows def duration(path): p = subprocess.run(["ffprobe", "-v", "error", "-show_entries", "format=duration", "-of", "csv=p=0", path], capture_output=True, text=True, check=True) return round(float(p.stdout.strip()), 2) def poster(src, t, dst): subprocess.run(["ffmpeg", "-y", "-loglevel", "error", "-ss", str(t), "-i", src, "-frames:v", "1", "-vf", "scale=480:-2", "-q:v", "4", dst], check=True) def main(): ap = argparse.ArgumentParser() ap.add_argument("--site", required=True) ap.add_argument("--release", required=True) a = ap.parse_args() sys.path.insert(0, os.path.join(a.release, "src")) from video_chunker.parsing import extract_json_chunks from video_chunker.prompt import build_prompt media = os.path.join(a.site, "public", "assets", "blog", "video-chunker") data = json.load(open(os.path.join(a.site, "src", "content", "blog", "video-chunker-27b", "data.json"))) released = {} for l in open(os.path.join(a.release, "results", "wgo", "tempora-1", "run1", "predictions.jsonl")): r = json.loads(l) released[r["id"]] = r os.makedirs(OUT, exist_ok=True) examples = [] def media_for(eid, fname, t): dst = os.path.join(OUT, fname) if not os.path.exists(dst): shutil.copy(os.path.join(media, fname), dst) jpg = os.path.splitext(fname)[0] + ".jpg" poster(dst, t, os.path.join(OUT, jpg)) return f"examples/{fname}", f"examples/{jpg}", duration(dst) for eid, key, fname, tag, title, instr, fields, t, note, credit in GENERAL: src, post, dur = media_for(eid, fname, t) names, descs = [f for f, _ in fields], [d for _, d in fields] prompt = build_prompt(instr, "", names, descs if any(descs) else None) live = os.path.join(HERE, "example_outputs", f"{eid}.json") if os.path.exists(live): res = json.load(open(live)) result = {"chunks": chunk_rows(res["chunks"]), "reasoning": res.get("reasoning"), "raw": res.get("raw"), "thinking": res.get("thinking", True), "provenance": "Release configuration (thinking on), run through this Space's backend."} assert res.get("prompt") == prompt, f"{eid}: saved output was made with a different prompt" else: segs = data[key]["clips"][0]["views"][0]["tracks"][-1]["segs"] chunks = [{"start": s["s"], "end": s["e"], "label": s["l"], "metadata": s.get("m") or {}} for s in segs] result = {"chunks": chunk_rows(chunks), "reasoning": None, "raw": json.dumps({"chunks": chunks}), "thinking": False, "provenance": "Output from the blog post (an earlier run, not the release configuration). " "Run it to see the release model."} examples.append({"id": eid, "tag": tag, "title": title, "src": src, "poster": post, "duration": dur, "instruction": instr, "task": "", "fields": [{"name": n, "description": d} for n, d in fields], "prompt": prompt, "note": note, "credit": credit, "result": result}) for eid, fname, tag, title, t, note in WGO: src, post, dur = media_for(eid, fname, t) r = released[eid] task = r["prompt"].split("\nTask: ", 1)[1].split("\n", 1)[0] prompt = build_prompt(PICK_PLACE, task, []) assert prompt == r["prompt"], eid examples.append({"id": eid, "tag": tag, "title": title, "src": src, "poster": post, "duration": dur, "instruction": PICK_PLACE, "task": task, "fields": [], "prompt": prompt, "note": note, "credit": WGO_CREDIT, "result": {"chunks": chunk_rows(extract_json_chunks(r["output"]) or []), "reasoning": r.get("reasoning"), "raw": r["output"], "thinking": True, "provenance": "Release configuration (thinking on): released WGO-Bench run 1, uncorrected."}}) json.dump(examples, open(os.path.join(HERE, "static", "examples.json"), "w"), indent=1, ensure_ascii=False) keep = {os.path.basename(e["src"]) for e in examples} | {os.path.basename(e["poster"]) for e in examples} for f in sorted(os.listdir(OUT)): if f not in keep: os.remove(os.path.join(OUT, f)) print("removed", f) for e in examples: print(f"{e['id']:24s} {e['duration']:7.1f}s {len(e['result']['chunks']):3d} chunks {e['result']['provenance'][:40]}") build_bench(a.release) BENCH = [ # group, display name, results.json slug (each model's best run per group, as in the blog's table) ("With reasoning (each model's default)", "Tempora-1", "tempora-1"), ("With reasoning (each model's default)", "Gemini 4 Carbon", "gemini-4-carbon_sheets"), ("With reasoning (each model's default)", "Gemini 4 Hydrogen", "gemini-4-hydrogen_sheets"), ("With reasoning (each model's default)", "Gemini 4 Neon", "gemini-4-neon_video"), ("With reasoning (each model's default)", "Elorian Glimpse", "elorian-glimpse_sheets"), ("With reasoning (each model's default)", "Gemini 3.8 Flash", "gemini-3.8-flash_sheets"), ("With reasoning (each model's default)", "Pegasus 1.6 (no reasoning setting)", "pegasus-1.6"), ("Without reasoning (off, or the lowest setting)", "Tempora-1", "tempora-1_no-thinking"), ("Without reasoning (off, or the lowest setting)", "Gemini 4 Carbon", "gemini-4-carbon_video_reasoning-off"), ("Without reasoning (off, or the lowest setting)", "Gemini 4 Neon", "gemini-4-neon_video_reasoning-lowest"), ("Without reasoning (off, or the lowest setting)", "Gemini 4 Hydrogen", "gemini-4-hydrogen_video_reasoning-minimal"), ("Without reasoning (off, or the lowest setting)", "Gemini 3.8 Flash", "gemini-3.8-flash_video_reasoning-minimal"), ("Without reasoning (off, or the lowest setting)", "Qwen3.8-27B, no fine-tuning", "qwen3.8-27b_base"), ] def build_bench(release): """static/benchmark.json from the release repo's results/wgo/results.json.""" res = {r["slug"]: r for r in json.load(open(os.path.join(release, "results", "wgo", "results.json")))} rows, base = [], {} for group, name, slug in BENCH: r = res[slug] m = r["mean"]["all"] ours = slug.startswith("tempora-1") if ours: base[group] = r["cost_per_video_hour"] rows.append({"group": group, "name": name, "ours": ours, "runs": r["runs"], "input": "contact sheets" if r["prompt"] == "refiner" else "video", "seg_f1": round(m["seg_f1"], 3), "e2e_f1": round(m["e2e_f1"], 3), "label_acc": round(m["label_acc"], 2), "cost": r["cost_per_video_hour"], "x": round(r["cost_per_video_hour"] / base[group], 1)}) json.dump(rows, open(os.path.join(HERE, "static", "benchmark.json"), "w"), indent=1) for r in rows: print(f"{r['name']:38s} {r['input']:15s} {r['seg_f1']:.3f} {r['e2e_f1']:.3f} {r['label_acc']:.2f} " f"{r['cost']:6.3f} {r['x']:5.1f}x") if __name__ == "__main__": main()