Delower commited on
Commit
dfd2042
·
verified ·
1 Parent(s): ee82dfc

Upload infer.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. infer.py +34 -0
infer.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # infer.py — Liver ExtraTrees deployment model (Arch3 winner, refit).
2
+ # Predicts the probability of the DILI-toxic class for one molecule.
3
+ #
4
+ # Usage:
5
+ # python3 infer.py "CCO" -> prints the probability
6
+ # from infer import predict; predict("CCO")
7
+ #
8
+ # Requires: scikit-learn, rdkit, joblib, numpy, and deployment_common.py
9
+ # (shipped in this repo) on the import path — the shipped preprocessing
10
+ # object (DescPrep) unpickles against that module.
11
+ import os, sys
12
+
13
+ HERE = os.path.dirname(os.path.abspath(__file__))
14
+ sys.path.insert(0, HERE)
15
+
16
+ import numpy as np
17
+ import joblib
18
+ from deployment_common import featurize, prep_matrix
19
+
20
+ _bundle = joblib.load(os.path.join(HERE, "model.joblib"))
21
+ _model, _prep = _bundle["model"], _bundle["prep"]
22
+
23
+
24
+ def predict(smiles):
25
+ """Probability of the toxic (DILI-concern) class; None if unparseable."""
26
+ blocks, valid = featurize([smiles])
27
+ if not bool(valid[0]):
28
+ return None
29
+ X = prep_matrix(blocks, _prep, "fp_desc")
30
+ return float(_model.predict_proba(X)[0, 1])
31
+
32
+
33
+ if __name__ == "__main__":
34
+ print(predict(sys.argv[1]))