Spaces:
Running
Running
Download visualization/render.py from Jellyfish042/Compression-Lens: direct link, hf CLI and curl.
- Browser
- Download file 1.54 kB
-
https://huggingface.co/spaces/Jellyfish042/Compression-Lens/resolve/main/visualization/render.py
- Command line
-
hf download hf://spaces/Jellyfish042/Compression-Lens/visualization/render.py
-
curl -L -o render.py https://huggingface.co/spaces/Jellyfish042/Compression-Lens/resolve/main/visualization/render.py
1.54 kB
| """ | |
| Page rendering using a lightweight template. | |
| """ | |
| from pathlib import Path | |
| from string import Template | |
| from typing import Any, Dict | |
| from core.escaping import escape_json_for_script, escape_text_node | |
| _TEMPLATE_PATH = Path(__file__).resolve().parent / "templates" / "page.html.tmpl" | |
| _ASSETS_DIR = Path(__file__).resolve().parent / "assets" | |
| def render_page(context: Dict[str, str]) -> str: | |
| template_text = _TEMPLATE_PATH.read_text(encoding="utf-8") | |
| template = Template(template_text) | |
| return template.safe_substitute(context) | |
| def render_comparison_page(model: Dict[str, Any]) -> str: | |
| """Render the current presentation without changing evaluation data.""" | |
| meta = model["meta"] | |
| return render_page( | |
| { | |
| "page_title": "Compression-Lens: Model Comparison", | |
| "model_a": escape_text_node(meta["model_a"]), | |
| "model_b": escape_text_node(meta["model_b"]), | |
| "rwkv_compression": f'{meta["avg_compression"]["rwkv"]:.2f}', | |
| "qwen_compression": f'{meta["avg_compression"]["qwen"]:.2f}', | |
| "mean_difference": f'{meta["avg_delta_compression"]:+.2f}', | |
| "document_meta": f'{len(model["text"].encode("utf-8")):,} bytes · {len(model["tokens"]):,} segments', | |
| "style_block": "\n".join((_ASSETS_DIR / name).read_text(encoding="utf-8") for name in ("theme.css", "main.css")), | |
| "render_model_json": escape_json_for_script(model), | |
| "script_body": (_ASSETS_DIR / "main.js").read_text(encoding="utf-8"), | |
| } | |
| ) | |