Skip to content

Latest commit

ย 

History

32 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ›ก๏ธ SafeRoute - AI-Powered Safety Navigation

Hackathon Project: Empowering safer journeys through AI-driven route analysis and real-time community alerts.

๐Ÿš€ Live Demo

Try SafeRoute now - No installation required!

๐ŸŒ User App ๐Ÿ‘จโ€๐Ÿ’ผ Admin Dashboard
Launch App Admin Panel
Main navigation interface Monitor SOS alerts & community reports

๐Ÿ”— Direct Links:


SafeRoute is an intelligent navigation system that prioritizes user safety by analyzing crime data, emergency services availability, and community reports to recommend the safest routes. Built during a hackathon with a focus on women's safety and community-driven protection.

๐ŸŒŸ Features

๐Ÿค– AI-Powered Safety Analysis

  • Multi-AI Provider Support: Groq AI (llama-3.3-70b-versatile) for comprehensive analysis
  • Smart Route Scoring: AI evaluates routes based on crime incidents, lighting, and emergency services
  • Real-time Risk Assessment: Dynamic safety scores using multiple data sources
  • Emergency Service Integration: Google Places API integration for real hospital/police/petrol/hotel locations
  • Evenly Distributed POI Markers: Hospitals, police stations, petrol pumps, and hotels are spatially distributed along each route using position-band sampling โ€” not clustered at start/end

๐Ÿง  AI Route Intelligence (New)

  • AI Safety Explainer: One-click Groq AI analysis of any route explaining why it is safe or risky in plain language (3โ€“4 sentences)
  • AI Route Narrator: Text-to-speech narration of your selected route with turn-by-turn safety briefing; uses Groq for a personalized briefing, falls back to browser Speech Synthesis
  • Predictive Safety Score: Bar chart showing safety forecasts for 7AM / 2PM / 8PM / 11PM with a "NOW" badge on the current time slot โ€” powered by time-of-day + day-of-week scoring with optional Groq AI insight

๐Ÿ”ฅ Danger Heatmap (New)

  • Crime Heatmap Overlay: Toggle a live danger heatmap built from community reports and SOS alerts directly on the map
  • Color-Coded Intensity: Yellow โ†’ Orange โ†’ Red โ†’ Deep Red gradient representing danger density
  • Auto-Refresh: Heatmap updates automatically when new community reports are submitted

๐Ÿšจ Emergency Response System

  • SOS Alert Broadcasting: Instant emergency alerts to admin dashboard via Socket.IO
  • Countdown SOS with Cancel: 5-second confirmation window prevents accidental triggers
  • AI Emergency Assistant: Groq AI provides nearby emergency services and personalized safety tips on SOS trigger
  • Live Location Sharing: Real-time GPS tracking with current address shown on map

๐Ÿ“ Location Awareness (New)

  • Current Location Marker: Animated blue drop-pin shows your detected location on the map with address in an info popup
  • Locate Me Button: Instantly fills the source field with your current location for route planning

๐Ÿ‘ฅ Community Safety Network

  • Crowd-sourced Reports: Users can report accidents, suspicious activity, harassment, theft, traffic, and road damage
  • Real-time Incident Mapping: Live visualization of community-reported safety concerns
  • Heatmap Integration: Community reports directly feed the danger heatmap

๐Ÿ“ฑ User Experience

  • Interactive Safety Dashboard: Visual route comparison with safety scores, distance, duration, and AI features per route
  • Safety-Color-Coded Routes: Green / Amber / Red polylines on map based on safety score
  • Night Mode Support: Full dark mode for comfortable night navigation
  • Mobile-Responsive Design: Hamburger navigation and sidebar overlay for all screen sizes
  • Personalized Experience: Name capture on first visit used in SOS alerts and AI narration

๐Ÿ—๏ธ Architecture

SafeRoute/
โ”œโ”€โ”€ backend/                 # Flask API Server
โ”‚   โ”œโ”€โ”€ app.py              # Main application with AI integration
โ”‚   โ””โ”€โ”€ saferoute.db        # SQLite database
โ”œโ”€โ”€ frontend/               # Static Web Application
โ”‚   โ”œโ”€โ”€ index.html          # Landing page (default)
โ”‚   โ”œโ”€โ”€ app.html            # Main user interface
โ”‚   โ”œโ”€โ”€ admin.html          # Admin dashboard
โ”‚   โ”œโ”€โ”€ main.js             # Core JavaScript functionality
โ”‚   โ”œโ”€โ”€ style.css           # Modern UI styling
โ”‚   โ””โ”€โ”€ config.js           # Environment configuration
โ”œโ”€โ”€ requirements.txt        # Python dependencies
โ”œโ”€โ”€ render.yaml            # Deployment configuration
โ””โ”€โ”€ Procfile              # Heroku deployment

