File size: 387 Bytes
179dfc2
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
"""Format `model.predict_topk` tuples for Gradio summaries and JSON."""
from __future__ import annotations

from typing import Any


def topk_tuples_to_ui_items(rows: list[tuple[str, float]]) -> list[dict[str, Any]]:
    """Match legacy Gradio `_topk` shape: `label` + `prob` rounded to 4 decimals."""
    return [{"label": label, "prob": round(float(prob), 4)} for label, prob in rows]