AI4deeperScience commited on
Commit
b3e8081
·
verified ·
1 Parent(s): 895c2c6

Guard PyG import; use PyGBatch alias

Browse files
Files changed (1) hide show
  1. app.py +16 -2
app.py CHANGED
@@ -26,6 +26,14 @@ from PIL import Image
26
  ROOT = Path(__file__).parent
27
  sys.path.insert(0, str(ROOT))
28
 
 
 
 
 
 
 
 
 
29
  from src.models.biointeract import BioInteract
30
  from src.data.mol_graph import smiles_to_graph
31
  from src.data.protein_feat import residue_physicochemical_features, residue_domain_labels
@@ -291,14 +299,20 @@ def run_prediction(smiles: str, sequence: str, progress=gr.Progress()):
291
  if not sequence:
292
  return "Please enter a protein sequence (amino acids).", "", None, None
293
 
 
 
 
 
 
 
 
294
  # --- Drug graph ---
295
  progress(0.1, desc="Parsing SMILES …")
296
  drug_graph = smiles_to_graph(smiles)
297
  if drug_graph is None:
298
  return "Invalid SMILES string — RDKit could not parse it.", "", None, None
299
 
300
- from torch_geometric.data import Batch
301
- drug_batch = Batch.from_data_list([drug_graph]).to(DEVICE)
302
 
303
  # --- Protein features ---
304
  seq = sequence[:MAX_SEQ_LEN]
 
26
  ROOT = Path(__file__).parent
27
  sys.path.insert(0, str(ROOT))
28
 
29
+ # torch-geometric import guard: provide useful error if wheels missing
30
+ try:
31
+ from torch_geometric.data import Batch as PyGBatch
32
+ PYGEOMETRIC_AVAILABLE = True
33
+ except ImportError as _pyg_err:
34
+ PYGEOMETRIC_AVAILABLE = False
35
+ _pyg_err_msg = str(_pyg_err)
36
+
37
  from src.models.biointeract import BioInteract
38
  from src.data.mol_graph import smiles_to_graph
39
  from src.data.protein_feat import residue_physicochemical_features, residue_domain_labels
 
299
  if not sequence:
300
  return "Please enter a protein sequence (amino acids).", "", None, None
301
 
302
+ if not PYGEOMETRIC_AVAILABLE:
303
+ return (
304
+ f"torch-geometric is not available in this environment: {_pyg_err_msg}. "
305
+ "Please use the Case Studies tab for pre-computed results.",
306
+ "", None, None
307
+ )
308
+
309
  # --- Drug graph ---
310
  progress(0.1, desc="Parsing SMILES …")
311
  drug_graph = smiles_to_graph(smiles)
312
  if drug_graph is None:
313
  return "Invalid SMILES string — RDKit could not parse it.", "", None, None
314
 
315
+ drug_batch = PyGBatch.from_data_list([drug_graph]).to(DEVICE)
 
316
 
317
  # --- Protein features ---
318
  seq = sequence[:MAX_SEQ_LEN]