wi-lab commited on
Commit
5fc4eb8
·
verified ·
1 Parent(s): f23306e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -3
app.py CHANGED
@@ -357,13 +357,20 @@ def plot_confusion_matrix(y_true, y_pred, title, save_path="confusion_matrix.png
357
  plt.xlabel('Predicted label', color=text_color, fontsize=12)
358
  plt.tight_layout()
359
 
360
- # Save the plot as an image
361
- plt.savefig(save_path, transparent=True) # Transparent to blend with website background
362
  plt.close()
363
 
 
 
 
 
 
 
 
364
  # Return the saved image
365
  return Image.open(save_path)
366
-
367
  def identical_train_test_split(output_emb, output_raw, labels, train_percentage):
368
  N = output_emb.shape[0]
369
  indices = torch.randperm(N)
 
357
  plt.xlabel('Predicted label', color=text_color, fontsize=12)
358
  plt.tight_layout()
359
 
360
+ # Save the plot as an image, ensure the image is fully written
361
+ plt.savefig(save_path, bbox_inches='tight', transparent=True)
362
  plt.close()
363
 
364
+ # Ensure the file is properly written and synced to disk before opening
365
+ time.sleep(0.5) # Add a small delay to ensure file writing is complete
366
+
367
+ # Check if the file exists and can be opened
368
+ if not os.path.exists(save_path):
369
+ raise FileNotFoundError(f"File {save_path} not found.")
370
+
371
  # Return the saved image
372
  return Image.open(save_path)
373
+
374
  def identical_train_test_split(output_emb, output_raw, labels, train_percentage):
375
  N = output_emb.shape[0]
376
  indices = torch.randperm(N)