-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrender_tables.py
More file actions
73 lines (55 loc) · 2.08 KB
/
render_tables.py
File metadata and controls
73 lines (55 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
"""
Render HTML table snippets from llms.json and asrs.json.
Usage:
python render_tables.py
python render_tables.py --llm-json llm/llms.json --asr-json asr/asrs.json
"""
import argparse
import json
from pathlib import Path
from jinja2 import Environment, FileSystemLoader
def fmt(value) -> str:
if value is None:
return "—"
if isinstance(value, float):
return f"{value:.4f}"
return str(value)
def fmt_pct(value) -> str:
if value is None:
return "—"
return f"{value:.1f}%"
def fmt_params(row) -> str:
params_b = row.get("params_b")
memory_gb = row.get("memory_gb")
if params_b is None:
return "—"
mem = f"{memory_gb:.1f}GB" if memory_gb is not None else "?"
if params_b < 1:
size = f"{params_b * 1000:.0f}M"
else:
size = f"{params_b:.0f}B"
return f"{size} ({mem})"
def render(json_path: Path, template_path: Path, out: Path) -> None:
data = json.loads(json_path.read_text())
col_labels = data["text"]
rows = data["data"]
cols = [k for k in col_labels if k != "model" and k not in ("cloud", "params_b", "memory_gb")]
env = Environment(loader=FileSystemLoader(str(template_path.parent)))
env.filters["fmt"] = fmt
env.filters["fmt_pct"] = fmt_pct
env.filters["fmt_params"] = fmt_params
template = env.get_template(template_path.name)
html = template.render(rows=rows, cols=cols, col_labels=col_labels)
out.write_text(html, encoding="utf-8")
print(f"Saved to {out}")
def main():
parser = argparse.ArgumentParser(description="Render table HTML from JSON")
parser.add_argument("--llm-json", default="llm/llms.json")
parser.add_argument("--asr-json", default="asr/asrs.json")
parser.add_argument("--llm-out", default="llm/llms_table.html")
parser.add_argument("--asr-out", default="asr/asrs_table.html")
args = parser.parse_args()
render(Path(args.llm_json), Path("llm/table_template.jinja"), Path(args.llm_out))
render(Path(args.asr_json), Path("asr/table_template.jinja"), Path(args.asr_out))
if __name__ == "__main__":
main()