#!/usr/bin/env python3 """Create a portable HTML sampler for whereami JSONL records.""" from __future__ import annotations import argparse import json import random from pathlib import Path from typing import Any try: from .common import html_escape_text, image_to_data_uri except ImportError: from common import html_escape_text, image_to_data_uri def parse_args() -> argparse.Namespace: parser = argparse.ArgumentParser(description="Render a random whereami sample viewer.") parser.add_argument("--input-jsonl", type=Path, required=True) parser.add_argument("--output-html", type=Path, required=True) parser.add_argument("--examples", type=int, default=12) parser.add_argument("--seed", type=int, default=0) parser.add_argument("--max-image-width", type=int, default=360) return parser.parse_args() def read_jsonl(path: Path) -> list[dict[str, Any]]: with path.open() as handle: return [json.loads(line) for line in handle if line.strip()] def image_block(path: str, index: int, max_width: int) -> str: uri = image_to_data_uri(Path(path), max_width=max_width) if uri is None: return f"
Image {index + 1}: missing
{html_escape_text(path)}
" return f"
Image {index + 1}: {html_escape_text(Path(path).name)}
" def render_record(record: dict[str, Any], max_width: int) -> str: metadata = record.get("metadata") or {} anchor = metadata.get("anchor") or {} cell = record.get("ground_truth_camera_cell") facing = record.get("ground_truth_facing_vector") images = "".join(image_block(path, index, max_width) for index, path in enumerate(record.get("image_paths") or [])) if not images: images = "
No exported image paths in this record.
" diagnostics = { "group": record.get("image_group_id"), "anchor image": record.get("anchor_image_index"), "anchor frame": record.get("anchor_frame_index"), "sharpness": anchor.get("frame_sharpness"), "max cell-axis offset (m)": (anchor.get("camera_cell_margin") or {}).get("cell_center_axis_offset_m"), "facing bin margin (deg)": (anchor.get("facing_bin_margin") or {}).get("facing_bin_margin_deg"), "group visible grid instances": metadata.get("visible_grid_instance_ids_used_for_crop"), "group visible grid categories": metadata.get("visible_grid_categories_used_for_crop"), "anchor visible grid instances": anchor.get("visible_grid_instance_ids"), } diagnostic_rows = "".join( f"{html_escape_text(key)}{html_escape_text(value)}" for key, value in diagnostics.items() ) return f"""

{html_escape_text(record.get('qa_id'))}

{images}

Ground truth

CAMERA_CELL: {html_escape_text(cell)}\nFACING_VECTOR: {html_escape_text(facing)}
{diagnostic_rows}

ASCII object grid

{html_escape_text(record.get('grid_text'))}
Prompt
{html_escape_text(record.get('prompt'))}
""" def main() -> None: args = parse_args() records = read_jsonl(args.input_jsonl) rng = random.Random(args.seed) if args.examples > 0 and len(records) > args.examples: records = rng.sample(records, args.examples) body = "\n".join(render_record(record, args.max_image_width) for record in records) page = f""" WhereAmI samples

WhereAmI self-localization samples ({len(records)})

{body}
""" args.output_html.parent.mkdir(parents=True, exist_ok=True) args.output_html.write_text(page) print(f"Wrote {len(records)} samples to {args.output_html}") if __name__ == "__main__": main()