An Explainable AI (XAI) system for automated surface defect detection in manufacturing β providing transparent, human-readable decision-making for quality assurance.
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.
- 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
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
| 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 |
- Python 3.12+
- Node.js 18+
- Docker (optional, for containerised deployment)
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 8000cd frontend
npm install
npm startGo to: http://localhost:5000
Run the backend via Docker for a consistent, production-ready environment:
cd backend
docker build -t xai-backend .
docker run -p 8000:8000 xai-backendThis project is configured for seamless deployment on Railway using the provided backend/Dockerfile.
Deployed the Express/EJS frontend to Vercel:
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.
| 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) |
{
"Temperature": 85.0,
"Pressure": 95.0,
"Speed": 1800.0,
"Vibration": 3.2,
"Humidity": 45.0,
"Power_Consumption": 160.0,
"Material_Hardness": 65.0
}{
"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 | 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 |
- SHAP (SHapley Additive exPlanations): Uses
TreeExplainerto 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.
The /dataset-analytics endpoint returns two charts:
- Sensor Correlation Heatmap β shows which sensors correlate with each other and with failure
- Temperature & Vibration KDE Distribution β overlaid density plots comparing Pass vs Fail distributions
This project was developed as a Web Technology semester project (Sem 6).