Delower's picture
Upload infer.py with huggingface_hub
dfd2042 verified
Raw History Blame Contribute Delete
1.09 kB
# infer.py — Liver ExtraTrees deployment model (Arch3 winner, refit).
# Predicts the probability of the DILI-toxic class for one molecule.
#
# Usage:
# python3 infer.py "CCO" -> prints the probability
# from infer import predict; predict("CCO")
#
# Requires: scikit-learn, rdkit, joblib, numpy, and deployment_common.py
# (shipped in this repo) on the import path — the shipped preprocessing
# object (DescPrep) unpickles against that module.
import os, sys
HERE = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, HERE)
import numpy as np
import joblib
from deployment_common import featurize, prep_matrix
_bundle = joblib.load(os.path.join(HERE, "model.joblib"))
_model, _prep = _bundle["model"], _bundle["prep"]
def predict(smiles):
"""Probability of the toxic (DILI-concern) class; None if unparseable."""
blocks, valid = featurize([smiles])
if not bool(valid[0]):
return None
X = prep_matrix(blocks, _prep, "fp_desc")
return float(_model.predict_proba(X)[0, 1])
if __name__ == "__main__":
print(predict(sys.argv[1]))