Skip to content

Aditya-Ranjan1234/SafeCityAI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

14 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

SafeCityAI: Bangalore Accident Prevention System

Application Screenshots

The following screenshots showcase the key features and interfaces of the SafeCityAI application:

Home Page

Home Page The main dashboard provides an overview of accident statistics, emergency service contacts, and key metrics for quick assessment of road safety in Bangalore.

A comprehensive AI-powered platform for accident prevention and road safety in Bangalore. This system integrates real-time weather data, historical accident records, and machine learning predictions to help citizens navigate safely and report hazardous conditions.

๐Ÿ† Created for เคธเคฎAI - Time for AI Competition

This project is developed as part of the เคธเคฎAI - Time for AI competition, which challenges participants to code, create, and innovate with Artificial Intelligence. SafeCityAI demonstrates how AI can be leveraged to create safer urban environments and potentially save lives through predictive analytics and community engagement.

โœจ Key Features

๐Ÿ—บ๏ธ Interactive Accident Hotspot Map

  • Detailed Visualization: View accident-prone areas across Bangalore with severity indicators
  • Filtering Options: Filter hotspots by severity, incident count, accident type, and time of day
  • Multiple Map Views: Switch between marker, heatmap, and cluster visualizations
  • Detailed Information: Click on markers to see comprehensive accident data and contributing factors

Accident Map The interactive map visualizes accident hotspots across Bangalore with color-coded markers indicating severity levels, allowing users to identify high-risk areas at a glance.

๐Ÿ›ฃ๏ธ Safe Route Planning

  • Source-Destination Selection: Choose starting and ending points in Bangalore
  • Safety-Optimized Routes: Get routes that avoid high-accident areas
  • Risk Assessment: View safety scores for suggested routes
  • Accident Hotspot Avoidance: Automatically routes around known dangerous areas
  • Time and Distance Estimates: Compare safety vs. convenience trade-offs

๐Ÿ“น Video Surveillance & YOLO-based Accident Detection

  • Real-time Monitoring: Live camera feeds from high-risk areas across Bangalore
  • YOLOv8 Detection: State-of-the-art object detection for vehicles and crashes
  • Bounding Box Visualization: Real-time tracking of vehicles with confidence scores
  • Crash Analysis: Automatic identification of accidents based on vehicle proximity and motion
  • Multi-Camera Support: Simultaneous monitoring of multiple locations with different video feeds
  • Instant Alerts: Immediate notification when incidents are detected
  • Emergency Response: Automatic dispatch of emergency services
  • Incident Analytics: Review and analysis of detected incidents with detailed metrics
  • Local Video Processing: Automatic detection and use of videos from the Crash-1500 directory

Video Surveillance Real-time video surveillance with YOLO-based crash detection across multiple camera feeds in Bangalore

๐Ÿค– Machine Learning Predictions

  • Risk Prediction: AI-powered prediction of accident likelihood based on multiple factors
  • City-wide Risk Map: Color-coded visualization of risk levels across the entire city
  • Emerging Hotspot Detection: Identification of new high-risk areas before they become problematic
  • Personalized Safety Recommendations: Contextual safety advice based on current conditions

Risk Prediction Map The city-wide risk prediction map uses AI to visualize accident risk levels across Bangalore with a heat map overlay. Red areas indicate high-risk zones, yellow shows moderate risk, and green represents lower risk areas. Red markers pinpoint specific accident hotspots.

Recent Updates Section

Recent Updates The recent updates section keeps users informed about road work, traffic signal changes, and other important traffic-related announcements with timestamps.

๐ŸŒฆ๏ธ Weather & Safety Alerts

  • Real-time Weather Data: Current weather conditions and forecasts for Bangalore
  • Weather-related Safety Alerts: Automatic warnings when weather conditions may affect road safety
  • Forecast Integration: 7-day weather forecast to help plan safer travel
  • Condition-specific Safety Tips: Tailored advice for different weather conditions

Current Weather Conditions Real-time weather data showing temperature (23.9ยฐC), humidity (65%), and wind speed (2.5 km/h) with clear sky conditions.

Weather Forecast 3-day weather forecast for March-April 2025 showing upcoming conditions: slight rain showers on Monday (April 14), overcast on Tuesday (April 15), and thunderstorm with slight hail on Wednesday (April 16).

