Safety AI Dashboard is a full-stack AI-powered web application designed to detect Personal Protective Equipment (PPE) compliance violations from images and videos.
The system uses computer vision models (YOLO / Ultralytics) to identify safety violations such as:
- Missing Helmet
- Missing Safety Vest
- Missing Mask
- Other configurable PPE rules
The dashboard provides real-time detection results, violation statistics, compliance calculation, and a clean professional interface.
- Upload PNG, JPG, JPEG, WEBP (max 10MB)
- Detect PPE violations
- Displays:
- Total Detections
- Violations Found
- Compliant Items
- Compliance Rate
- Annotated detection results
- Upload MP4, AVI, MOV, WEBM (max 100MB)
- Frame-by-frame processing
- Displays:
- Frames Processed
- Violations Found
- Compliant Items
- FPS Processed
- This Image and Video detection model was trained in
yoloV8 - The number of epochs = 20
- The batach size = 32
- The dataset was takes from the roboflow website.
- The dataset consisted over 2500+ annotated images
- There was more than 10 classes in the dataset
Built with React and FastAPI, this system automates PPE compliance monitoring through a high-performance pipeline.
-
Frontend Interface: Developed with
Reactproviding a high-performance, responsive dashboard for real-time visualization of compliance metrics and annotated media. -
Core Engine:
FastAPIhandles asynchronous requests and coordinates theYOLO (Ultralytics)model for real-time detection of helmets, vests, and masks. -
Data Persistence: A
PostgreSQLdatabase serves as the central audit log, storing timestamps and violation metadata for historical compliance tracking. -
Intelligent Notifications:
n8nmanages automated workflows, triggering immediate SMS alerts to safety officers when critical violations are identified. -
Infrastructure: Fully containerized using
Dockerfor streamlined deployment toAWSorRender.
The system operates through a strictly defined data pipeline to ensure low latency and high reliability:
-
Ingestion: User uploads are handled by the
Reactfrontend and transmitted via theFetch APIto theFastAPIgateway. -
Inference: The backend triggers the
YOLO(Ultralytics) model to perform object detection for PPE compliance (Helmets, Vests, Masks). -
Persistence (The "Log" Phase): If a violation is detected, the API immediately executes a write operation to the
PostgreSQLdatabase, recording the event timestamp and metadata. -
Automation (The "Alert" Phase): The database entry triggers an
n8nwebhook.n8nthen processes the logic and transmits an immediateSMS notificationto designated safety personnel. -
Visualization: The results are returned to the
Reactdashboard, updating thecompliance rateanddetectionstatistics in real-time.
Explore the Deep Dive: For a comprehensive breakdown of the infrastructure, please checkout System Architecture With Diagram
git clone https://github.com/your-username/safety-ai.git
Get into the root directory
cd safety-ai
docker-compose up --build
Run in background:
docker-compose up -d --build
http://localhost:3000
http://localhost:8001/docs
- First open
cmd promptin the directory - Navigate to backend directory.
cd backend-api
- Create a virtual environment in Python
python -m venv venv
- Activate the virtual environment
venv/bin/activate
- Intall all the modules by using
pipin thecmd.
pip install -r requirements.txt
- Run the
FastApiserver inPORT 8001.
uvicorn main:app --reload --port 8001
Backend runs at: http://localhost:8001
To run the frontend revert back to the root directory
- Open a new tab in
CMDprompt - Navigate to the frontend directory
cd frontend
- Install all the node modules file
npm install
- Run the React server
npm start
Frontend runs at: http://localhost:3000
This project uses GitHub Actions to implement Continuous Integration (CI) for both the backend and frontend services.
The pipeline automatically runs whenever:
-
Code is pushed to the main branch
-
A Pull Request is opened targeting the main branch
This ensures:
-
Backend code integrity
-
Successful frontend builds
-
Automated validation before deployment
-
Stable production releases
The backend is built using FastAPI (Python 3.11) and is automatically tested through GitHub Actions.
.github/workflows/backend-ci.yml
name: Backend CI
on:
push:
branches: ["main"]
pull_request:
branches: ["main"]
jobs:
backend-ci:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install dependencies
run: |
cd backend-api
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Check app imports (FastAPI sanity check)
run: |
cd backend-api
python -c "import main; print('Backend imports OK')"
- name: Run Tests
run: |
cd backend-api
pytest
The frontend is built using React (Node.js 20) and validated using GitHub Actions.
.github/workflows/backend-ci.yml
name: Frontend CI
on:
push:
branches: ["main"]
pull_request:
branches: ["main"]
jobs:
frontend-ci:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: "20"
- name: Install and build React app
run: |
cd frontend
npm install
npm run build
- Push code to GitHub
- Create Web Service for backend
- Build Command:
pip install -r requirements.txt
- Start Command:
uvicorn main:app --host 0.0.0.0 --port 10000
- Launch Ubuntu EC2
- Open ports 22, 3000, 8000
- Install Docker:
sudo apt update
sudo apt install docker.io docker-compose -y
- Clone project
- Run:
docker-compose up -d --build
We used pytest alongside FastAPI.testclient to validate the API's core functionality and logic.
These tests verify that the server is alive and that the AI detection endpoint handles file uploads correctly.
from fastapi.testclient import TestClient
from main import app
import pytest
client = TestClient(app)
# Test 1: System Health Check
def test_health():
response = client.get("/health")
assert response.status_code == 200
assert response.json() == {"status": "ok"}
These test verify if that the detection is logging events in the database and triggering the n8n to send notification
from logic import decide_event
def test_no_hardhat_violation():
event_type, severity = decide_event(["Person", "NO-Hardhat"])
assert event_type == "PPE_VIOLATION"
assert severity == "HIGH"
def test_no_vest_violation():
event_type, severity = decide_event(["Person", "NO-Safety Vest"])
assert event_type == "PPE_VIOLATION"
assert severity == "HIGH"
def test_normal_case():
event_type, severity = decide_event(["Person", "Hardhat"])
assert event_type == "Normal"
assert severity == "LOW"
To run all tests and see the pass/fail results in your terminal:
pytest
This project integrates n8n for workflow automation. The automation is responsible for:
-
Receiving detection results from backend
-
Processing alert logic
-
Sending SMS notifications
- User uploads image
- Backend processes via OpenCV
- YOLO model detects PPE
- Violations calculated
- Results returned
- User uploads video
- Frames extracted
- Each frame processed
- Violations aggregated
- Compliance calculated
Compliance Rate = (Compliant Items / Total Detected Items) × 100
{
"total_detections": 5,
"violations": 2,
"compliant": 3,
"compliance_rate": 60.0,
"detections": [
{ "class": "no-helmet", "confidence": 0.92, "bbox": [10, 20, 50, 80] },
{ "class": "vest", "confidence": 0.88, "bbox": [15, 25, 55, 85] }
]
"frame": 1
}
[
{
"total_detections": 5,
"violations": 2,
"compliant": 3,
"compliance_rate": 60.0,
"detections": [
{ "class": "no-helmet", "confidence": 0.92, "bbox": [10, 20, 50, 80] },
{ "class": "vest", "confidence": 0.88, "bbox": [15, 25, 55, 85] }
]
"frame": 2
},
{
"total_detections": 5,
"violations": 2,
"compliant": 3,
"compliance_rate": 60.0,
"detections": [
{ "class": "no-helmet", "confidence": 0.92, "bbox": [10, 20, 50, 80] },
{ "class": "vest", "confidence": 0.88, "bbox": [15, 25, 55, 85] }
]
"frame": 4
}
]
- File type validation
- File size limits
- CORS enabled
- Containerized backend
- Real-time camera streaming
- WebSocket support
- User authentication
- Cloud storage integration
- GPU acceleration
- Python 3.10+
- Node 18+
- Docker (optional)
- 8GB RAM minimum
- GPU (optional)
Author Name: MD Moshiur Rahman
MIT License

