InnerI commited on
Commit
166c0b2
·
verified ·
1 Parent(s): fc6508e

Update utils_viz.py

Browse files
Files changed (1) hide show
  1. utils_viz.py +11 -3
utils_viz.py CHANGED
@@ -2,16 +2,24 @@
2
  import io
3
  import matplotlib.pyplot as plt
4
 
 
 
 
 
 
5
  def bar_topk(top_rows):
6
  labels = [r["name"] for r in top_rows]
7
  vals = [r["score"] for r in top_rows]
8
- fig, ax = plt.subplots(figsize=(7,3))
9
  ax.barh(labels[::-1], vals[::-1])
10
  ax.set_xlabel("Score")
11
- ax.set_xlim(0,100)
12
  fig.tight_layout()
 
13
  bio = io.BytesIO()
14
  fig.savefig(bio, format="png", dpi=160, bbox_inches="tight")
15
  plt.close(fig)
16
  bio.seek(0)
17
- return bio
 
 
 
2
  import io
3
  import matplotlib.pyplot as plt
4
 
5
+ # utils_viz.py
6
+ import io
7
+ import matplotlib.pyplot as plt
8
+ from PIL import Image # ← add this import
9
+
10
  def bar_topk(top_rows):
11
  labels = [r["name"] for r in top_rows]
12
  vals = [r["score"] for r in top_rows]
13
+ fig, ax = plt.subplots(figsize=(7, 3))
14
  ax.barh(labels[::-1], vals[::-1])
15
  ax.set_xlabel("Score")
16
+ ax.set_xlim(0, 100)
17
  fig.tight_layout()
18
+
19
  bio = io.BytesIO()
20
  fig.savefig(bio, format="png", dpi=160, bbox_inches="tight")
21
  plt.close(fig)
22
  bio.seek(0)
23
+
24
+ # Return a PIL Image (what gr.Image(type="pil") wants)
25
+ return Image.open(bio).convert("RGB")