openfree commited on
Commit
c3c2c75
·
verified ·
1 Parent(s): ccf64c2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -5
app.py CHANGED
@@ -162,13 +162,14 @@ class Visualization:
162
 
163
  plt.tight_layout()
164
 
165
- # Convert matplotlib figure to PIL Image
166
- fig.canvas.draw()
167
- img_array = np.frombuffer(fig.canvas.tostring_rgb(), dtype=np.uint8)
168
- img_array = img_array.reshape(fig.canvas.get_width_height()[::-1] + (3,))
 
169
  plt.close(fig)
170
 
171
- return Image.fromarray(img_array)
172
 
173
  def download_dataset():
174
  """Download the dataset using kagglehub"""
 
162
 
163
  plt.tight_layout()
164
 
165
+ # Save to BytesIO and convert to PIL Image
166
+ buf = BytesIO()
167
+ fig.savefig(buf, format='png', dpi=100, bbox_inches='tight')
168
+ buf.seek(0)
169
+ img = Image.open(buf)
170
  plt.close(fig)
171
 
172
+ return img
173
 
174
  def download_dataset():
175
  """Download the dataset using kagglehub"""