expert-gamer/solar-rooftop-analyzer
0
Solar Rooftop Analyzer Pro
☀️ Overview
The Solar Rooftop Analyzer Pro is an enterprise-grade, AI-powered application designed to provide comprehensive solar potential assessment for rooftops in the Indian market. It offers a sophisticated analysis pipeline, leveraging computer vision for rooftop detection, robust algorithms for solar energy and financial projections, and advanced AI models for insightful recommendations. Built with Streamlit, the application provides an intuitive and interactive user experience.
✨ Features
- AI-Driven Rooftop Analysis: Utilizes YOLOv8 for precise detection of rooftop structures and calculation of suitable solar installation areas from satellite imagery.
- Detailed Solar Potential Assessment: Generates estimates for annual electricity generation (kWh), optimal system size (kW), and panel count, integrating regional solar irradiance data.
- Comprehensive Financial Modeling: Provides in-depth financial insights including total system costs, net investment post-subsidies (supporting India's tiered subsidy structure), annual/monthly savings, payback period, and 25-year Net Present Value (NPV).
- Intelligent AI Recommendations: Integrates with leading Large Language Models (LLMs) via OpenRouter API (supporting both text-based and multi-modal vision models) to deliver:
- Overall solar potential assessments.
- Specific technical recommendations for optimized installations.
- Identification of potential site-specific challenges with suggested solutions.
- Predictive maintenance schedules for solar components.
- Flexible Satellite Imagery Acquisition: Fetches real-world satellite images using Google Static Maps API. Includes a robust fallback mechanism to synthetic demo data and supports direct user image uploads.
- Enterprise-Grade Foundations:
- Dockerized Deployment: Uses multi-stage Docker builds for efficient and lean production container images.
- Structured Logging: Implements an advanced JSON logging system for comprehensive error tracking, performance monitoring, and security event logging.
- Modular Design: Features a clear service-oriented architecture (Geo, Analysis, AI, Vision, Image Processing) for maintainability and scalability.
- User-Centric Interface: A Streamlit-based web application with an easy-to-use sidebar for inputs and a tabbed dashboard for organized result visualization.
🏛️ Architecture Highlights
The application is structured into a logical, modular hierarchy:
- `main.py`: The Streamlit frontend, orchestrating user interaction and calling backend services.
- `config.py`: Centralized configuration management, loading environment variables, defining constants, and managing application-wide settings including solar parameters from
solar_config.json. - `production/services/`:
- `geo_service.py`: Handles geocoding (Nominatim) and satellite imagery retrieval (Google Static Maps API).
- `analysis_service.py`: Core logic for YOLO-based rooftop detection, solar energy calculations, and financial analysis.
- `ai_service.py`: Provides general text-based AI insights using OpenRouter's LLM capabilities.
- `vision_ai.py`: Offers image-contextual AI insights and visual assessment using OpenRouter's multi-modal LLM capabilities.
- `production/utils/`:
- `image_utils.py`: Contains utility functions for image preprocessing, manipulation, and generating visual overlays for detections.
- `logging_config.py`: Sets up the structured logging framework across the application.
- `input_validator.py`: Ensures data integrity by validating all incoming user inputs.
- `Dockerfile` & `run.sh`: Facilitate containerization, dependency management, and application startup.
🚀 Getting Started
These instructions will guide you through setting up and running the Solar Rooftop Analyzer Pro.
Prerequisites
- Docker: Recommended for the simplest setup.
- Python 3.11+: Required if running directly.
- Git: For cloning the repository.
1. Clone the Repository
git clone https://github.com/pc-expertgamer/solar-ai-assistant.git
cd solar-ai-assistant
IGNORE_WHEN_COPYING_START
Use code with caution. Markdown
IGNORE_WHEN_COPYING_END
2. Configure Environment Variables
Create a .env file in the root directory. This file will store your API keys and other critical configurations.
Generated ini
# .env example
# --- API Keys ---
# Required for AI insights. Obtain from https://openrouter.ai/keys
OPENROUTER_API_KEY="your_openrouter_api_key_here"
# Required for real satellite imagery. Obtain from Google Cloud Console.
# Ensure 'Static Maps API' is enabled for your project.
GOOGLE_STATIC_MAPS_API_KEY="your_google_maps_api_key_here"
# --- Optional AI Model Specifics (defaults are provided in config.py) ---
# See OpenRouter documentation for available models.
# TEXT_MODEL_NAME="meta-llama/llama-3.1-8b-instruct:free"
# IMAGE_MODEL_NAME="openai/gpt-4o-mini"
# --- Geocoding User Agent ---
# Customize with your application name and contact email.
NOMINATIM_USER_AGENT="SolarAnalyzerPro/2.0 (contact@yourdomain.com)"
# --- Streamlit Server Configuration (defaults are in run.sh / Dockerfile) ---
# STREAMLIT_SERVER_PORT=7860
# STREAMLIT_SERVER_ADDRESS=0.0.0.0
# STREAMLIT_SERVER_HEADLESS=true
# STREAMLIT_BROWSER_GATHER_USAGE_STATS=false
# --- Application Logging (defaults are INFO/production) ---
# LOG_LEVEL=INFO # DEBUG, INFO, WARNING, ERROR, CRITICAL
# ENVIRONMENT=production # or development
IGNORE_WHEN_COPYING_START
Use code with caution. Ini
IGNORE_WHEN_COPYING_END
3. Run with Docker (Recommended)
This method ensures all dependencies are managed within a container, providing a consistent environment.
Generated bash
# 1. Build the Docker image (this will also download the YOLOv8 model)
docker build -t solar-analyzer-pro .
# 2. Run the Docker container
# The --env-file option passes your API keys from .env into the container.
docker run -d \
-p 7860:7860 \
--name solar-analyzer-app \
--env-file ./.env \
solar-analyzer-pro
IGNORE_WHEN_COPYING_START
Use code with caution. Bash
IGNORE_WHEN_COPYING_END
Access the application in your web browser at http://localhost:7860.
4. Run Locally (for Development)
If you prefer to run the application directly on your machine for development and debugging:
Generated bash
# 1. Create and activate a Python virtual environment
python -m venv venv
source venv/bin/activate # On Windows, use `venv\Scripts\activate`
# 2. Install Python dependencies
pip install -r requirements.txt
# 3. Manually download the YOLO model
# This step is crucial as the Docker build normally handles it.
# The model will be saved to `data/pretrained_models/yolov8n.pt`
python -c "from ultralytics import YOLO; YOLO('yolov8n.pt').save('data/pretrained_models/yolov8n.pt')"
# 4. Run the Streamlit application
# Ensure your .env file is present in the root directory to load API keys.
streamlit run app.py --server.port 8501 --server.address 0.0.0.0
IGNORE_WHEN_COPYING_START
Use code with caution. Bash
IGNORE_WHEN_COPYING_END
Access the application in your web browser at http://localhost:8501.
🖥️ How to Use
Once the application is running:
Select Location: In the sidebar, choose how to specify the property's location: by entering an Address, Coordinates, selecting a Demo Location, or Upload Image (for custom aerial views).
Input Parameters: Provide your Estimated Roof Area (sq ft) and Average Monthly Bill (₹).
Initiate Analysis: Click the "🔍 Analyze Solar Potential" button. The application will process the data and provide real-time updates via a progress bar.
Review Results: The main content area will populate with a comprehensive dashboard, organized into tabs:
Satellite & Rooftop Analysis: Visuals of the property and AI-detected rooftop metrics.
Solar & Financial Analysis: Key performance indicators and financial projections.
AI Insights & Recommendations: Textual guidance and strategic advice from the AI models.
Reports & Export: (Future Feature) Options to generate detailed reports or export data.