# license_curation.py from typing import Any, Dict, List from fastapi import APIRouter from fastapi.responses import HTMLResponse, JSONResponse import html from data import get_pages, ensure_page_loaded, flatten_models, license_label_and_url, is_complete router = APIRouter() def _rows(models: List[Dict[str, Any]]) -> str: from data import model_id out = [] for m in models: mid = html.escape(model_id(m)) label, url = license_label_and_url(m) label_h = html.escape(label or "Unknown") lic_html = f"{label_h}" if url else label_h out.append(f"{mid}{lic_html}") return "\n".join(out) def _counts(models: List[Dict[str, Any]]) -> Dict[str, Any]: total, known, unknown = 0, 0, 0 by_label: Dict[str, int] = {} for m in models: total += 1 label, _ = license_label_and_url(m) if label and label.lower() != "unknown": known += 1 else: unknown += 1 by_label[label] = by_label.get(label, 0) + 1 return {"total": total, "known": known, "unknown": unknown, "by_label": by_label} def _shell(table_rows: str) -> str: return f""" License Curation
License Curation catalog complete: {"yes" if is_complete() else "no"} pages loaded: {len(get_pages())}
{table_rows}
IDLicense

License log

Total models
Known licenses
Unknown licenses
""" @router.get("/licenses", response_class=HTMLResponse) def licenses_page(): if not get_pages(): try: ensure_page_loaded(0) except Exception: pass rows = _rows(flatten_models()) return HTMLResponse(_shell(rows)) @router.get("/licenses/stats") def licenses_stats(): return JSONResponse(_counts(flatten_models()))