Download src/predict_format.py from pdjota/artydemo: direct link, hf CLI and curl.
- Browser
- Download file 387 Bytes
-
https://huggingface.co/spaces/pdjota/artydemo/resolve/main/src/predict_format.py
- Command line
-
hf download hf://spaces/pdjota/artydemo/src/predict_format.py
-
curl -L -o predict_format.py https://huggingface.co/spaces/pdjota/artydemo/resolve/main/src/predict_format.py
387 Bytes
| """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] | |