| title | AI Traffic Moderator |
|---|---|
| emoji | ๐ฆ |
| colorFrom | red |
| colorTo | green |
| sdk | docker |
| app_port | 7860 |
| pinned | false |
A modern AI-powered traffic signal control system that uses YOLOv8 for real-time vehicle detection and dynamically manages traffic signals. Built with React, Flask, OpenCV, and Ultralytics YOLO.
- ๐ฏ Real-time Vehicle Detection - YOLOv8 powered detection for cars, motorcycles, buses, and trucks
- ๐ฆ Dynamic Traffic Signal Control - AI-based signal timing based on vehicle density
- ๐ Live Analytics Dashboard - Real-time vehicle count graphs and statistics
- ๐บ๏ธ Interactive Map View - Traffic camera location visualization with Leaflet
- ๐น Live Video Streaming - Real-time camera feed with vehicle annotations
- ๐จ Modern UI - Professional React-based interface with smooth animations
- ๐ฑ Responsive Design - Works seamlessly on desktop and mobile devices
- React 18 - Modern UI framework
- React Router - Client-side routing
- Chart.js - Real-time data visualization
- React Leaflet - Interactive maps
- Axios - HTTP client
- Vite - Fast build tool
- Flask - Python web framework
- OpenCV - Video processing
- YOLOv8 (Ultralytics) - Object detection
- PyTorch - Deep learning framework
- Python 3.8+
- Node.js 16+ and npm
- Webcam (for live detection)
- Git
git clone https://github.com/your-username/AI-Traffic-Moderator.git
cd AI-Traffic-Moderatorpip install -r requirements.txtnpm installYou need to run both the backend and frontend servers:
python app.pyThe backend will run on http://localhost:5000
npm run devThe frontend will run on http://localhost:3000
Open your browser and navigate to:
http://localhost:3000
Login: Use any username and password (demo authentication)
AI-Traffic-Moderator/
โโโ src/ # React frontend source
โ โโโ components/ # Reusable components
โ โ โโโ Header.jsx # Navigation header
โ โ โโโ TrafficLight.jsx # Traffic signal component
โ โโโ pages/ # Page components
โ โ โโโ Login.jsx # Login page
โ โ โโโ Dashboard.jsx # Main dashboard
โ โ โโโ MapView.jsx # Map view page
โ โโโ App.jsx # Main app component
โ โโโ main.jsx # Entry point
โโโ models/ # AI models
โ โโโ yolov8n.pt # YOLOv8 nano model
โโโ Wireless type/ # Future wireless implementation
โโโ app.py # Flask backend server
โโโ requirements.txt # Python dependencies
โโโ package.json # Node.js dependencies
โโโ vite.config.js # Vite configuration
โโโ README.md # This file
- Video Capture - Captures live video feed from webcam
- Vehicle Detection - YOLOv8 processes each frame to detect vehicles
- Traffic Analysis - Counts vehicles and determines traffic density
- Signal Control - Adjusts traffic signal timing dynamically:
- Red: Low traffic (< 5 vehicles) - 15 seconds
- Yellow: Medium traffic (5-9 vehicles) - 10 seconds
- Green: High traffic (โฅ 10 vehicles) - 15 seconds
- Real-time Updates - Frontend polls backend every 5 seconds for updates
- Data Visualization - Displays live graphs and statistics
- ๐ Car
- ๐๏ธ Motorcycle
- ๐ Bus
- ๐ Truck
- Real-time video stream with vehicle detection boxes
- Vehicle labels and bounding boxes
- Traffic signal status overlay
- Current vehicle count
- System status indicator
- Real-time updates
- Vehicle count over time (last 20 data points)
- Interactive Chart.js visualization
- 5-second update interval
- Interactive map showing camera location
- Powered by OpenStreetMap and Leaflet
- Marker with location details
# Camera settings
cap = cv2.VideoCapture(0) # Change 0 to camera index
# Vehicle classes (COCO dataset)
VEHICLE_CLASSES = {2: 'car', 3: 'motorcycle', 5: 'bus', 7: 'truck'}
# Traffic signal timing
traffic_state = {
"signal": "red",
"timer": 15,
"vehicle_count": 0
}server: {
port: 3000,
proxy: {
'/video_feed': 'http://localhost:5000',
'/traffic_status': 'http://localhost:5000'
}
}If you encounter _pickle.UnpicklingError, the code includes a fix:
# Monkey patch torch.load to use weights_only=False
original_load = torch.load
def patched_load(*args, **kwargs):
kwargs['weights_only'] = False
return original_load(*args, **kwargs)
torch.load = patched_load- Check if camera is being used by another application
- Verify camera permissions in Windows settings
- Try changing camera index in
app.py:cv2.VideoCapture(1)orcv2.VideoCapture(2)
- Frontend: Change port in
vite.config.js - Backend: Change port in
app.py:app.run(port=5001)
npm run buildThe production build will be in the dist/ folder.
- Multi-camera intersection support
- Emergency vehicle prioritization
- Cloud-based deployment
- Historical data analytics
- Mobile app integration
- Wireless sensor integration (see
Wireless type/folder)
This project is for educational and research purposes.
Manaswin Sripatnala
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
- Ultralytics YOLOv8 - Object detection model
- OpenCV - Computer vision library
- React - Frontend framework
- Flask - Backend framework
- Chart.js - Data visualization
- Leaflet - Interactive maps
โญ Star this repository if you find it helpful!