A comprehensive Python-based toolkit for emergency shelter management:
- Shelter Locator: Fetches potential shelter locations using Google Maps Places API
- Offline Map Plotter: Visualizes coordinates from Excel files on interactive offline-capable maps
- AI-powered crisis assistance using Gemma 3 model
- Offline-capable emergency first-aid guidance
- Context-aware responses with knowledge retrieval from first aid database
- India-specific emergency numbers and mountain/flood safety information
- Interactive web interface with map integration
- Fetches locations of potential emergency shelters:
- Schools
- Police Stations
- Fire Stations
- Exports data to Excel with multiple sheets for easy analysis
- Configurable search location and radius
- Includes location details: name, coordinates, address, ratings, and operational status
- Automatic pagination to retrieve all available results
- Read Excel files with latitude/longitude coordinates
- Generate interactive HTML maps using Leaflet.js and OpenStreetMap
- Works offline after initial map tile load (or with local tile server)
- Color-coded markers by category/type
- Interactive popups with detailed location information
- Auto-zoom to fit all markers
- No API key required for viewing maps
- Python 3.7 or higher
- Google Maps API Key with Places API enabled
- Ollama (for chatbot functionality) - see Chatbot Setup below
- Go to Google Cloud Console
- Create a new project or select an existing one
- Enable the Places API for your project
- Go to Credentials and create an API key
- (Optional but recommended) Restrict your API key to only the Places API
-
Clone this repository:
git clone <repository-url> cd emergency
-
Install dependencies:
pip install -r requirements.txt
-
Create a
.envfile from the example:cp .env.example .env
-
Edit
.envand add your Google Maps API key:GOOGLE_MAPS_API_KEY=your_actual_api_key_here SEARCH_LOCATION=40.7128,-74.0060 SEARCH_RADIUS=5000
Edit the .env file to customize your search:
- GOOGLE_MAPS_API_KEY: Your Google Maps API key (required)
- SEARCH_LOCATION: Center point for search in
latitude,longitudeformat- Default:
40.7128,-74.0060(New York City)
- Default:
- SEARCH_RADIUS: Search radius in meters (default: 5000m = 5km)
- Maximum recommended: 50000 (50km)
- New York City:
40.7128,-74.0060 - Los Angeles:
34.0522,-118.2437 - Chicago:
41.8781,-87.6298 - Houston:
29.7604,-95.3698 - Phoenix:
33.4484,-112.0740 - Philadelphia:
39.9526,-75.1652
Run the shelter locator script:
python shelter_locator.pyThe script will:
- Connect to Google Maps Places API
- Search for schools, police stations, and fire stations within the specified radius
- Export results to an Excel file named
shelters_YYYYMMDD_HHMMSS.xlsx
Generate an interactive map from your Excel file:
python offline_map_plotter.py your_file.xlsxBasic Examples:
# Plot data from Excel file (auto-detects lat/lon columns)
python offline_map_plotter.py shelters_20241114.xlsx
# Specify custom output filename
python offline_map_plotter.py shelters.xlsx --output my_map.html
# Specify custom column names
python offline_map_plotter.py data.xlsx --lat Latitude --lon Longitude --name Location
# Specify sheet name and add custom title
python offline_map_plotter.py data.xlsx --sheet "All Shelters" --title "Emergency Shelters Map"Command Line Options:
--sheet <name>- Sheet name to read (default: first sheet)--lat <column>- Latitude column name (default: 'latitude')--lon <column>- Longitude column name (default: 'longitude')--name <column>- Name/title column (default: 'name')--type <column>- Type/category column for color coding (default: 'type')--output <file>- Output HTML file name (default: 'offline_map.html')--title <title>- Map title (default: 'Location Map')
Output:
- Creates an HTML file with an interactive map
- Open the HTML file in any web browser (Chrome, Firefox, Safari, etc.)
- Works offline after initial tile load (tiles are cached by browser)
The chatbot provides AI-powered emergency assistance with first-aid guidance, shelter location, and crisis management information.
1. Install Ollama:
For Linux:
curl -fsSL https://ollama.com/install.sh | shFor macOS:
brew install ollamaFor Windows: Download and install from ollama.com/download
2. Install Gemma 3 Model:
After installing Ollama, pull the Gemma model:
ollama pull gemma2:2bThis downloads the Gemma 2 2B model (recommended for efficiency). For better quality responses, you can use larger models:
# Alternative: Larger model with better quality
ollama pull gemma2:9b3. Verify Installation:
Test that Ollama is working:
ollama list # Should show gemma2:2b in the list4. Start Ollama Service:
Ollama needs to be running as a service:
# On Linux/macOS
ollama serve
# Or on systemd-based Linux systems, it should start automaticallyStart the Flask backend server:
python app.pyThe server will start on http://localhost:8080 and display:
============================================================
Emergency Shelter Chatbot Backend
============================================================
Flask server: http://localhost:8080
Chatbot: Gemma 3 via Ollama
Shelters loaded: <number>
============================================================
- Open your browser and go to
http://localhost:8080 - The interactive map with chat interface will load
- Click "Get My Location" or click on the map to set your location
- Type your emergency question in the chat box
Example queries:
- "What should I do for severe bleeding?"
- "Snake bite treatment"
- "What to do in a flood?"
- "Find nearest shelter"
- "Emergency numbers in India"
- "Altitude sickness symptoms"
- Knowledge Retrieval: Automatically retrieves relevant first-aid information from the knowledge base
- Context-Aware: Uses your location to provide relevant shelter information
- India-Specific: Includes Indian emergency numbers (108, 100, 1078) and local emergency protocols
- First-Aid Coverage: CPR, bleeding, burns, fractures, snake bites, flood safety, mountain emergencies, and more
- Offline-Capable: Once Gemma model is downloaded, works without internet (except for map tiles)
To use a different Gemma model, edit gemma_chat.py:
# Default model
gemma_chat(user_message, model_name="gemma2:2b")
# Use larger model for better responses
gemma_chat(user_message, model_name="gemma2:9b")Ollama Connection Error:
- Ensure Ollama service is running:
ollama serve - Check if the model is installed:
ollama list - Verify the service is accessible:
curl http://localhost:11434
Model Not Found:
- Pull the model:
ollama pull gemma2:2b - Check available models:
ollama list
Slow Responses:
- The 2B model should be fast on most modern hardware
- If too slow, ensure you have enough RAM (at least 4GB free)
- Consider using a smaller model or upgrading hardware
Fallback Behavior:
- If Ollama is unavailable, the chatbot will return the raw knowledge base information
- Emergency numbers and critical info are always accessible
The Excel file contains multiple sheets:
- All Shelters: Combined list of all locations
- Schools: Only school locations
- Police Stations: Only police station locations
- Fire Stations: Only fire station locations
- name: Name of the facility
- type: Type of shelter (schools/police_stations/fire_stations)
- latitude: Latitude coordinate
- longitude: Longitude coordinate
- address: Street address or vicinity
- rating: Google Maps rating (if available)
- user_ratings_total: Number of user ratings
- operational_status: Current operational status
- place_id: Google Places unique identifier
============================================================
Crisis Shelter Locator
============================================================
API Key: ********************AbCd
Location: 40.7128,-74.0060
Radius: 5000m
============================================================
Searching for shelters around 40.7128,-74.0060 within 5000m radius...
Fetching schools...
Found 20 schools in this batch
Total schools found: 20
Fetching police_stations...
Found 5 police_stations in this batch
Total police_stations found: 5
Fetching fire_stations...
Found 8 fire_stations in this batch
Total fire_stations found: 8
Total shelters found: 33
Data exported successfully to: shelters_20241114_123045.xlsx
Total records: 33
Breakdown:
- schools: 20
- police_stations: 5
- fire_stations: 8
- The Google Places API has usage limits and may incur costs
- The free tier includes $200 monthly credit (as of 2024)
- Nearby Search requests cost approximately $32 per 1000 requests
- Each search can return up to 60 results (3 pages of 20)
- Monitor your usage in the Google Cloud Console
- Verify your API key is correct in
.env - Ensure Places API is enabled in Google Cloud Console
- Check if your API key has proper restrictions
- Verify the location coordinates are correct
- Try increasing the search radius
- Check if the location has the types of facilities you're searching for
Make sure all dependencies are installed:
pip install -r requirements.txtBy default, the offline map plotter uses OpenStreetMap tiles from the internet. The map will work offline after you've loaded it once (tiles are cached by your browser), but for completely offline use without any internet connection, you have several options:
- Open the generated HTML map in your browser
- Pan and zoom around the area to load tiles
- Use your browser's "Save Page As" → "Webpage, Complete" to save all resources
- The saved page will work offline with the cached tiles
The HTML file currently loads Leaflet from a CDN. To make it fully offline:
- Download Leaflet.js and CSS:
mkdir -p offline_resources
cd offline_resources
wget https://unpkg.com/[email protected]/dist/leaflet.css
wget https://unpkg.com/[email protected]/dist/leaflet.js
wget https://unpkg.com/[email protected]/dist/images/marker-icon.png
wget https://unpkg.com/[email protected]/dist/images/marker-shadow.png- Modify the HTML file to reference local files instead of CDN links
For true offline mapping with full pan/zoom capabilities:
-
Download map tiles for your area using tools like:
-
Set up a simple tile server:
# Example using Python's HTTP server
python -m http.server 8080-
Place tiles in the correct directory structure:
tiles/{z}/{x}/{y}.png -
Run the map plotter with local tiles enabled (modify the script or use custom tile URL)
If you don't need interactivity, you can generate static map images that are completely offline. Let me know if you need this functionality!
Potential improvements for production use:
- Add more shelter types (hospitals, community centers, hotels)
- Implement geocoding for address-based searches
- Add capacity estimation based on building size
- Include accessibility information
- Real-time availability status integration
- Clustering for large datasets
- Heatmap visualization
- Distance/routing calculations between shelters
- Export to KML/GeoJSON formats
- Database storage instead of Excel
- Multi-location batch processing
- Mobile-responsive map interface
MIT License - feel free to use and modify for your crisis management needs.
Contributions are welcome! Please feel free to submit issues or pull requests.