# 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")