#!/usr/bin/env python3 """Build the interactive static Space "RoboRACE-Playground". Everything is precomputed from the cached Cosmos-Reason2 scores: for each robot, attack and set of lying cameras, the page gets the corrupted reports and every fusion method's verdict per episode. The browser only looks things up, so what the visitor sees is exactly what the benchmark code computes. python scripts/make_playground.py OUT_DIR -> OUT_DIR/index.html, data.json, README.md """ import itertools import json import sys from pathlib import Path import numpy as np ROOT = Path(__file__).resolve().parents[1] sys.path.insert(0, str(ROOT / "src")) from robotics.bench import trackA # noqa: E402 from robotics.swarm import attacks, fusion, racenet # noqa: E402 DS = "Nabidnur/RoboRACE-Bench" RES = f"https://huggingface.co/datasets/{DS}/resolve/main" ATTACKS = ("invert", "collude", "noise", "stuck") CAMS = ("front", "left", "right", "back", "top") def methods(): m = {"receiver alone": lambda P: fusion.single(P, P, 0), "majority vote": lambda P: fusion.majority(P, P), "Dawid–Skene": lambda P: fusion.dawid_skene(P, P), "RACE-S (ours)": lambda P: fusion.race_s(P, P, 0)[:2]} if racenet.available(): m["RACE-Net (ours, learned)"] = lambda P: racenet.race_net(P, P, 0) return m def compute(): out = {"cams": CAMS, "attacks": ATTACKS, "robots": {}} M = methods() out["methods"] = list(M) for robot, label in (("so101", "SO-101"), ("panda", "Franka Panda")): sp, ep = ROOT / f"results/{robot}/vlm_scores.jsonl", ROOT / f"data/{robot}/episodes.jsonl" if not sp.exists() or not ep.exists(): continue (_, _, _), (Pe, ye, _) = trackA.load_scores(sp) eps = sorted((e for e in map(json.loads, open(ep)) if e["split"] == "eval"), key=lambda e: e["seed"]) cells = {} for atk in ATTACKS: for m in range(0, 5): for liars in itertools.combinations(range(1, 5), m): P = attacks.apply(Pe, list(liars), atk, "eval", np.random.default_rng(0)) if liars else Pe dec, acc = {}, {} for name, fn in M.items(): s, thr = fn(P) d = np.asarray(s) > thr dec[name] = "".join("1" if x else "0" for x in d) acc[name] = round(float(np.mean(d == ye)), 4) cells[f"{atk}|{''.join(map(str, liars))}"] = {"p": np.round(P, 2).ravel().tolist(), "dec": dec, "acc": acc} out["robots"][robot] = {"label": label, "episodes": [{"seed": e["seed"], "task": e["task"], "mode": e["mode"], "gt": int(e["success"])} for e in eps], "cells": cells} return out PAGE = r""" RoboRACE Playground

RoboRACE Playground

Five cameras watch a robot arm; a vision-language model (Cosmos-Reason2-2B, run on a CPU) scores each view for “did the task succeed?”. Choose which cameras lie and see what each fusion rule concludes on 110 real cached episodes. The front camera is the receiver: the robot's own camera, which it trusts. All numbers are precomputed by the benchmark code in the RoboRACE dataset; nothing is simulated in your browser.

Robot
Attack
Lying cameras

Accuracy over all 110 evaluation episodes (thin line = 50%, coin flip)

Attacks: invert – liars report 1 − p (a consistent liar still carries information); collude – all liars send one identical inverted report; noise – random reports; stuck – always “success”. Methods are label-free: none sees the ground truth. Each camera's vote uses its own threshold (a quantile of its unlabelled history), so a low raw score can still count as a “yes” vote. Full study, code and videos: showcase · RACE-Net model.

""" def build(out): out = Path(out) out.mkdir(parents=True, exist_ok=True) data = compute() (out / "data.json").write_text(json.dumps(data, separators=(",", ":"))) (out / "index.html").write_text(PAGE.replace("__RES__", RES)) (out / "README.md").write_text("""--- title: RoboRACE Playground emoji: 🕵️ colorFrom: red colorTo: green sdk: static pinned: false short_description: Pick which robot cameras lie; watch each fusion rule --- Interactive companion to RoboRACE. Data and code: https://huggingface.co/datasets/""" + DS + "\n") print("playground cells:", {k: len(v["cells"]) for k, v in data["robots"].items()}, "bytes", (out / "data.json").stat().st_size) return out if __name__ == "__main__": build(sys.argv[1] if len(sys.argv) > 1 else ROOT / ".hf_stage_play")