Drug toxicity prediction app built with Streamlit, scikit-learn, XGBoost, and SHAP.
ToxiScan AI predicts whether a compound is likely Toxic or Non-Toxic using a model trained on the Tox21 dataset. It supports single-compound input, batch CSV scoring, model comparison, and optional AI-generated interpretation via the Inception API.
- Single-compound prediction with probability and risk level (Low, Medium, High)
- Batch CSV prediction for many compounds at once
- Two model choices in the UI: XGBoost and Random Forest
- Feature-importance and SHAP visualization support
- Optional Inception API summary for model output interpretation
- Built-in analytics and comparison dashboards
- Predict: manual entry of descriptor values
- Batch Upload: upload CSV, score compounds, download results
- Analytics: feature importance and SHAP/dataset image panels
- Model Comparison: RF vs XGB metrics and architecture summary
- About: system overview and stack summary
ToxiScan AI/
├─ app.py
├─ README.md
├─ requirements.txt
├─ data/
│ └─ .gitkeep
├─ model/
│ ├─ __init__.py
│ ├─ feature_names.pkl
│ ├─ metrics.json
│ ├─ model.pkl
│ ├─ predict.py
│ ├─ rf_model.pkl
│ ├─ scaler.pkl
│ ├─ train.py
│ └─ xgb_model.pkl
└─ notebooks/
└─ ToxiScan_Training.ipynb
Note: files like model artifacts and charts may be regenerated depending on your training flow.
- Load Tox21 data (KaggleHub download, with local CSV fallback).
- Build target label
is_toxicfrom assay columns. - Train both Random Forest and XGBoost models.
- Save model artifacts to
model/. - Serve inference through Streamlit UI (
app.py). - Optionally call Inception API for narrative toxicity insights.
- Python 3.10+
- pip
- Internet access for KaggleHub dataset download (or local CSV in
data/tox21.csv)
From the project root:
pip install -r requirements.txtCreate a .env file in the project root if you want AI-generated text insights:
INCEPTION_API_KEY=your_api_key_hereIf the key is missing, predictions still work; only the Inception insight panel is disabled.
Open and run:
notebooks/ToxiScan_Training.ipynb
python model/train.pyThe script trains both models and saves artifacts to model/:
rf_model.pklxgb_model.pklmodel.pkl(default fallback)scaler.pklfeature_names.pkl
streamlit run app.pyThen open the local URL shown by Streamlit (typically http://localhost:8501).
For batch mode, your CSV should contain feature columns matching the names in model/feature_names.pkl.
App output columns include:
prediction(0/1)label(ToxicorNon-Toxic)probability(class-1 probability)risk_level(Low,Medium,High)
Tip: the Batch Upload page provides a sample template download.
Current metrics are read from model/metrics.json and displayed in the UI.
At the time of writing, model/metrics.json contains:
- Random Forest: accuracy 1.000, ROC-AUC 1.000, F1 1.000
- XGBoost: accuracy 1.000, ROC-AUC 1.000, F1 1.000
- Samples: 7,831
- Features: 12
These values can change after retraining with different data splits or preprocessing.
The Analytics page can display the following files if present in project root:
shap_summary.pngshap_waterfall.pngeda_overview.pngmodel_evaluation.png
If they are missing, run the notebook/training flow that generates them.
- Models not found in app:
- Train with
python model/train.pyor run the notebook and place artifacts inmodel/.
- Train with
- Dataset download fails:
- Put
tox21.csvindata/and rerun training.
- Put
- Inception insight errors:
- Check
INCEPTION_API_KEYand network access.
- Check
- Batch upload fails:
- Ensure CSV columns align with
feature_names.pkl.
- Ensure CSV columns align with
This project is for research/educational use only and is not a medical or regulatory decision system.