"""Write kaggle/runner.ipynb, the public notebook friends copy, from kaggle/bootstrap.py. python kaggle/make_notebook.py --ops-repo ORG/pocket-math-ops """ from __future__ import annotations import argparse import json from pathlib import Path HERE = Path(__file__).resolve().parent def build(ops_repo: str) -> dict: src = (HERE / "bootstrap.py").read_text(encoding="utf-8").replace('"ORG/pocket-math-ops"', f'"{ops_repo}"') lines = src.splitlines(keepends=True) settings = [ln for ln in lines if ln.startswith(("JOB_ID", "OPS_REPO"))] code = [ln for ln in lines if ln not in settings] intro = ("# Pocket Math runner\n\nOne click runs the next queued job for up to 12 hours, then saves everything " "to Hugging Face, so the next session (on any account) continues it.\n\n" "1. Settings (right panel): **Accelerator: GPU T4 x2**, **Internet: on**.\n" "2. Add-ons > Secrets: a secret named **HF_TOKEN** (your Hugging Face write token), attached.\n" "3. **Save Version > Save & Run All (Commit)**. You can close the tab.\n") cell = lambda kind, text: {"cell_type": kind, "metadata": {}, "source": text, # noqa: E731 **({"outputs": [], "execution_count": None} if kind == "code" else {})} return { "cells": [cell("markdown", intro), cell("code", "".join(settings)), cell("code", "".join(code))], "metadata": {"kernelspec": {"display_name": "Python 3", "language": "python", "name": "python3"}, "language_info": {"name": "python"}, "kaggle": {"accelerator": "nvidiaTeslaT4", "isInternetEnabled": True, "isGpuEnabled": True}}, "nbformat": 4, "nbformat_minor": 5, } def main() -> None: p = argparse.ArgumentParser() p.add_argument("--ops-repo", default="ORG/pocket-math-ops") p.add_argument("--out", default=str(HERE / "runner.ipynb")) a = p.parse_args() Path(a.out).write_text(json.dumps(build(a.ops_repo), indent=1), encoding="utf-8") print(f"wrote {a.out} for {a.ops_repo}") if __name__ == "__main__": main()