Spaces:
Running
Running
Update app.py
Browse files
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)
|
| 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)
|