๐Ÿš€ Quick Start

Prerequisites

  • Python 3.8+
  • Google Maps API Key
  • AI API Keys (optional, for enhanced AI features):
    • Groq AI API Key
    • Google Gemini API Key

1. Clone Repository

git clone https://github.com/yourusername/saferoute.git
cd saferoute

2. Environment Setup

# Copy environment template
cp .env.example .env

# Edit .env with your API keys
GROQ_API_KEY=your_groq_api_key_here
GEMINI_API_KEY=your_gemini_api_key_here
GOOGLE_MAPS_API_KEY=your_google_maps_api_key_here

3. Install Dependencies

pip install -r requirements.txt

4. Run Application

# Start backend server
python backend/app.py

# Open frontend (in another terminal)
# Serve frontend files on localhost:8000 or open index.html (landing) or app.html (main app) directly

5. Access Application

  • Main App: http://localhost:5000 or open frontend/app.html
  • Admin Dashboard: frontend/admin.html

๐Ÿ”ง API Endpoints

Route Analysis

POST /get-routes
Content-Type: application/json

{
  "source": "Starting Location",
  "destination": "Destination Location",
  "frontend_routes": [{ "polyline": "<encoded_polyline>" }]
}

AI Safety Explainer

POST /explain-route
Content-Type: application/json

{
  "route": { "safety_score": 82, "distance": "12.3 km", ... }
}

AI Route Narrator

POST /narrate-route
Content-Type: application/json

{
  "route": { ... },
  "route_num": 1,
  "user_name": "Priya"
}

Predictive Safety Score

POST /predict-safety
Content-Type: application/json

{
  "route": { "safety_score": 82, ... }
}

Returns scores for 7AM / 2PM / 8PM / 11PM slots with optional Groq AI one-line insight.

Emergency Alerts

POST /send-alert
Content-Type: application/json

{
  "lat": 17.3850,
  "lng": 78.4867,
  "user_name": "Priya"
}

Community Reports

POST /post-feedback
Content-Type: application/json

{
  "lat": 17.3850,
  "lng": 78.4867,
  "type": "harassment",
  "description": "Incident description"
}

๐Ÿค– AI Integration

Groq AI โ€” Core Intelligence

  • Model: llama-3.3-70b-versatile
  • Use Cases:
    • Route safety explanation (3โ€“4 sentence human-readable analysis)
    • Voice narration script generation (time-of-day aware)
    • Predictive safety one-line insight per route
    • Emergency SOS AI assistant (nearest hospitals, police, actionable advice)
  • Speed: ~500ms average response
  • Fallback: All AI features have client-side fallbacks โ€” app is fully functional without Groq

Fallback System

  1. Primary: Groq AI (llama-3.3-70b-versatile)
  2. Secondary: Google Places API (real location data for POI markers)
  3. Tertiary: Client-side calculation (safety scores, narration text, forecast bars)
  4. Final: Generic emergency suggestions with helpline numbers

๐ŸŽฏ Safety Scoring Algorithm

SafeRoute calculates safety scores using multiple factors:

  1. Crime Incident Analysis (40%)

    • Historical crime data simulation
    • Incident severity weighting
    • Proximity to route calculation
  2. Emergency Services Availability (30%)

    • Hospital proximity and count
    • Police station accessibility
    • Response time estimation
  3. Infrastructure Quality (20%)

    • Street lighting assessment
    • Road condition evaluation
    • Public transport availability
  4. Community Reports (10%)

    • Real-time incident reports
    • User-generated safety alerts
    • Crowd-sourced hazard mapping

๐Ÿ”ฎ Predictive Safety Scoring (New)

Time-of-day and day-of-week adjustments applied to base score:

Time Slot Modifier
7 AM +8 (morning commute, safer)
2 PM +5 (daytime, peak safety)
8 PM โˆ’10 (evening, higher risk)
11 PM โˆ’20 (night, highest risk)

Weekend penalty: โˆ’3 points. Groq AI adds a one-sentence contextual insight per forecast.

๐ŸŒ Deployment

Render.com (Recommended)

# render.yaml configuration included
# Automatic deployment from GitHub

Manual Deployment

# Set environment variables
export PORT=5000
export GROQ_API_KEY=your_key
export GOOGLE_MAPS_API_KEY=your_key

# Run production server
python backend/app.py

๐Ÿ› ๏ธ Technology Stack

