Skip to content
Β 
Β 

Latest commit

Β 

History

19 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

XAI Manufacturing Inspector Pro

An Explainable AI (XAI) system for automated surface defect detection in manufacturing β€” providing transparent, human-readable decision-making for quality assurance.


🧠 What It Does

XAI Manufacturing Inspector Pro takes real-time sensor readings from industrial machines and predicts whether a machine is likely to pass or fail quality inspection. More importantly, it explains why β€” using SHAP and LIME to break down which sensor readings are driving the risk, and providing actionable maintenance recommendations.


✨ Features

  • Real-time failure prediction β€” XGBoost classifier trained on 7 sensor inputs
  • Explainable AI (XAI) β€” SHAP TreeExplainer + LIME for transparent predictions
  • Sensor impact analysis β€” Ranked feature contributions with directional reasoning
  • Actionable recommendations β€” Specific maintenance guidance based on sensor thresholds
  • Dataset analytics β€” Correlation heatmap & distribution plots (Matplotlib + Seaborn)
  • Interactive dashboard β€” D3.js & Chart.js powered frontend with KPI cards
  • Multiple ML models β€” Linear/Logistic Regression, Random Forest, Decision Tree, XGBoost

πŸ—‚οΈ Project Structure

XAI-Manufacturing-Inspector-Pro/
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ main.py              # FastAPI app β€” prediction, training & analytics endpoints
β”‚   β”œβ”€β”€ models.py            # ML model training + SHAP/LIME explanation functions
β”‚   β”œβ”€β”€ dataset.py           # Synthetic sensor dataset generation
β”‚   β”œβ”€β”€ predict.py           # Standalone prediction utilities
β”‚   β”œβ”€β”€ train_models.py      # Script to train and save the XGBoost model
β”‚   β”œβ”€β”€ inspect_data.py      # Data inspection helpers
β”‚   └── requirements.txt     # Python dependencies
β”œβ”€β”€ frontend/
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   └── server.js        # Express.js server
β”‚   β”œβ”€β”€ views/               # EJS templates
β”‚   β”œβ”€β”€ public/
β”‚   β”‚   └── js/
β”‚   β”‚       └── charts.js    # D3.js / Chart.js dashboard visualisations
β”‚   └── package.json
β”œβ”€β”€ models/
β”‚   └── xgboost_classifier.joblib   # Saved trained model (generated after training)
└── README.md

βš™οΈ Tech Stack

Layer Technology
ML / XAI Backend Python, FastAPI, XGBoost, scikit-learn, SHAP, LIME
Data & Analytics Pandas, NumPy, Matplotlib, Seaborn
Frontend Server Node.js, Express.js
Templating EJS
Charts / Visuals Chart.js, D3.js
API Communication Axios


πŸš€ Getting Started

Prerequisites

  • Python 3.12+
  • Node.js 18+
  • Docker (optional, for containerised deployment)

1. Local Development Setup

Backend Setup

cd backend

# Install Python dependencies
pip install -r requirements.txt

# Train the XGBoost model (saves to models/xgboost_classifier.joblib)
python train_models.py

# Start the FastAPI server on port 8000
uvicorn main:app --reload --port 8000

Frontend Setup

cd frontend
npm install
npm start

Go to: http://localhost:5000


🐳 Docker Deployment (Recommended)

Run the backend via Docker for a consistent, production-ready environment:

cd backend
docker build -t xai-backend .
docker run -p 8000:8000 xai-backend

🚒 Cloud Deployment

1. Backend (Railway [previously] => Render)

This project is configured for seamless deployment on Railway using the provided backend/Dockerfile.

2. Frontend (Vercel)

Deployed the Express/EJS frontend to Vercel:

πŸ“± Responsiveness

The dashboard is fully responsive and optimized for:

  • πŸ’» Desktop: Full multi-chart grid view.
  • πŸ“± Mobile: Collapsible tables and stacked KPI cards designed for screens as small as 320px (iPhone SE).
  • πŸ“Š Dynamic Scaling: Canvas-based charts (Chart.js) and SVG (D3.js) adjust size automatically.

πŸ“‘ API Endpoints

Method Endpoint Description
GET / Health check
POST /predict Predict failure from sensor readings
POST /train Re-train the XGBoost model on fresh data
GET /dataset-analytics Returns correlation heatmap & distribution plots (base64 PNG)

/predict β€” Request Body

{
  "Temperature": 85.0,
  "Pressure": 95.0,
  "Speed": 1800.0,
  "Vibration": 3.2,
  "Humidity": 45.0,
  "Power_Consumption": 160.0,
  "Material_Hardness": 65.0
}

/predict β€” Response

{
  "status": "Fail",
  "failure_probability": 0.87,
  "prediction": 1,
  "model_confidence": 74.0,
  "top_risk_factor": "Vibration Level",
  "risk_factors_count": 3,
  "weaknesses": ["Vibration Level", "System Temperature", "Internal Pressure"],
  "improvement_plan": ["Inspect bearings for excessive wear..."],
  "explanation": {
    "features": [...],
    "recommendation": "..."
  },
  "detailed_summary": {
    "problem": "...",
    "cause": "...",
    "solution": "..."
  }
}

πŸ”¬ Sensor Thresholds

Sensor Risk Threshold Risk Reason
Temperature > 90 Β°C Thermal expansion / cooling failure
Vibration > 4.0 Bearing wear / spindle misalignment
Power Consumption > 180 W Electrical fault / overload
Pressure > 100 bar Valve blockage / line leak
Speed > 2000 RPM Mechanical stress on moving parts
Humidity > 60 % Corrosion / moisture ingress risk
Material Hardness > 75 Excessive tooling wear

πŸ€– XAI Explainability

  • SHAP (SHapley Additive exPlanations): Uses TreeExplainer to attribute each sensor's contribution to the final prediction, returning a ranked list of feature impacts with direction (positive/negative).
  • LIME (Local Interpretable Model-agnostic Explanations): Fits a locally linear model around the prediction point to produce intuitive, instance-level explanations.

πŸ“Š Analytics

The /dataset-analytics endpoint returns two charts:

  1. Sensor Correlation Heatmap β€” shows which sensors correlate with each other and with failure
  2. Temperature & Vibration KDE Distribution β€” overlaid density plots comparing Pass vs Fail distributions

πŸ“„ License

This project was developed as a Web Technology semester project (Sem 6).

About

An Explainable AI (XAI) system for automated surface defect detection in manufacturing, providing transparent decision-making for quality assurance.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages