# βš™οΈ SID-AI β€” Universal Engineering Drawing Intelligence Platform

Python Version LangGraph Streamlit Qwen 2.5 Gemini PaddleOCR

--- ## πŸ“Œ Executive Overview **SID-AI** (*System for Intelligent Engineering Diagrams*) is an agentic AI system designed to read, classify, reason over, and extract structured digital twins from **ANY engineering drawing type**. Unlike conventional fixed P&ID parsers, **SID-AI** features a **universal multi-discipline intelligence engine** that automatically identifies drawing typesβ€”including **P&ID**, **Electrical Layouts**, **Earthing/Grounding Layouts**, **Single Line Diagrams (SLD)**, **HVAC Layouts**, **Structural Plans**, **Cable Schedules**, and **Generic Engineering Schematics**β€”and maps all graphical symbols, alphanumeric tags, connectivity pipelines, electrical circuits, and dynamic specifications into structured engineering formats (**AVEVA Diagrams**, **Siemens COMOS**, **Intergraph SmartPlant P&ID**, **Excel**, and **JSON Graph**). --- ## ✨ Key Features & Capabilities ### 🌐 1. Universal Multi-Discipline Engineering Support Automated title block recognition and vocabulary scoring classify incoming documents into 10 distinct engineering drawing types: * 🚰 **P&ID / PFD / Isometric**: Lines, equipment, instruments, manual valves, safety relief valves (PSVs), fluid specs, pressure/temperature classes. * πŸ’‘ **Electrical Layouts**: Luminaires/fittings (`L-01`, `TL-101`), distribution boards (`DB-01`, `MDB-A`), circuits (`MCB-3`), elevation references (`EL.101.445`). * ⏚ **Earthing Layouts**: Earth bars (`EB-01`, `MEB`), earth pits/electrodes (`EP-A`), bonding conductors (`BC-01`), resistance specs (`<1 Ohm`). * ⚑ **Single Line Diagrams (SLD)**: Switchgear panels, transformers, busbars, circuit breakers, feeder networks, fault levels. * ❄️ **HVAC Layouts**: AHUs, FCUs, ductwork, dampers, diffusers, air volume ratings. * πŸ—οΈ **Structural Layouts**: Structural columns, beams, footings, gridlines, level markings. * πŸ”Œ **Cable Schedules**: Cable drum tags, core specifications, cross-sectional areas (`mmΒ²`), routing tray pathways. --- ### 🧠 2. 2-Layer Customizable Extraction Engine To maximize accuracy while minimizing API token usage, text and visual data pass through a modular **2-Layer Extraction Pipeline**: ``` β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ LAYER 1: OCR Text Extraction Engine β”‚ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”‚ β€’ Local Offline Options : PaddleOCR (GPU/CPU), PyMuPDF Vector Text β”‚ β”‚ β€’ Online VLM Options : Gemini Vision OCR, Qwen 2.5-VL β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ (Raw OCR Text + Bounding Box Coordinates) β–Ό β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ LAYER 2: Reasoning & Refinement Engine β”‚ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”‚ β€’ Local Offline Option : Rule-Based Regex Classifier β”‚ β”‚ β€’ Online LLM Options : Qwen 2.5 via OpenRouter, Gemini, GPT-4o β”‚ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”‚ DEEP REASONING CAPABILITIES: β”‚ β”‚ 1. Fixes OCR Typos : Corrects misread characters (e.g. P1T -> PIT)β”‚ β”‚ 2. Recombines Split Tags : Merges multiline tag text β”‚ β”‚ 3. Maps Misplaced Data : Associates nearby ratings/specs to tags β”‚ β”‚ 4. Discovers Missing Data : Infers callout notes & missing entities β”‚ β”‚ 5. Validated JSON Output : Generates structured RawTextList JSON β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` --- ### πŸ“¦ 3. Multi-Platform Deliverables & Export System Extracts digital twins directly into standard engineering formats: * πŸ“Š **Excel Workbook (`.xlsx`)**: Styled multi-tab workbook with auto-fitted columns and color-coded revision history delta highlighting. * πŸ•ΈοΈ **Master JSON Graph (`.json`)**: Hierarchical Pydantic schema representation of the entire drawing network. * πŸ“ **AVEVA Diagrams / SP3D XML (`.xml`)**: Complete XML plant model schema compliant with AVEVA and Smart 3D import requirements. * πŸ”§ **Siemens COMOS JSON (`.json`)**: Hierarchical `Project -> Unit -> Location -> Object` tree formatting. * πŸ—ƒοΈ **SmartPlant P&ID CSV (`.csv`)**: Relational database import format with standardized headers. --- ### ⚑ 4. 75% Token Savings & Hybrid Optimization Replaces traditional multi-agent image calls with a **Unified Visual Agent** that extracts graphical symbols, topological relationships, and polyline grid geometry in **1 single visual pass**, saving ~75% in vision token costs. --- ## πŸ“ Project Architecture & Flowsheet Diagram The system orchestration is built on **LangGraph (`StateGraph`)**. The complete execution flow and conditional loops defined in [`src/graph.py`](file:///c:/Users/ADMIN/Downloads/pid_project/src/graph.py) are illustrated below: ```mermaid flowchart TD %% Styling classDef startEnd fill:#1A73E8,stroke:#0D47A1,stroke-width:2px,color:#FFF; classDef agentNode fill:#F8F9FA,stroke:#1A73E8,stroke-width:2px,color:#1A1A2E; classDef parallelNode fill:#E8F0FE,stroke:#1A73E8,stroke-width:2px,color:#1A73E8; classDef routerNode fill:#FEF3C7,stroke:#F59E0B,stroke-width:2px,color:#92400E; classDef outputNode fill:#D1FAE5,stroke:#059669,stroke-width:2px,color:#065F46; %% Nodes START([πŸ“‚ Document Upload / Start]) ::: startEnd Ingest["πŸ“„ Ingestion Agent\n(PDF Rasterization & Drawing Type Detection)"] ::: agentNode ContextLoader["πŸ“š Context Loader Agent\n(Legends & Client Standards)"] ::: agentNode Supervisor["πŸ‘¨β€βœˆοΈ Supervisor Agent\n(Parallel Task Dispatcher)"] ::: agentNode %% Parallel Sub-Graph subgraph ParallelVision ["πŸ‘οΈ Parallel Vision Sub-Graph"] TextDetection["πŸ”€ Text Detection Agent\n(2-Layer OCR + Qwen 2.5 / Gemini Reasoning)"] ::: parallelNode UnifiedVision["πŸ‘οΈ Unified Vision Agent\n(1-Call VLM: Symbols + Relations + Geometry)"] ::: parallelNode end Compiler["βš™οΈ Universal Object Compiler\n(Entity Assembly into UniversalEngineeringGraph)"] ::: agentNode Validation["πŸ” Validation Agent\n(Rule-Based & Topological QA Checks)"] ::: agentNode Completeness["πŸ“‹ Completeness Checker\n(Missing Region & Entity Detection)"] ::: agentNode %% Router Router{"πŸ”€ Completeness Router\n(Missing Items & Count < Max Retries?)"} ::: routerNode ReExtractor["πŸ”Ž Focused Re-Extractor Agent\n(Cropped Re-Scanning)"] ::: agentNode OutputGen["πŸ“₯ Output Generator Agent\n(Excel, AVEVA XML, COMOS, SPPID CSV)"] ::: outputNode END_NODE([🏁 Final Deliverables Ready]) ::: startEnd %% Flow Connections START --> Ingest Ingest --> ContextLoader ContextLoader --> Supervisor Supervisor --> TextDetection Supervisor --> UnifiedVision TextDetection --> Compiler UnifiedVision --> Compiler Compiler --> Validation Validation --> Completeness Completeness --> Router Router -- "YES: Missing Items Found" --> ReExtractor ReExtractor --> Compiler Router -- "NO: Validated / Max Retries" --> OutputGen OutputGen --> END_NODE ``` --- ## πŸ“‚ Repository Structure ``` pid_project/ β”œβ”€β”€ app.py # Streamlit UI Dashboard & Config Controls β”œβ”€β”€ main.py # CLI Execution Entry Point β”œβ”€β”€ requirements.txt # Dependencies β”œβ”€β”€ .env.example # Sample Environment Variables Configuration β”œβ”€β”€ .gitignore # Git Exclusion Rules β”œβ”€β”€ src/ β”‚ β”œβ”€β”€ graph.py # LangGraph StateGraph Execution Topology β”‚ β”œβ”€β”€ state.py # GraphState TypedDict Definition β”‚ β”œβ”€β”€ models.py # Universal Engineering Data Models (Pydantic) β”‚ β”œβ”€β”€ config.py # Multi-Provider Client Factory (Gemini, OpenRouter, Qwen) β”‚ β”œβ”€β”€ agents/ β”‚ β”‚ β”œβ”€β”€ base.py # Base Agent Class for Multi-Model Execution β”‚ β”‚ β”œβ”€β”€ ingestion.py # Document Rasterization & Metadata Extraction β”‚ β”‚ β”œβ”€β”€ context_loader.py # Client Legend & Standard Parser β”‚ β”‚ β”œβ”€β”€ supervisor.py # Execution Coordinator β”‚ β”‚ β”œβ”€β”€ parallel_vision.py # TextDetectionAgent (2-Layer) & UnifiedVisionAgent β”‚ β”‚ β”œβ”€β”€ compiler.py # Universal Engineering Graph Compiler β”‚ β”‚ β”œβ”€β”€ validation.py # QA & Engineering Consistency Rules β”‚ β”‚ β”œβ”€β”€ completeness.py # Missing Entity Checker β”‚ β”‚ β”œβ”€β”€ re_extractor.py # Cropped Bounding Box Re-Scanner β”‚ β”‚ └── output_generator.py # Excel, AVEVA XML, COMOS JSON & SPPID CSV Generator β”‚ └── utils/ β”‚ β”œβ”€β”€ drawing_type_detector.py # Drawing Classification Heuristics β”‚ β”œβ”€β”€ tag_classifier.py # Multi-Discipline Regex Pattern Library β”‚ β”œβ”€β”€ paddle_ocr.py # Local PaddleOCR & PyMuPDF Text Layer Extractor β”‚ β”œβ”€β”€ preprocess.py # OpenCV Image Preprocessing β”‚ └── mock_data.py # Static Fallback Databases ``` --- ## πŸ› οΈ Quickstart & Setup Guide ### 1. Prerequisites * **Python**: 3.11, 3.12, or 3.13 * **OS**: Windows, macOS, or Linux ### 2. Installation Clone the repository and install dependencies: ```bash git clone https://github.com/your-username/sid-ai.git cd pid_project # Create virtual environment python -m venv pid_env # Activate virtual environment # Windows: pid_env\Scripts\activate # Linux/macOS: source pid_env/bin/activate # Install requirements pip install -r requirements.txt ``` --- ### 3. Environment Configuration (`.env`) Create a `.env` file in the project root directory: ```env # Google Gemini API Key (For Gemini 2.0 Flash) GEMINI_API_KEY=your_gemini_api_key_here # OpenRouter API Key (For Qwen 2.5 via OpenRouter) OPENROUTER_API_KEY=sk-or-v1-your_openrouter_key_here # Qwen Settings (Defaults to OpenRouter) QWEN_BASE_URL=https://openrouter.ai/api/v1 QWEN_MODEL=qwen/qwen-2.5-72b-instruct # Optional OpenAI / Groq keys OPENAI_API_KEY=your_openai_api_key_here GROQ_API_KEY=your_groq_api_key_here ``` --- ### 4. Running the Dashboard Launch the Streamlit interactive dashboard: ```bash streamlit run app.py ``` The web dashboard will be available at `http://localhost:8501`. --- ## πŸ’» Dashboard Configuration Controls The dashboard sidebar provides complete control over the pipeline execution: | Section | Setting | Options / Description | |---|---|---| | **Layer 1: OCR Text Engine** | `1st Layer OCR` | β€’ `PaddleOCR (Local / Offline)`
β€’ `PyMuPDF Vector Text (Local / Offline)`
β€’ `Gemini Vision OCR (Online API)`
β€’ `Qwen 2.5-VL / Vision API (Online)` | | **Layer 2: Reasoning Engine** | `2nd Layer Reasoning` | β€’ `Rule-Based Regex (Local / Offline)`
β€’ `Qwen 2.5 Reasoning Engine (OpenRouter / API)`
β€’ `Gemini 2.0 Flash Engine (Online API)`
β€’ `OpenAI GPT-4o Engine (Online API)` | | **Provider Settings** | `API Key & Base URL` | Custom inputs for OpenRouter API keys (`sk-or-v1-...`), custom endpoints, or local vLLM / Ollama (`http://localhost:11434/v1`). | | **Execution Options** | `Offline Mode` | `πŸ”Œ Force Full Offline Mode`: Runs PaddleOCR + Regex Classifier locally with zero API token consumption. | --- ## πŸ“ž Author & Contact **Developer**: Abhinav Gupta **Email**: [abhinavgupta15.ag@gmail.com](mailto:abhinavgupta15.ag@gmail.com) ---

Built with ❀️ using Python, LangGraph, Streamlit, OpenRouter Qwen 2.5, and Google Gemini.