Backend

  • Flask: Web framework with CORS support
  • Flask-SocketIO: Real-time WebSocket communication
  • SQLite: Lightweight database for alerts and feedback
  • Groq AI SDK: llama-3.3-70b-versatile for route explanation, narration, and prediction
  • Google Directions API: Multi-route planning with polyline encoding
  • Google Places API (New): Real hospital, police, petrol pump, and hotel locations along routes

Frontend

  • Vanilla JavaScript: No framework dependencies
  • Google Maps JavaScript API: Interactive mapping with HeatmapLayer, DirectionsRenderer, custom SVG markers
  • Web Speech Synthesis API: Browser-native TTS for route narration
  • Socket.IO Client: Real-time SOS and community report updates
  • Modern CSS: Responsive design with dark mode, animated route cards, forecast bars

Deployment

  • Render.com: Primary hosting platform
  • Heroku: Alternative deployment option
  • Static Hosting: Frontend can be served separately

๐Ÿ”’ Security Features

  • API Key Protection: Secure environment variable management
  • CORS Configuration: Proper cross-origin request handling
  • Input Validation: Sanitized user inputs and SQL injection prevention
  • Rate Limiting: Built-in protection against abuse
  • Emergency Verification: Confirmation tokens for sensitive operations

๐Ÿ“Š Database Schema

SOS Alerts

CREATE TABLE sos_alerts (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    lat REAL NOT NULL,
    lng REAL NOT NULL,
    timestamp DATETIME NOT NULL,
    status TEXT DEFAULT 'PENDING'
);

Community Feedback

CREATE TABLE route_feedback (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    lat REAL,
    lng REAL,
    type TEXT,
    description TEXT,
    timestamp DATETIME NOT NULL,
    route_polyline TEXT
);

๐ŸŽจ UI/UX Features

  • Animated Logo: Dynamic slogan rotation
  • Safety Color Coding: Intuitive visual safety indicators
  • Responsive Design: Mobile-first approach
  • Dark Mode: Eye-friendly night navigation
  • Real-time Updates: Live incident and alert notifications

๐Ÿค Contributing

This is a hackathon project, but contributions are welcome!

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

๐Ÿ“ License

This project is open source and available under the MIT License.

๐Ÿ† Hackathon Context

Built for: Hackathon
Theme: Women's Safety & Community Protection
Duration:
Team: Thrivers

Hackathon Achievements

  • โœ… AI-powered safety analysis with Groq (llama-3.3-70b-versatile)
  • โœ… AI Safety Explainer โ€” plain-language route risk analysis
  • โœ… AI Route Narrator โ€” voice narration with Groq + Speech Synthesis fallback
  • โœ… Predictive Safety Score โ€” time-of-day forecast with bar chart UI
  • โœ… Danger Heatmap Overlay โ€” community-fed live crime heatmap
  • โœ… Real-time SOS emergency response system
  • โœ… Evenly distributed POI markers (hospitals, police, petrol, hotels) along routes
  • โœ… Safety-color-coded route polylines (Green / Amber / Red)
  • โœ… Live user location marker with animated drop-pin
  • โœ… Community-driven safety network with real-time Socket.IO updates
  • โœ… Mobile-responsive design with hamburger navigation
  • โœ… Production-ready deployment on Render.com

๐Ÿ”ฎ Future Enhancements

  • Fake incoming call feature for discreet SOS escape
  • Shake-to-SOS via device motion sensor
  • Trusted contacts auto-alert via WhatsApp/SMS deep links
  • Journey Guard Mode โ€” auto-SOS if user doesn't check in by ETA
  • Live SOS tracking shareable link for trusted contacts
  • Machine learning model for predictive safety analysis using real crime datasets
  • Integration with local law enforcement APIs
  • Wearable device compatibility (smartwatch alerts)
  • Multi-language support for global accessibility
  • Advanced analytics dashboard for city planners
  • Integration with ride-sharing platforms

๐Ÿ“ž Emergency Numbers

India: 100 (Police), 102 (Ambulance), 1091 (Women Helpline)

๐Ÿ™ Acknowledgments

  • Groq AI for providing fast, unlimited AI inference
  • Google Gemini for advanced AI reasoning capabilities
  • Google Maps Platform for comprehensive location services
  • Open Source Community for inspiration and tools
  • Hackathon Organizers for the opportunity to build for social impact

โš ๏ธ Disclaimer: This is a hackathon prototype. While functional, it should not be used as the sole source for emergency situations. Always contact local emergency services directly in case of real emergencies.

๐Ÿ›ก๏ธ SafeRoute - Because every journey should be a safe journey.

About

SafeRoute - Because every journey should be a safe journey.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages