RavindranadhM's picture
Simplify deployed UX and remove surface gate flow
c36c5e5 verified
|
Raw
History Blame Contribute Delete
6.35 kB
---
title: Manufacturing Monitoring System
emoji: 🏭
colorFrom: blue
colorTo: gray
sdk: docker
app_port: 7860
---
# Manufacturing Monitoring System
Manufacturing Monitoring System is a full-stack industrial monitoring platform for steel surface inspection. It generates automated reports, streams live updates over WebSockets, and exposes a production-style dashboard for real-time manufacturing visibility.
## Highlights
- Real-time defect detection for steel surface images
- Browser camera inspection and uploaded image inspection
- Fast real-time inspection mode with optional deep AI analysis
- Hosted or local AI recommendations with automatic fallback to rule-based guidance
- FastAPI backend with REST and WebSocket streaming
- Local JSON report persistence with optional PostgreSQL logging
- React + Vite + Tailwind monitoring dashboard
- Analytics, history, alerts, and live command center views
## Tech Stack
- Backend: FastAPI, Uvicorn, OpenCV, Ultralytics YOLO
- LLM: LangGraph + OpenRouter, Ollama, or Hugging Face Inference Providers
- Frontend: React, Vite, Tailwind CSS, Recharts
- Realtime: WebSocket broadcast pipeline
- Storage: Local reports plus optional PostgreSQL or Supabase
## Project Structure
```text
api/ FastAPI app and WebSocket server
agent/ Recommendation and decision helpers
core/ Config, logging, constants, database access
inspection/ Inference, formatting, reporting, service layer
dashboard/ React monitoring dashboard
models/ Trained defect detection model
training/ Experimental training utilities
test_images/ Sample images for local testing
live_camera.py Simulation runner for offline inspection playback
main.py Python entry point
```
## Features
### Dashboard
- Live decision status and connection health
- Inspection KPIs and critical alert banners
- Organized architecture and backend overview panels
### Live Monitoring
- Upload an image and run inspection
- Use browser camera feed for auto or manual live inspection
- Annotated preview output for every inspected frame
- Fast mode for real-time inspection and optional deep AI analysis toggle
- PASS, REVIEW, and FAIL guidance with visible operator feedback
- Camera calibration guidance for top-view steel inspection
### History
- Searchable inspection log
- Decision filtering
- Defect-level report detail view
### Analytics
- Severity distribution
- Decision distribution
- Defect-type frequency
- Timeline charts for inspection trends
## Backend API
### Main endpoints
- `GET /health`
- `GET /reports`
- `GET /reports/latest`
- `GET /analytics/summary`
- `POST /inspect/image`
- `POST /inspect/frame`
- `WS /ws`
## Environment Setup
Copy `.env.example` to `.env` if you want to configure PostgreSQL logging.
```env
DATABASE_URL=postgresql://username:password@hostname:6543/postgres
CORS_ORIGINS=http://127.0.0.1:5173,http://localhost:5173
ENABLE_LLM_REPORTS=true
LLM_PROVIDER=auto
OLLAMA_BASE_URL=http://127.0.0.1:11434
OLLAMA_MODEL=llama3
OLLAMA_TIMEOUT_SECONDS=6
HF_TOKEN=
HF_CHAT_MODEL=meta-llama/Llama-3.1-8B-Instruct:cerebras
HF_ROUTER_BASE_URL=https://router.huggingface.co/v1
OPENROUTER_API_KEY=
OPENROUTER_MODEL=openrouter/free
OPENROUTER_BASE_URL=https://openrouter.ai/api/v1
MAX_UPLOAD_SIZE_MB=8
```
`DATABASE_URL` is optional. If it is not set, the system still works and stores reports locally inside `reports/`.
If `ENABLE_LLM_REPORTS=true`, the system can use:
- `LLM_PROVIDER=auto` to prefer a hosted provider when configured and fall back automatically
- `LLM_PROVIDER=ollama` for local development with Ollama
- `LLM_PROVIDER=huggingface` for cloud deployment with `HF_TOKEN`
- `LLM_PROVIDER=openrouter` for low-volume free cloud demos with `OPENROUTER_API_KEY`
If the configured provider is unavailable, the app falls back to a rule-based recommendation path automatically.
## Camera Calibration
For the best live-monitoring performance, position the camera so the steel surface is clearly visible in a stable top view with minimal background clutter. This project is currently optimized around that operating assumption for public deployment.
## Deployment
For a single public URL without needing any local computer:
- Deploy the whole app as one Docker service
- The included [Dockerfile](/Users/ravindranadhm/Documents/Projects/steel-surface-inspection copy/Dockerfile) builds the React frontend and serves it from FastAPI
- Best free option: Hugging Face Docker Spaces
- Best frontend-only option: Vercel, if you later want a split architecture
Recommended Hugging Face Space environment variables:
```env
ENABLE_LLM_REPORTS=true
LLM_PROVIDER=auto
HF_TOKEN=your_huggingface_token
HF_CHAT_MODEL=meta-llama/Llama-3.1-8B-Instruct:cerebras
```
In deployed mode, keep deep AI analysis off for continuous live camera monitoring and enable it only for manual review or uploaded images.
## Local Run
### 1. Backend
```bash
cd "/Users/ravindranadhm/Documents/Projects/steel-surface-inspection copy"
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
venv/bin/uvicorn api.main:app --host 127.0.0.1 --port 8000
```
### 2. Frontend
```bash
cd "/Users/ravindranadhm/Documents/Projects/steel-surface-inspection copy/dashboard"
npm install
npm run dev -- --host 127.0.0.1 --port 5173
```
### 3. Open the app
- Frontend: `http://127.0.0.1:5173`
- Backend health: `http://127.0.0.1:8000/health`
## Verification
Recommended checks:
```bash
python -m compileall api core inspection agent live_camera.py main.py
```
```bash
cd dashboard
npm run lint
npm run build
```
## Notes
- The provided model file `models/steel_inspection.pt` is included in the project and is small enough for a standard GitHub repository.
- Browser camera inspection requires camera permission in your browser.
- Live camera mode is optimized to always return a visible inspection result, even when no defects are found.
- The frontend automatically uses the same origin as the backend when deployed as a single Docker service.
## Resume-Friendly Summary
Built an AI-powered manufacturing monitoring system for steel surface inspection using FastAPI, React, WebSocket streaming, OpenCV, Ultralytics YOLO, analytics dashboards, and live browser camera inspection.