Spaces:
Running
on
Zero
Running
on
Zero
Anton Bushuiev
commited on
Commit
·
ec017a6
1
Parent(s):
d27d885
Use temporary copy of input file
Browse files
app.py
CHANGED
|
@@ -449,10 +449,12 @@ def _predict_core(lib_pth, in_pth, calculate_modified_cosine, progress):
|
|
| 449 |
# Clear cache at start to prevent memory buildup
|
| 450 |
clear_smiles_cache()
|
| 451 |
|
| 452 |
-
# Create temporary
|
| 453 |
-
progress(0, desc="Creating temporary
|
| 454 |
temp_lib_path = Path(lib_pth).parent / f"temp_{datetime.now().strftime('%Y%m%d_%H%M%S')}_{Path(lib_pth).name}"
|
|
|
|
| 455 |
shutil.copy2(lib_pth, temp_lib_path)
|
|
|
|
| 456 |
|
| 457 |
try:
|
| 458 |
# Load library data
|
|
@@ -462,7 +464,7 @@ def _predict_core(lib_pth, in_pth, calculate_modified_cosine, progress):
|
|
| 462 |
print(f'Shape of the library embeddings: {embs_lib.shape}')
|
| 463 |
|
| 464 |
# Get query embeddings
|
| 465 |
-
embs = _predict_gpu(
|
| 466 |
|
| 467 |
# Compute similarity matrix
|
| 468 |
progress(0.4, desc="Computing similarity matrix...")
|
|
@@ -474,7 +476,7 @@ def _predict_core(lib_pth, in_pth, calculate_modified_cosine, progress):
|
|
| 474 |
topk_cands = np.argsort(sims, axis=1)[:, -k:][:, ::-1]
|
| 475 |
|
| 476 |
# Load query data for processing
|
| 477 |
-
msdata = MSData.load(
|
| 478 |
print(f'Available columns: {msdata.columns()}')
|
| 479 |
|
| 480 |
# Construct results DataFrame
|
|
@@ -506,9 +508,11 @@ def _predict_core(lib_pth, in_pth, calculate_modified_cosine, progress):
|
|
| 506 |
return df, csv_path
|
| 507 |
|
| 508 |
finally:
|
| 509 |
-
# Clean up temporary
|
| 510 |
if temp_lib_path.exists():
|
| 511 |
temp_lib_path.unlink()
|
|
|
|
|
|
|
| 512 |
|
| 513 |
|
| 514 |
def predict(lib_pth, in_pth, calculate_modified_cosine=False, progress=gr.Progress(track_tqdm=True)):
|
|
|
|
| 449 |
# Clear cache at start to prevent memory buildup
|
| 450 |
clear_smiles_cache()
|
| 451 |
|
| 452 |
+
# Create temporary copies of library and input files to allow multiple processes
|
| 453 |
+
progress(0, desc="Creating temporary file copies...")
|
| 454 |
temp_lib_path = Path(lib_pth).parent / f"temp_{datetime.now().strftime('%Y%m%d_%H%M%S')}_{Path(lib_pth).name}"
|
| 455 |
+
temp_in_path = in_pth.parent / f"temp_{datetime.now().strftime('%Y%m%d_%H%M%S')}_{in_pth.name}"
|
| 456 |
shutil.copy2(lib_pth, temp_lib_path)
|
| 457 |
+
shutil.copy2(in_pth, temp_in_path)
|
| 458 |
|
| 459 |
try:
|
| 460 |
# Load library data
|
|
|
|
| 464 |
print(f'Shape of the library embeddings: {embs_lib.shape}')
|
| 465 |
|
| 466 |
# Get query embeddings
|
| 467 |
+
embs = _predict_gpu(temp_in_path, progress)
|
| 468 |
|
| 469 |
# Compute similarity matrix
|
| 470 |
progress(0.4, desc="Computing similarity matrix...")
|
|
|
|
| 476 |
topk_cands = np.argsort(sims, axis=1)[:, -k:][:, ::-1]
|
| 477 |
|
| 478 |
# Load query data for processing
|
| 479 |
+
msdata = MSData.load(temp_in_path, in_mem=True)
|
| 480 |
print(f'Available columns: {msdata.columns()}')
|
| 481 |
|
| 482 |
# Construct results DataFrame
|
|
|
|
| 508 |
return df, csv_path
|
| 509 |
|
| 510 |
finally:
|
| 511 |
+
# Clean up temporary files
|
| 512 |
if temp_lib_path.exists():
|
| 513 |
temp_lib_path.unlink()
|
| 514 |
+
if temp_in_path.exists():
|
| 515 |
+
temp_in_path.unlink()
|
| 516 |
|
| 517 |
|
| 518 |
def predict(lib_pth, in_pth, calculate_modified_cosine=False, progress=gr.Progress(track_tqdm=True)):
|