Files
surya-ocr/scripts/quant/aggregate.py
T
Fu DaiandClaude Opus 4.8 1a585693be Suya OCR API — vLLM-backed, OpenAI-compatible OCR service
FastAPI service wrapping the Surya-OCR-2 model (datalab-to) served through vLLM:
legacy /v1/api/ai/* endpoints, an OpenAI-compatible /v1/chat/completions endpoint,
a coalescing request batcher, a local OCR CLI, Docker packaging, multilingual
example outputs, and quantization/concurrency benchmarks.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-17 10:20:02 +04:00

60 lines
1.4 KiB
Python

"""Summary-row contract and rendering to CSV + markdown."""
from __future__ import annotations
import csv
import io
from typing import Any, Dict, List
SUMMARY_FIELDS = [
"method",
"status",
"t4_deployable",
"model_size_mb",
"mean_latency_s",
"p50_latency_s",
"p95_latency_s",
"throughput_rps",
"decode_tok_s",
"mean_cer",
"max_cer",
"mean_bbox_iou",
"mean_missed_lines",
"mean_extra_lines",
"error",
]
def build_row(**kwargs: Any) -> Dict[str, Any]:
unknown = set(kwargs) - set(SUMMARY_FIELDS)
if unknown:
raise KeyError(f"unknown summary field(s): {sorted(unknown)}")
row = {field: None for field in SUMMARY_FIELDS}
row.update(kwargs)
return row
def rows_to_csv(rows: List[Dict[str, Any]]) -> str:
buf = io.StringIO()
writer = csv.DictWriter(buf, fieldnames=SUMMARY_FIELDS)
writer.writeheader()
for row in rows:
writer.writerow(row)
return buf.getvalue()
def _fmt(value: Any) -> str:
if value is None:
return ""
if isinstance(value, float):
return f"{value:.4f}"
return str(value)
def rows_to_markdown(rows: List[Dict[str, Any]]) -> str:
header = "| " + " | ".join(SUMMARY_FIELDS) + " |"
sep = "| " + " | ".join("---" for _ in SUMMARY_FIELDS) + " |"
lines = [header, sep]
for row in rows:
lines.append("| " + " | ".join(_fmt(row[f]) for f in SUMMARY_FIELDS) + " |")
return "\n".join(lines)