Instructions to use Delower/liver-extratrees-deployment with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Scikit-learn
How to use Delower/liver-extratrees-deployment with Scikit-learn:
from huggingface_hub import hf_hub_download import joblib model = joblib.load( hf_hub_download("Delower/liver-extratrees-deployment", "sklearn_model.joblib") ) # only load pickle files from sources you trust # read more about it here https://skops.readthedocs.io/en/stable/persistence.html - Notebooks
- Google Colab
- Kaggle
Upload infer.py with huggingface_hub
Browse files
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]))
|