CoolFace
Apppublic

Nikhil1417/Ann-Drift-detection

sourceHugging Faceupdated 7mo agoView on Hugging Face
0likes
App README

๐Ÿ” ModelShift Monitor

A lightweight, end-to-end data drift detection tool built with a pre-trained autoencoder, a FastAPI inference backend, and a Streamlit frontend.

Upload any CSV โ€” ModelShift scores each row against the training distribution and tells you whether your live data has drifted.


๐Ÿ—‚๏ธ Project Structure

ModelShift-Monitor/
โ”œโ”€โ”€ app.py                  # Streamlit UI
โ”œโ”€โ”€ main.py                 # FastAPI backend
โ”œโ”€โ”€ requirements.txt
โ”œโ”€โ”€ runtime.txt
โ”œโ”€โ”€ .streamlit/
โ”‚   โ””โ”€โ”€ config.toml         # UI theme
โ”œโ”€โ”€ .devcontainer/
โ”‚   โ””โ”€โ”€ devcontainer.json   # VS Code dev container
โ””โ”€โ”€ model/
    โ”œโ”€โ”€ autoencoder_drift_model.h5
    โ”œโ”€โ”€ scaler.pkl
    โ”œโ”€โ”€ feature_columns.pkl
    โ””โ”€โ”€ drift_threshold.json

โš™๏ธ How It Works

  1. 1.Autoencoder โ€” trained on the original (clean) dataset to learn its distribution.
  2. 2.Reconstruction error โ€” for each incoming row, the model attempts to reconstruct it. High error โ†’ the sample is out-of-distribution.
  3. 3.Drift ratio โ€” the fraction of samples whose error exceeds the calibrated threshold.
  4. 4.Decision โ€” if more than 30 % of samples exceed the threshold, drift is flagged.

๐Ÿš€ Running Locally

1 โ€” Install dependencies

bash
pip install -r requirements.txt

2 โ€” Start the FastAPI backend

bash
uvicorn main:api --reload --port 8000

3 โ€” Launch the Streamlit app

bash
streamlit run app.py

Open http://localhost:8501 in your browser.


๐ŸŒ API Endpoints

MethodEndpointDescription
POST/detect_driftReturns drift_ratio and drift_detected flag
POST/diagnosticsReturns mean error, p95 error, and threshold

Example request body

json
{
  "columns": ["feature_1", "feature_2"],
  "data": [[0.5, 1.2], [0.9, 0.3]]
}

Example response (/detect_drift)

json
{
  "drift_ratio": 0.12,
  "drift_detected": false
}

๐Ÿงฉ Tech Stack

LayerTechnology
ML modelTensorFlow / Keras Autoencoder
Preprocessingscikit-learn StandardScaler
Backend APIFastAPI + Uvicorn
FrontendStreamlit
DeploymentHugging Face Spaces

๐Ÿ“Œ Notes

  • โ€”Input CSV must contain numeric columns that overlap with the training feature set.
  • โ€”Rows are capped at 1 000 before inference for latency reasons.
  • โ€”The hosted backend is on Hugging Face Spaces and may cold-start โ€” allow ~30 s on the first request.