jfaustin commited on
Commit
e557ff0
·
1 Parent(s): 86d28da

Add caching to the instance

Browse files
Files changed (1) hide show
  1. app.py +17 -12
app.py CHANGED
@@ -1,4 +1,4 @@
1
- import uuid
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 = str(uuid.uuid4())
56
  output_dir = Path(f"sequence_{seq_id}")
57
  output_dir.mkdir(parents=True, exist_ok=True)
58
 
59
- # Run Boltz prediction
60
- logger.info(f"Predicting {seq_file.stem} with project code {FOLDING_PROJECT_CODE}")
61
- boltz_predict(
62
- source=seq_file,
63
- project_code=FOLDING_PROJECT_CODE,
64
- output=output_dir,
65
- unzip=True
66
- )
67
- logger.info("Prediction done. Output directory: %s", output_dir)
 
 
 
 
 
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")