File size: 652 Bytes
328f62b 166c0b2 328f62b 166c0b2 328f62b 166c0b2 328f62b 166c0b2 328f62b 166c0b2 |
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 |
# utils_viz.py
import io
import matplotlib.pyplot as plt
# utils_viz.py
import io
import matplotlib.pyplot as plt
from PIL import Image # ← add this import
def bar_topk(top_rows):
labels = [r["name"] for r in top_rows]
vals = [r["score"] for r in top_rows]
fig, ax = plt.subplots(figsize=(7, 3))
ax.barh(labels[::-1], vals[::-1])
ax.set_xlabel("Score")
ax.set_xlim(0, 100)
fig.tight_layout()
bio = io.BytesIO()
fig.savefig(bio, format="png", dpi=160, bbox_inches="tight")
plt.close(fig)
bio.seek(0)
# Return a PIL Image (what gr.Image(type="pil") wants)
return Image.open(bio).convert("RGB")
|