"""Render the share card and the icons with a real browser. python docs/og/render.py [--fig path/to/figure.svg] Writes docs/og/og-1200x630.png (the Open Graph / Twitter card), favicon-32.png and apple-touch-icon-180.png, plus og-preview-600.png -- the card downscaled to the width Slack and X show it at, so legibility is checked by looking, not assumed. The card is an HTML page in the strands system (static/tokens.css, dark palette): frog mark and pixel wordmark, the title, the one-line promise, and the hero's concept figure in its static frame (reduced-motion). The figure is the hero lane's `docs/img/decider-concept.svg` when it exists, else landing.figure_svg(); --fig overrides. Fonts are the self-hosted woff2. Nothing here loads a model. """ from __future__ import annotations import argparse import base64 import sys from pathlib import Path ROOT = Path(__file__).resolve().parents[2] OUT = Path(__file__).resolve().parent STATIC = ROOT / "static" TITLE = "Strands Decider Playground" LINE = "One question, every decider." SUB = "7 public StrandsAgents deciders answer the same question side by side — with a probability, a confidence and a cost." def _font_face(name: str, file: str, weight: str) -> str: b64 = base64.b64encode((STATIC / "fonts" / file).read_bytes()).decode("ascii") return (f'@font-face{{font-family:"{name}";font-weight:{weight};font-style:normal;' f'src:url("data:font/woff2;base64,{b64}") format("woff2")}}') def figure_svg(path: Path | None) -> str: if path is None: cand = ROOT / "docs" / "img" / "decider-concept.svg" if cand.exists(): path = cand if path is not None: return path.read_text(encoding="utf-8") sys.path.insert(0, str(ROOT)) import landing # noqa: E402 return landing.figure_svg() if hasattr(landing, "figure_svg") else "" def card_html(fig: str, fig_css: str, n_models: int) -> str: tokens = (STATIC / "tokens.css").read_text(encoding="utf-8") mark = (STATIC / "mark.svg").read_text(encoding="utf-8").replace("
{mark}{word}/decider-playground

One question.
Every decider.

{sub}

{fig}
huggingface.co/spaces/cagataydev/strands-decider-playground
""" def icons_html() -> str: mark = (STATIC / "mark.svg").read_text(encoding="utf-8") return (f'' f'
{mark}
{mark}
') def main() -> int: ap = argparse.ArgumentParser() ap.add_argument("--fig", type=Path, default=None, help="svg to place on the card (default: docs/img/decider-concept.svg or landing.figure_svg())") ap.add_argument("--fig-css", type=Path, default=None, help="extra css for the figure (default: static/landing.css)") ap.add_argument("--models", type=int, default=0, help="public model count for the subtitle (0 = keep the text as is)") a = ap.parse_args() from playwright.sync_api import sync_playwright fig = figure_svg(a.fig) css_path = a.fig_css or (STATIC / "landing.css") fig_css = css_path.read_text(encoding="utf-8") if css_path.exists() else "" (OUT / "card.html").write_text(card_html(fig, fig_css, a.models), encoding="utf-8") with sync_playwright() as p: b = p.chromium.launch() ctx = b.new_context(viewport={"width": 1200, "height": 630}, device_scale_factor=1, color_scheme="dark", reduced_motion="reduce") pg = ctx.new_page() pg.goto((OUT / "card.html").as_uri()); pg.wait_for_timeout(600) pg.screenshot(path=str(OUT / "og-1200x630.png"), clip={"x": 0, "y": 0, "width": 1200, "height": 630}) # the size Slack/X show it at ctx2 = b.new_context(viewport={"width": 1200, "height": 630}, device_scale_factor=0.5, color_scheme="dark", reduced_motion="reduce") pg2 = ctx2.new_page(); pg2.goto((OUT / "card.html").as_uri()); pg2.wait_for_timeout(400) pg2.screenshot(path=str(OUT / "og-preview-600.png")) pg3 = b.new_page(viewport={"width": 300, "height": 300}); pg3.set_content(icons_html()); pg3.wait_for_timeout(200) pg3.locator("#a").screenshot(path=str(OUT / "favicon-32.png")) pg3.locator("#b").screenshot(path=str(OUT / "apple-touch-icon-180.png")) b.close() (OUT / "card.html").unlink() for f in ("og-1200x630.png", "og-preview-600.png", "favicon-32.png", "apple-touch-icon-180.png"): print(f"{f}: {(OUT / f).stat().st_size:,} bytes") return 0 if __name__ == "__main__": raise SystemExit(main())