CityGuard AI is a comprehensive real-time local incident monitoring and alert system that aggregates data from multiple sources, uses AI-powered analysis to assess incident relevance and severity, and delivers targeted notifications to keep residents informed about critical safety information.
CityGuard AI | Python | Flask | AI
GEMINI_API_KEY
)OPENWEATHERMAP_API_KEY
)NEWS_API_KEY
)git clone https://github.com/AishwaryaChandel27/CityGuardAlert cd cityguard-ai
pip install -r requirements.txt
export GEMINI_API_KEY="your_gemini_api_key" export OPENWEATHERMAP_API_KEY="your_openweathermap_key" export NEWS_API_KEY="your_news_api_key" export SESSION_SECRET="your_session_secret"
python main.py
http://localhost:5000
.┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ Data Agent │ │ Notification │ │ Web Interface │
│ │ │ Agent │ │ │
│ • Weather API │───▶│ │───▶│ • Dashboard │
│ • News API │ │ • Gemini AI │ │ • Weather Page │
│ • Scheduled │ │ • Analysis │ │ • News Page │
│ Fetching │ │ • Email Alerts │ │ • Interactive │
└─────────────────┘ └──────────────────┘ │ Map │
└─────────────────┘
│
▼
┌──────────────────┐
│ Database │
│ │
│ • Incidents │
│ • Users │
│ • Subscriptions │
│ • Notifications │
└──────────────────┘
GET /api/incidents
- Retrieve all incidents with filtering options.GET /api/incidents/weather
- Weather-specific incidents.GET /api/incidents/news
- News-specific incidents.GET /api/incidents/<id>
- Individual incident details.hours
- Time range filter (default: 24).min_relevance
- Minimum relevance score (default: 0.3).source
- Filter by data source (weather/news).severity
- Filter by severity level.{ "success": true, "incidents": [ { "id": 1, "title": "Weather Alert: Fog", "description": "Dense fog conditions affecting visibility", "ai_summary": "Fog reported in New York, exercise caution while traveling", "severity": "low", "category": "weather", "source": "weather", "location": "New York", "relevance_score": 0.5, "is_verified": true, "created_at": "2025-08-14T10:30:00Z", "url": null } ], "count": 1 }
id
- Primary keytitle
- Incident titledescription
- Original incident descriptionai_summary
- AI-generated summaryseverity
- Severity level (low/medium/high/critical)category
- Incident categorysource
- Data source (weather/news)location
- Geographic locationrelevance_score
- AI relevance score (0.0-1.0)is_verified
- AI verification statusurl
- Source URL (for news incidents)created_at
- Timestampid
- Primary keyusername
- Unique usernameemail
- Email addresspassword_hash
- Encrypted passwordid
- Primary keyuser_id
- Foreign key to Usersseverity_threshold
- Minimum severity for alertscategories
- Subscribed incident categoriesis_active
- Subscription statusData Ingestion
# Weather data from OpenWeatherMap weather_data = weather_api.get_current_conditions() weather_alerts = weather_api.get_alerts() # News data from NewsAPI news_articles = news_api.search_local_incidents()
AI Processing
# Gemini AI analysis for each incident analysis = gemini.analyze_incident({ "title": incident.title, "description": incident.description, "location": incident.location }) # Returns structured analysis { "relevance_score": 0.75, "severity": "high", "category": "weather", "is_credible": true, "summary": "AI-generated incident summary" }
Notification Logic
# Email notifications for high-priority incidents if incident.severity in ['critical', 'high'] and incident.relevance_score > 0.7: notification_agent.send_email_alerts(incident, subscribers)
# Required API Keys GEMINI_API_KEY=your_gemini_api_key_here OPENWEATHERMAP_API_KEY=your_openweather_api_key NEWS_API_KEY=your_news_api_key # Application Settings SESSION_SECRET=your_secure_session_secret DATABASE_URL=sqlite:///instance/cityguard.db # Local development DATABASE_URL=postgresql://user:pass@host/db # Production # Email Configuration (Optional) SMTP_SERVER=smtp.gmail.com SMTP_PORT=587 EMAIL_USER=your_email@gmail.com EMAIL_PASS=your_app_password
# Data Agent Configuration WEATHER_FETCH_INTERVAL = 10 # minutes NEWS_FETCH_INTERVAL = 10 # minutes MAX_INCIDENTS_PER_FETCH = 5 # AI Analysis Thresholds MIN_RELEVANCE_SCORE = 0.3 HIGH_PRIORITY_THRESHOLD = 0.7 CRITICAL_ALERT_THRESHOLD = 0.9
cityguard-ai/
├── agents/
│ ├── data_agent.py # Data fetching automation
│ └── notification_agent.py # AI processing and alerts
├── templates/
│ ├── base.html # Base template with navigation
│ ├── index.html # Main dashboard
│ ├── weather.html # Weather alerts page
│ ├── news.html # News alerts page
│ ├── map.html # Interactive map
│ └── subscribe.html # Subscription management
├── static/
│ ├── css/custom.css # Custom styling
│ └── js/dashboard.js # Frontend JavaScript
├── utils/
│ └── email_service.py # Email notification utilities
├── app.py # Flask application factory
├── main.py # Application entry point
├── models.py # Database models
├── routes.py # Web routes and API endpoints
├── gemini.py # Gemini AI integration
└── README.md # This file
# Run the application in debug mode export FLASK_ENV=development python main.py # Check API endpoints curl http://localhost:5000/api/incidents curl http://localhost:5000/api/incidents/weather?hours=12
git checkout -b feature/new-feature
).git commit -am 'Add new feature'
).git push origin feature/new-feature
).This project is licensed under the MIT License. See LICENSE file for details.
For support, feature requests, or bug reports:
Version 2.0.0 (August 2025)
CityGuard AI - Keeping communities safe through intelligent incident monitoring.