Add caching to the instance
Browse files
app.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
import
|
2 |
import gradio as gr
|
3 |
from pathlib import Path
|
4 |
from Bio.PDB import MMCIFParser, PDBIO
|
@@ -51,20 +51,25 @@ def predict(sequence: str) -> str:
|
|
51 |
seq_file = Path("sequence.fasta")
|
52 |
_write_fasta_file(seq_file, sequence)
|
53 |
|
54 |
-
# Set up unique output directory
|
55 |
-
seq_id =
|
56 |
output_dir = Path(f"sequence_{seq_id}")
|
57 |
output_dir.mkdir(parents=True, exist_ok=True)
|
58 |
|
59 |
-
#
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
|
|
|
|
|
|
|
|
|
|
68 |
|
69 |
# # TODO: remove this
|
70 |
# output_dir = Path("boltz_results")
|
|
|
1 |
+
import hashlib
|
2 |
import gradio as gr
|
3 |
from pathlib import Path
|
4 |
from Bio.PDB import MMCIFParser, PDBIO
|
|
|
51 |
seq_file = Path("sequence.fasta")
|
52 |
_write_fasta_file(seq_file, sequence)
|
53 |
|
54 |
+
# Set up unique output directory based on sequence hash
|
55 |
+
seq_id = hashlib.sha1(sequence.encode()).hexdigest()
|
56 |
output_dir = Path(f"sequence_{seq_id}")
|
57 |
output_dir.mkdir(parents=True, exist_ok=True)
|
58 |
|
59 |
+
# Check if prediction already exists
|
60 |
+
pred_cif = list(output_dir.rglob("*_model_0.cif"))
|
61 |
+
if not pred_cif:
|
62 |
+
# Run Boltz prediction
|
63 |
+
logger.info(f"Predicting {seq_file.stem} with project code {FOLDING_PROJECT_CODE}")
|
64 |
+
boltz_predict(
|
65 |
+
source=seq_file,
|
66 |
+
project_code=FOLDING_PROJECT_CODE,
|
67 |
+
output=output_dir,
|
68 |
+
unzip=True
|
69 |
+
)
|
70 |
+
logger.info("Prediction done. Output directory: %s", output_dir)
|
71 |
+
else:
|
72 |
+
logger.info("Prediction already exists. Output directory: %s", output_dir)
|
73 |
|
74 |
# # TODO: remove this
|
75 |
# output_dir = Path("boltz_results")
|