Driving Safety Tips Context-aware driving safety tips that update based on current and forecasted weather conditions, helping drivers navigate safely during adverse weather.

๐Ÿ“ Citizen Reporting System

  • Issue Reporting: Allow citizens to report road hazards and safety issues
  • Location Selection: Interactive map for precise location reporting
  • Media Upload: Support for uploading photos of hazardous conditions
  • Status Tracking: Follow the status of reported issues

Community Reports Recent community reports showing citizen-submitted hazards with location details, issue type, severity level, and report status. Reports from April 2025 include a pothole on Outer Ring Road, a broken traffic signal, and waterlogging after rain.

๐Ÿšจ Emergency Services Integration

  • One-click Emergency Contact: Quick access to emergency services at the top of every page
  • Direct Calling: Integrated calling functionality for immediate assistance
  • Multiple Services: Access to Police, Fire, Ambulance, and General Emergency services

The emergency services bar at the top of the application provides quick access to important contact numbers (112 for Police, 108 for Ambulance, 100 for Emergency, 101 for Fire) for immediate assistance in case of accidents.

๐ŸŒ Multilingual Support (Planned)

  • Support for English, Hindi, and Kannada languages
  • Easy language switching via the top navigation bar
  • Localized emergency information and safety tips

Footer

The application footer displays copyright information (ยฉ 2025) and acknowledges that the system was created for the เคธเคฎAI - Time for AI competition, reinforcing the project's forward-looking vision.

๐Ÿ“Š Data & AI Components

Data Sources

  • Accident Data: Historical records of accident-prone areas in Bangalore
  • Weather Data: Real-time and forecast data from Open-Meteo API
  • Citizen Reports: Crowdsourced information about road hazards and safety issues

AI & Machine Learning

  • Risk Prediction Model: Analyzes multiple factors to predict accident likelihood
  • Hotspot Identification: Uses clustering algorithms to identify accident-prone areas
  • Weather Impact Analysis: Correlates weather conditions with accident frequency
  • Emerging Risk Detection: Identifies new patterns in accident data to predict future hotspots

๐Ÿ”ง Technical Implementation

Technology Stack

  • Frontend: Streamlit for interactive web interface
  • Data Processing: Pandas for data manipulation and analysis
  • Visualization: Folium for maps, Plotly for interactive charts
  • Machine Learning: Scikit-learn for predictive models
  • APIs: Open-Meteo for weather data

Architecture

The application follows a modular architecture with clear separation of concerns:

  • Data Layer: Handles data loading, processing, and storage
  • Logic Layer: Implements business logic, predictions, and data analysis
  • Presentation Layer: Manages the user interface and visualization components

๐Ÿ“ Installation & Setup

Prerequisites

  • Python 3.8 or higher
  • Git

Installation Steps

  1. Clone this repository:

    git clone https://github.com/Aditya-Ranjan1234/SafeCityAI.git
    cd SafeCityAI
  2. Create a virtual environment and activate it:

    python -m venv venv
    
    # On Windows
    venv\Scripts\activate
    
    # On macOS/Linux
    source venv/bin/activate
  3. Install the required packages:

    pip install -r requirements.txt

    Note: The application uses several key dependencies:

    • Streamlit: For the interactive web interface
    • Folium: For interactive maps and route visualization
    • NetworkX: For route planning algorithms
    • OpenCV: For video processing and accident detection
    • Plotly: For data visualization
    • Scikit-learn: For machine learning predictions
  4. Download the CarCrash dataset for accident detection (optional):

    git clone https://github.com/Cogito2012/CarCrashDataset.git
  5. Configure environment variables (if needed):

    • Rename .env.example to .env
    • Add your API keys for weather services

๐Ÿš€ Usage

Local Development

  1. Run the Streamlit application:

    streamlit run app.py
  2. Open your web browser and navigate to:

    http://localhost:8501
    

Streamlit Cloud Deployment

