AlGe commited on
Commit
4a784d9
·
verified ·
1 Parent(s): 760d9b0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -2
app.py CHANGED
@@ -150,8 +150,13 @@ def generate_wordcloud(entities: List[Dict], color_map: Dict[str, str], file_pat
150
 
151
  plt_image = plt.gcf()
152
  plt_image.canvas.draw()
153
- image_array = np.frombuffer(plt_image.canvas.tostring_rgb(), dtype=np.uint8)
154
- image_array = image_array.reshape(plt_image.canvas.get_width_height()[::-1] + (3,))
 
 
 
 
 
155
  plt.close()
156
 
157
  return image_array
 
150
 
151
  plt_image = plt.gcf()
152
  plt_image.canvas.draw()
153
+ #image_array = np.frombuffer(plt_image.canvas.tostring_rgb(), dtype=np.uint8)
154
+ #image_array = image_array.reshape(plt_image.canvas.get_width_height()[::-1] + (3,))
155
+ # Get the RGBA buffer directly as a (height, width, 4) numpy array
156
+ image_array_rgba = np.asarray(plt_image.canvas.buffer_rgba())
157
+
158
+ # Keep only the RGB channels (slice off the Alpha channel)
159
+ image_array = image_array_rgba[:, :, :3]
160
  plt.close()
161
 
162
  return image_array