Skip to content

malikibric/SiteWarden-AI

Repository files navigation

🏗️ SiteWarden AI — Autonomous Architectural Compliance Agent

Self-healing architectural compliance system powered by Google Gemini 3 Pro. Upload a blueprint → SiteWarden autonomously detects building-code violations and generates correction recommendations — no manual review needed.

Built for the Google Gemini 3 Hackathon.


✨ Key Features

Feature Description
🔍 Autonomous Vision Analysis Sends your real blueprint to Gemini 3 Pro Vision to detect building-code violations
🌍 44-Country Regulation Support Auto-discovers building codes for 44 countries via Grounding with Google Search
🔄 Self-Healing Loop Iteratively corrects synthetic floor plans until fully compliant (demo mode)
🏢 Context Adaptation Describe building type (hospital, school, warehouse) → Gemini generates stricter constraints
📄 PDF Compliance Certificate Professional downloadable report with before/after visual evidence
📏 Real-Time Annotation Violations are overlaid directly on your blueprint image
⚡ Rate-Limited & Resilient Exponential backoff, retry logic, graceful degradation

🏛️ Architecture

┌─────────────────────────────────────────────────┐
│                  Streamlit UI                    │
│  (app.py — upload, sidebar, thought stream)     │
└────────────┬───────────────────────┬────────────┘
             │                       │
     ┌───────▼────────┐    ┌────────▼──────────┐
     │  Agent Brain    │    │   Regulations      │
     │ (agent_brain.py)│    │  (regulations.py)  │
     │                 │    │                    │
     │ • See→Think→Act│    │ • PDF extraction   │
     │ • Vision API    │    │ • Web discovery    │
     │ • Multi-turn    │    │ • Google Search    │
     │   compliance    │    │   grounding        │
     │   loop          │    │ • Gemini normalize │
     └───────┬─────────┘    └────────┬──────────┘
             │                       │
     ┌───────▼───────────────────────▼──────────┐
     │           Google Gemini 3 Pro              │
     │  • system_instruction for role context    │
     │  • Vision (blueprint analysis)            │
     │  • Structured JSON output                 │
     │  • Grounding with Google Search           │
     └──────────────────────────────────────────┘
             │
     ┌───────▼──────────┐    ┌──────────────────┐
     │  Blueprint        │    │  PDF Certificate  │
     │  Renderer         │    │ (pdf_certificate) │
     │ (Matplotlib)      │    │  (ReportLab)      │
     └──────────────────┘    └──────────────────┘

Agent Loop: See → Think → Act

  1. SEE — Render or load the floor plan image
  2. THINK — Send image + regulations to Gemini Vision with system_instruction
  3. ACT — Parse structured JSON response, apply corrections
  4. LOOP — Repeat until compliant or max iterations

🚀 Getting Started

Prerequisites

Installation

# Clone the repo
git clone https://github.com/your-username/sitewarden-ai.git
cd sitewarden-ai

# Create virtual environment
python -m venv .venv
source .venv/bin/activate  # macOS/Linux
# .venv\Scripts\activate   # Windows

# Install dependencies
pip install -r requirements.txt

# Configure API key
cp .env.example .env
# Edit .env and paste your GEMINI_API_KEY

Run

streamlit run app.py

Open http://localhost:8501 in your browser.


🔑 Configuration

Environment Variable Description Required
GEMINI_API_KEY Google Gemini API key Yes (or use Demo Mode)

Configuration is loaded from a .env file in the project root. See .env.example.


📁 Project Structure

sitewarden-ai/
├── app.py                  # Streamlit frontend — UI, sidebar, agent orchestration
├── agent_brain.py          # Core autonomous agent — Gemini Vision, compliance loop
├── regulations.py          # Regulation pipeline — PDF extraction, web discovery, normalization
├── blueprint_renderer.py   # Parametric floor plan renderer (Matplotlib)
├── pdf_certificate.py      # Professional PDF compliance report (ReportLab)
├── style.css               # Custom theme styles (dark + orange)
├── requirements.txt        # Python dependencies
├── .env.example            # Environment variable template
├── .gitignore              # Git ignore rules
└── README.md               # This file

🤖 Gemini API Features Used

Gemini Feature Where Used Purpose
Gemini 3 Pro All API calls Latest model for speed + quality
Vision (multimodal) analyse_real_blueprint() Analyze uploaded blueprint images
system_instruction All GenerateContentConfig calls Set agent persona without polluting conversation
Structured JSON output Compliance verdicts, parameter extraction Reliable parsing with Pydantic validation
Grounding with Google Search _gemini_generate_regulations() Real-time building code discovery
Context-aware generation adapt_context_constraints() Translate building types to numeric constraints
Rate limiting + retry _rate_limited_generate() Production-resilient API usage

🔧 How It Works

Two Analysis Paths

Path A — Real Blueprint Upload:

  1. User uploads an architectural blueprint image
  2. Gemini 3 Pro Vision analyzes the image against regulations
  3. Violations are annotated directly on the user's blueprint
  4. Correction recommendations are generated
  5. PDF compliance certificate is produced

Path B — Demo Mode (Synthetic Floor Plan):

  1. A parametric FloorPlan is rendered with intentionally non-compliant dimensions
  2. Gemini analyzes → detects violations → suggests corrected parameters
  3. Floor plan is re-rendered with corrections
  4. Loop continues until all checks pass

Regulation Pipeline

  1. User Upload — Extract text from uploaded PDFs via PyPDF2
  2. Web Discovery — Search for official building-code PDFs online
  3. Google Search Grounding — Gemini queries real-time web data for current codes
  4. Normalization — Gemini extracts structured ComplianceRules from raw text
  5. Fallback — Regex-based extraction if Gemini is unavailable

🌍 Supported Countries

44 countries with region-specific building codes:

🇺🇸 US · 🇬🇧 UK · 🇩🇪 Germany · 🇫🇷 France · 🇨🇦 Canada · 🇦🇺 Australia · 🇳🇱 Netherlands · 🇸🇪 Sweden · 🇳🇴 Norway · 🇩🇰 Denmark · 🇫🇮 Finland · 🇦🇹 Austria · 🇨🇭 Switzerland · 🇮🇹 Italy · 🇪🇸 Spain · 🇯🇵 Japan · 🇰🇷 South Korea · 🇸🇬 Singapore · 🇦🇪 UAE · 🇮🇳 India · 🇧🇷 Brazil · 🇲🇽 Mexico · 🇿🇦 South Africa · 🇳🇿 New Zealand · 🇵🇱 Poland · 🇨🇿 Czech Republic · 🇮🇪 Ireland · 🇧🇦 Bosnia & Herzegovina · 🇭🇷 Croatia · 🇷🇸 Serbia · 🇸🇮 Slovenia · 🇹🇷 Turkey · 🇸🇦 Saudi Arabia · 🇪🇬 Egypt · 🇳🇬 Nigeria · 🇰🇪 Kenya · 🇵🇭 Philippines · 🇹🇭 Thailand · 🇲🇾 Malaysia · 🇮🇩 Indonesia · 🇻🇳 Vietnam · 🇨🇳 China · 🇷🇺 Russia · 🇺🇦 Ukraine


📜 License

MIT License — see LICENSE for details.


SiteWarden AI — Because buildings should be safe by design, not by accident.
Powered by Google Gemini 3 Pro

About

Project for Gemini 3 Hackathon

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published