A comprehensive web application that predicts accident risk along routes using machine learning, real-time weather data, and historical accident patterns.
- Interactive Map: Click to set start and end points for route planning
- Real-time Risk Analysis: ML-powered accident risk assessment
- Live Weather Integration: Real weather data from OpenWeatherMap API
- Historical Hotspots: Visual heatmap of accident-prone areas
- Route Alternatives: Compare multiple route options for safety
- Weather Caching: 30-minute cache to reduce API calls
- Error Recovery: Graceful fallback when APIs are unavailable
- Data Validation: Comprehensive input validation and range checking
- Health Monitoring: Built-in health checks and logging
- Docker Support: Complete containerization for easy deployment
- 🟢 Low Risk: Safe driving conditions (Score: 80-100)
- 🟡 Medium Risk: Moderate caution advised (Score: 50-79)
- 🔴 High Risk: Dangerous conditions, avoid if possible (Score: 0-49)
# Clone and run with Docker
git clone <repository>
cd SafeStreets
docker-compose up --buildAccess at: http://localhost
# Install dependencies
pip install -r requirements.txt
# Start backend
cd backend
python app.py
# Start frontend (new terminal)
cd frontend
python -m http.server 8000Access at: http://localhost:8000
Copy .env.example to .env and configure:
cp .env.example .envKey settings:
OPENWEATHER_API_KEY: Get from OpenWeatherMapWEATHER_CACHE_DURATION: Cache duration in seconds (default: 1800)API_HOST/API_PORT: Backend server configuration
- Register at OpenWeatherMap
- Get your free API key
- Add to
.env:OPENWEATHER_API_KEY=your_key_here - Restart the application
GET /- API statusGET /health- Health check with model statusGET /weather/<lat>/<lon>- Get weather data for coordinatesPOST /predict- Predict accident risk with weather data
cd tests
python test_api.py- API endpoint testing
- Data validation testing
- Weather function testing
- Error handling testing
# Build and start all services
docker-compose up -d
# View logs
docker-compose logs -f
# Stop services
docker-compose down- Frontend: Nginx serving static files on port 80
- Backend: Flask API on port 5000
- Network: Internal Docker network for service communication
SafeStreets/
├── backend/
│ ├── app.py # Flask API server with weather integration
│ └── (enhanced with caching, validation, error handling)
├── frontend/
│ ├── index.html # Enhanced web interface
│ ├── script.js # Real weather API calls, route alternatives
│ ├── style.css # Modern styling with animations
│ └── accident_hotspots.json # Heatmap data
├── tests/
│ └── test_api.py # Comprehensive unit tests
├── model/
│ ├── accident_model.pkl # Trained ML model
│ └── train_model.py # Model training script
├── docker-compose.yml # Multi-service orchestration
├── Dockerfile # Multi-stage build configuration
├── nginx.conf # Frontend web server configuration
├── requirements.txt # Updated Python dependencies
└── .env.example # Environment configuration template
- Weather Integration: OpenWeatherMap API with 30-minute caching
- Error Recovery: Automatic fallback to simulated data
- Input Validation: Comprehensive range checking for all parameters
- Logging: Structured logging with different levels
- Health Checks: Built-in monitoring endpoints
- Real Weather: API calls to backend for live weather data
- Route Alternatives: Compare multiple route options
- Better UX: Loading states, error messages, smooth animations
- Responsive Design: Works on desktop and mobile devices
- Algorithm: Random Forest Classifier
- Features: Temperature, humidity, visibility, wind speed, precipitation
- Training: US accident records with weather conditions
- Validation: Input range validation and error handling
- Real-time weather data from OpenWeatherMap
- Automatic fallback to simulated data
- 30-minute caching to reduce API calls
- Seasonal and geographic variations
- Compare multiple route options
- Safety scores for each alternative
- Time vs safety trade-offs
- Interactive route selection
- Graceful degradation when APIs fail
- Comprehensive input validation
- User-friendly error messages
- Automatic retry logic
- Docker containerization
- Nginx reverse proxy
- Health checks and monitoring
- Optimized static asset serving
- Traffic data integration
- Real-time route optimization
- Mobile app development
- User authentication and saved routes
- Historical route analysis
- Machine learning model improvements
- Fork the repository
- Create a feature branch
- Make your changes with tests
- Submit a pull request
This project is for educational purposes. Please ensure compliance with data usage terms for accident datasets and weather APIs.