SafeSphere AI is an AI-powered system designed to predict, prevent, and manage crowd risks in large-scale events like the Kumbh Mela. It enables real-time decision-making to avoid stampedes, optimize crowd movement, and improve public safety.
Large gatherings often suffer from:
- Sudden crowd surges
- Poor real-time visibility
- Lack of predictive intelligence
- High risk of stampedes
Traditional systems are reactive, responding only after congestion occurs.
SafeSphere AI introduces a predictive AI command system that:
- Monitors crowd density across zones
- Detects high-risk and critical areas
- Predicts crowd buildup trends
- Suggests dynamic rerouting strategies
- Generates real-time alerts
- ๐ Crowd Density Analysis
โ ๏ธ Risk Detection (High / Critical / Stampede Risk)- ๐ฎ Predictive Intelligence (Trend Forecasting)
- ๐ Smart Crowd Rerouting
- ๐ข Real-Time Alerts
- ๐งฉ Structured JSON API for easy integration
Simulated Data โ AI Agent (Antigravity + Gemini) โ Cloud Run API โ JSON Response
-
Deployed on Google Cloud Run (serverless, scalable)
-
Uses Gemini API for AI decision-making
-
Designed for integration with:
- Google Firestore (real-time data storage)
- Pub/Sub (event-driven updates)
- Cloud Logging (monitoring & debugging)
- Lightweight processing for low-latency responses
- Optimized decision logic to minimize compute overhead
- Designed for real-time scalability using serverless architecture
- Supports future enhancements like caching and batch processing
- API keys managed via environment variables
- Secure deployment using Google Cloud infrastructure
- Designed with controlled access patterns
- Simple and intuitive REST API
- Structured JSON responses for easy consumption
- Clear error handling and validation
- Designed for integration with dashboards and assistive systems
POST /analyze
{
"zones": [
{"zone_id": "A1", "density": 85, "movement_speed": 1.2},
{"zone_id": "B2", "density": 95, "movement_speed": 0.4}
]
}{
"zone_status": [
{
"zone_id": "B2",
"density_level": "Critical",
"risk_level": "Stampede Risk",
"trend": "Increasing"
}
],
"actions": [
"Redirect crowd from Zone B2 to Zone C1"
],
"alerts": [
"Avoid Zone B2 due to heavy congestion"
]
}Basic test coverage is implemented to validate core functionality.
def test_analyze_endpoint():
response = client.post("/analyze", json={
"zones": [{"zone_id": "A1", "density": 90, "movement_speed": 0.5}]
})
assert response.status_code == 200- โ Normal scenarios
โ ๏ธ High-risk scenarios- โ Edge cases (empty input / invalid data)
git clone https://github.com/YOUR_USERNAME/safesphere.git
cd safesphere
pip install -r requirements.txt
GEMINI_API_KEY=your_api_key_here
python app.py
gcloud run deploy safesphere-api --source .
- Religious gatherings (e.g., Kumbh Mela)
- Sports stadiums
- Concerts and festivals
- Smart city crowd management
- Real-time CCTV integration
- IoT sensor-based tracking
- Live dashboard with heatmaps
- Automated emergency response system
- Multi-agent orchestration
This is a prototype system using simulated data, designed for demonstration and scalability.
Developed by Shiva Tiwari
If you find this project useful, consider giving it a โญ on GitHub!