Download studies/shared/scripts/sync_readme.py from lyffseba/xai-studies: direct link, hf CLI and curl.
- Browser
- Download file 2.32 kB
-
https://huggingface.co/datasets/lyffseba/xai-studies/resolve/main/studies/shared/scripts/sync_readme.py
- Command line
-
hf download hf://datasets/lyffseba/xai-studies/studies/shared/scripts/sync_readme.py
-
curl -L -o sync_readme.py https://huggingface.co/datasets/lyffseba/xai-studies/resolve/main/studies/shared/scripts/sync_readme.py
2.32 kB
| #!/usr/bin/env python3 | |
| """Sync root README status section from derived/STATUS.json.""" | |
| from __future__ import annotations | |
| import json | |
| import re | |
| import sys | |
| from pathlib import Path | |
| ROOT = Path(__file__).resolve().parents[2] | |
| README = ROOT / "README.md" | |
| STATUS = ROOT / "derived" / "STATUS.json" | |
| START = "<!-- status:start -->" | |
| END = "<!-- status:end -->" | |
| def build_block(status: dict) -> str: | |
| # Minimal Bellard-style list; full table lives in derived/DASHBOARD.md | |
| lines = [START, ""] | |
| for m in status.get("models") or []: | |
| active = m.get("active_params") | |
| if active is None: | |
| active = "undisclosed" | |
| total = m.get("total_params") or "?" | |
| lines.append( | |
| f"- [`{m['model_id']}`](models/{m['model_id']}/) — {m['display_name']}: " | |
| f"{total} / {active}, status `{m['status']}`" | |
| ) | |
| lines += [ | |
| "", | |
| f"[full table](derived/DASHBOARD.md) · {status.get('generated_at_utc', '')}", | |
| "", | |
| END, | |
| ] | |
| return "\n".join(lines) | |
| def main() -> int: | |
| if not STATUS.exists(): | |
| print("missing derived/STATUS.json — run make dashboard first", file=sys.stderr) | |
| return 1 | |
| if not README.exists(): | |
| return 0 | |
| text = README.read_text() | |
| # Bellard-style READMEs have no status anchors — leave them alone | |
| if START not in text and "## Status" not in text: | |
| print("README has no status anchors — skip") | |
| return 0 | |
| status = json.loads(STATUS.read_text()) | |
| block = build_block(status) | |
| if START in text and END in text: | |
| new = re.sub( | |
| re.escape(START) + r".*?" + re.escape(END), | |
| block, | |
| text, | |
| count=1, | |
| flags=re.S, | |
| ) | |
| else: | |
| # insert after first ## Status heading if present | |
| if "## Status" in text: | |
| new = re.sub( | |
| r"(## Status\n)", | |
| r"\1\n" + block + "\n", | |
| text, | |
| count=1, | |
| ) | |
| else: | |
| new = text.rstrip() + "\n\n## Status\n\n" + block + "\n" | |
| if new != text: | |
| README.write_text(new) | |
| print("✓ README status section synced") | |
| else: | |
| print("README status already current") | |
| return 0 | |
| if __name__ == "__main__": | |
| raise SystemExit(main()) | |