"""Emit the static Space: index.html + style.css. No server, no container. The chart is pre-rendered to SVG here and the numbers ride along in the page as JSON, so the browser has everything it needs on first paint. The only script is a few lines to pin the hover box on click. Usage: python3 fetch_data.py # refresh the numbers python3 build_static.py # rebuild index.html and style.css """ from __future__ import annotations import json from pathlib import Path import render HERE = Path(__file__).parent # Static hosting serves the page directly, so unlike the Gradio build the click # handler is just a script — nothing strips it. PIN_JS = """ (function () { "use strict"; document.addEventListener("click", function (e) { if (e.target.closest(".tts-rel")) return; // logos are links var slot = e.target.closest(".tts-slot"); document.querySelectorAll(".tts-slot.is-pinned").forEach(function (s) { if (s !== slot) s.classList.remove("is-pinned"); }); if (!slot) return; var pinned = slot.classList.toggle("is-pinned"); if (!pinned && slot.blur) slot.blur(); // else :focus keeps it open }); document.addEventListener("keydown", function (e) { if (e.key !== "Escape") return; document.querySelectorAll(".tts-slot.is-pinned").forEach(function (s) { s.classList.remove("is-pinned"); }); }); })(); """ PAGE_CSS = """ /* the page is the whole document here, not a component inside a framework */ * { box-sizing: border-box; } html, body { margin: 0; padding: 0; } body { background: #ffffff; color: #111111; font-family: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif; -webkit-font-smoothing: antialiased; } .tts-page { max-width: 1080px; margin: 0 auto; padding: 26px 24px 30px; } @media (max-width: 600px) { .tts-page { padding: 18px 14px 22px; } } """ def main() -> None: d = render.load() releases = [r for r in render.load_releases() if r["date"][:7] >= render.START_MONTH] (HERE / "style.css").write_text( PAGE_CSS.lstrip() + "\n" + render.CSS.strip() + "\n\n" + render.month_css(d, releases) + "\n" ) page = render.build_page(d, releases) html = f""" {render.esc(render.TASK["title"])}
{page}
""" (HERE / "index.html").write_text(html) print(f"index.html {len(html):,} bytes") print(f"style.css {(HERE / 'style.css').stat().st_size:,} bytes") print(f"{d['total']:,} models · {len(releases)} landmark releases · as of {d['retrieved']}") if __name__ == "__main__": main()