A powerful interactive application that combines Google's Gemini AI with geospatial analysis capabilities, enabling natural language-driven exploration and visualization of geographic data.
- AI-Powered Chat Interface: Interact with geospatial data using natural language queries
- Interactive Map Visualization: Real-time display of geospatial data with multiple layer support
- Risk Analysis Tools: Specialized tools for assessing weather risks to infrastructure
- Power Line Infrastructure Analysis: Visualize and analyze power line networks
- Integrated Weather Data: Access weather forecasts and analyze weather-related risks
- Python 3.10+
- Google Gemini API key
- Streamlit
- GeoPandas and other geospatial libraries (see
requirements.txt
for full details)
-
Clone the repository
git clone https://github.com/yourusername/gemini-geospatial-streamlit.git cd gemini-geospatial-streamlit
-
Create a virtual environment and install dependencies
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate pip install -r requirements.txt
-
Set up environment variables
Create a
.env
file in the project root with the following variables:PROJECT_ID=your_google_cloud_project_id GCS_BUCKET_NAME=your_gcs_bucket_name
-
Download supplementary shapefiles
python download_gcs_data.py
This will download required shapefiles and other geospatial data from the specified GCS bucket to the
data/local
directory. -
Run the application
streamlit run app.py
-
Access the web interface
Open your browser and navigate to http://localhost:8501
The application is structured into several key components:
app.py
: Main entry point for the Streamlit applicationcomponents/
: UI components including chat interface, map, and sidebarservices/
: Core services for Gemini integration, map processing, and risk analysisdata/
: Data access and processing modulesutils/
: Utility functions and helpersaction_handlers/
: Handlers for map actions triggered by AI responses
"What areas in Pennsylvania are at high risk for wind damage to power lines in the next 3 days?"
"Show me the power infrastructure in Chester County and highlight areas with potential weather impacts."
"Compare the weather risks between Philadelphia and Pittsburgh for the next week."
- User submits a query through the chat interface
- The query is processed by the Gemini AI model with a specialized system prompt
- Gemini generates a structured response including:
- Text response for the user
- Map action instructions
- Optional structured data for visualization
- The application processes the map actions to update the interactive map
- Results are displayed to the user in both chat and map interfaces
You can configure the application behavior in the sidebar, including:
- Model parameters
- Feature toggles for specific capabilities
- Date selection for weather forecasts
- Debug panel for viewing system prompts and API responses
# enable services
gcloud services enable storage.googleapis.com &&
gcloud services enable run.googleapis.com &&
gcloud services enable aiplatform.googleapis.com &&
gcloud services enable cloudbuild.googleapis.com
# grant permissions to service account
export PROJECT_ID=`gcloud config get-value project`
export PROJECT_NUMBER=`gcloud projects describe $PROJECT_ID --format="value(projectNumber)"`
gcloud projects add-iam-policy-binding $PROJECT_ID --member=serviceAccount:$PROJECT_NUMBER[email protected] --role="roles/run.builder"
gcloud projects add-iam-policy-binding $PROJECT_ID --member=serviceAccount:$PROJECT_NUMBER[email protected] --role="roles/logging.logWriter"
gcloud projects add-iam-policy-binding $PROJECT_ID --member=serviceAccount:$PROJECT_NUMBER[email protected] --role="roles/storage.objectUser"
Manually enable IAP then run:
gcloud beta run deploy gemini-geospatial-streamlit \
--source . \
--region="us-central1" \
--platform managed \
--memory 32Gi \
--cpu 8 \
--region us-central1 \
--min-instances 1 \
--timeout 1h \
--no-cpu-throttling \
--cpu-boost \
--no-allow-unauthenticated \
--iap
-- Deploying from Artifact Registry ...: Y -- Allow unauthenticated invocations...: N
- Add IAP-secured Web App User to appropriate users
- Go to Cloud Run service → Source → Edit source
- Rename
.env.example
to.env
and update with your configuration, for example:
GCP_PROJECT_ID=your-project-id
GCS_BUCKET_NAME=your-bucket
The application uses several data sources:
- Weather forecast data
- US geographic boundaries (states, counties)
- Power infrastructure data for Pennsylvania
- Custom local datasets (as configured)
- Supplementary shapefiles stored in a GCS bucket specified by the
GCS_BUCKET_NAME
environment variable
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.