To deploy on Streamlit Cloud and avoid the libGL.so.1 error:

  1. Make sure your requirements.txt file includes all necessary dependencies.

  2. The application has built-in fallback mechanisms to handle missing OpenCV dependencies.

  3. If you encounter the libGL.so.1 error, you can install the required system packages on your server:

    # For Ubuntu/Debian
    apt-get update && apt-get install -y libgl1-mesa-glx libglib2.0-0
    
    # For Amazon Linux/CentOS
    yum update -y && yum install -y mesa-libGL
  4. Alternatively, use the provided Dockerfile for containerized deployment:

    # Build and run using Docker
    docker build -t safecityai .
    docker run -p 8501:8501 safecityai
  5. Access the application at:

    http://localhost:8501
    

๐Ÿ“ Project Structure

โ”œโ”€โ”€ app.py                      # Main Streamlit application
โ”œโ”€โ”€ sample.py                    # Standalone crash detection interface
โ”œโ”€โ”€ requirements.txt            # Python dependencies
โ”œโ”€โ”€ Dockerfile                   # Docker configuration for containerized deployment
โ”œโ”€โ”€ docker-compose.yml           # Docker Compose configuration for easy deployment
โ”œโ”€โ”€ WORKFLOW.md                  # Detailed workflow documentation
โ”œโ”€โ”€ .env                        # Environment variables (API keys)
โ”œโ”€โ”€ src/                        # Source code
โ”‚   โ”œโ”€โ”€ components/             # UI components
โ”‚   โ”‚   โ”œโ”€โ”€ emergency_services.py  # Emergency services components
โ”‚   โ”‚   โ”œโ”€โ”€ map_components.py   # Map visualization components
โ”‚   โ”‚   โ”œโ”€โ”€ stats_components.py # Statistical visualization components
โ”‚   โ”‚   โ””โ”€โ”€ weather_components.py # Weather visualization components
โ”‚   โ”œโ”€โ”€ data/                   # Data files
โ”‚   โ”‚   โ”œโ”€โ”€ bangalore_accident_data.csv  # Accident hotspot data
โ”‚   โ”‚   โ””โ”€โ”€ videos/              # Video files for surveillance demo
โ”‚   โ”œโ”€โ”€ pages/                  # Application pages
โ”‚   โ”‚   โ”œโ”€โ”€ home_page.py        # Home page
โ”‚   โ”‚   โ”œโ”€โ”€ accident_map_page.py # Accident map page
โ”‚   โ”‚   โ”œโ”€โ”€ ml_predictions_page.py # ML predictions page
โ”‚   โ”‚   โ”œโ”€โ”€ route_planning_page.py # Safe route planning page
โ”‚   โ”‚   โ”œโ”€โ”€ video_surveillance_page.py # Video surveillance page
โ”‚   โ”‚   โ”œโ”€โ”€ weather_page.py     # Weather and alerts page
โ”‚   โ”‚   โ””โ”€โ”€ report_page.py      # Issue reporting page
โ”‚   โ””โ”€โ”€ utils/                  # Utility modules
โ”‚       โ”œโ”€โ”€ config.py           # Configuration settings
โ”‚       โ”œโ”€โ”€ data_loader.py      # Data loading utilities
โ”‚       โ”œโ”€โ”€ video_detection.py  # Video processing and accident detection
โ”‚       โ””โ”€โ”€ yolo_detection.py   # YOLOv8-based crash detection
โ”œโ”€โ”€ CarCrashDataset/            # Reference dataset for accident detection
โ”œโ”€โ”€ screenshots/                # Application screenshots for documentation
โ””โ”€โ”€ images/                     # Application screenshots for README

๐Ÿค Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

๐Ÿ“œ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ™ Acknowledgements

๐Ÿ” Standalone Crash Detection Interface

In addition to the main application, this project includes a standalone crash detection interface (sample.py) that allows users to upload and analyze traffic videos for crashes.

Features

  • Video Upload: Upload any traffic video for crash analysis
  • YOLOv8 Processing: Frame-by-frame analysis with state-of-the-art object detection
  • Real-time Visualization: Watch the detection process with bounding boxes
  • Crash Frame Identification: Pinpoints the exact moment of collision
  • Detailed Analysis: Provides confidence scores, timestamps, and severity assessment
  • Emergency Recommendations: Suggests actions to take when a crash is detected

Usage

To run the standalone crash detection interface:

streamlit run sample.py

This will open a web interface where you can upload traffic videos for crash analysis.

About

AI-powered platform integrating real-time data and citizen reports to predict and prevent urban accidents

Topics

Resources

Stars

Watchers

Forks

Contributors