#!/usr/bin/env python3 """Blind A/B gallery of the visual-bench pages of two eval runs (eval_code_api.py --bench visual). python scripts/visual_gallery.py base looped_t3 --out runs/code_eval/gallery_base_vs_t3.html Writes ONE self-contained HTML file (screenshots embedded) to open in any browser. For each prompt the two models' renders are shown side by side in random order without labels; pick Left / Right / Tie (stored in the browser), then press "Reveal" for the labels and the tally. "Live" runs the page itself in a sandboxed iframe (scripts on, no access to the gallery or disk). """ from __future__ import annotations import argparse import base64 import html import json import random from pathlib import Path PAGE = """Visual A/B

Blind visual comparison

Judge each pair against its prompt. Your choices are saved in this browser.

__TASKS__ """ def side(run_dir: Path, tag: str, tid: str, sample: int, rec: dict, pos: str) -> str: stem = run_dir / "visual" / f"{tid}_s{sample}" png, page = stem.with_suffix(".png"), stem.with_suffix(".html") img = (f'' if png.exists() else '
no page produced
') live = (f'' if page.exists() else "") r = rec.get("render") or {} errs = "; ".join((r.get("page_errors") or [])[:2]) or rec.get("detail", "") return (f'
{html.escape(tag)}
' f'{img}
{live}
{html.escape(errs)}
') def main() -> None: ap = argparse.ArgumentParser() ap.add_argument("tag_a") ap.add_argument("tag_b") ap.add_argument("--runs", default="runs/code_eval") ap.add_argument("--visual-file", default=str(Path(__file__).resolve().parent.parent / "data" / "visual_prompts.jsonl")) ap.add_argument("--out", default=None) ap.add_argument("--seed", type=int, default=0) args = ap.parse_args() runs = Path(args.runs) prompts = {r["id"]: r["prompt"] for r in map(json.loads, open(args.visual_file, encoding="utf-8")) if r} def recs(tag): d = {} for r in map(json.loads, open(runs / tag / "results.jsonl", encoding="utf-8")): if r["bench"] == "visual": d[(r["id"], r["sample"])] = r return d ra, rb = recs(args.tag_a), recs(args.tag_b) rng = random.Random(args.seed) blocks = [] for key in sorted(set(ra) & set(rb)): tid, s = key pair = [(args.tag_a, ra[key]), (args.tag_b, rb[key])] rng.shuffle(pair) sides = "".join(side(runs / tag, tag, tid, s, rec, pos) for (tag, rec), pos in zip(pair, ("left", "right"))) blocks.append( f'

{html.escape(tid)} (sample {s})

' f'
{html.escape(prompts.get(tid, ""))}
{sides}
' '

' '

') out = Path(args.out or runs / f"gallery_{args.tag_a}_vs_{args.tag_b}.html") key = f"visual-ab:{args.tag_a}:{args.tag_b}:{args.seed}" out.write_text(PAGE.replace("__TASKS__", "\n".join(blocks)).replace("__KEY__", key), encoding="utf-8") print(f"wrote {out} ({len(blocks)} pairs)") if __name__ == "__main__": main()