feat: enhance Earthing & Lighting layout sensitivity, un-gate tag classifier, fix deliverable exports & property access

- Un-gated pattern loops across all drawing types in tag_classifier.py
- Added missing EARTH_PIT_TAG & BOND_CONDUCTOR_TAG passes and expanded IEEE 80 / IS 3043 earthing patterns
- Expanded Luminaire, Distribution Panel, and Circuit search patterns
- Added smart compiler defaults for materials, dimensions, and resistance limits in compiler.py
- Un-gated EARTHED_TO and FEEDS topological relations mapping across all drawings in line_tracer.py
- Fixed EquipmentItem missing location attribute error in models.py and output_generator.py
- Fixed Relationship missing source_tag attribute error by adding property getters in models.py
- Updated SmartPlant CSV and Excel generators to export RELATIONSHIP rows and dynamic Earthing/Equipment sheets
- Updated README.md and .gitignore
This commit is contained in:
Avhinav Gupta
2026-08-08 21:58:56 +05:30
parent 5b31d4fdca
commit 9d78cceef5
13 changed files with 998 additions and 156 deletions
+194 -41
View File
@@ -2,86 +2,239 @@
<p align="center">
<img src="https://img.shields.io/badge/Python-3.11%20%7C%203.12%20%7C%203.13-blue?style=for-the-badge&logo=python&logoColor=white" alt="Python Version" />
<img src="https://img.shields.io/badge/LangGraph-StateGraph%20Workflow-orange?style=for-the-badge&logo=langchain&logoColor=white" alt="LangGraph" />
<img src="https://img.shields.io/badge/LangGraph-Parallel%20Perception-orange?style=for-the-badge&logo=langchain&logoColor=white" alt="LangGraph" />
<img src="https://img.shields.io/badge/Streamlit-Interactive%20Dashboard-FF4B4B?style=for-the-badge&logo=streamlit&logoColor=white" alt="Streamlit" />
<img src="https://img.shields.io/badge/Pathnovo-ISA%205.1%20API-008080?style=for-the-badge" alt="Pathnovo ISA 5.1" />
<img src="https://img.shields.io/badge/ISA--5.1-Native%20Extraction-008080?style=for-the-badge" alt="Pathnovo ISA 5.1" />
<img src="https://img.shields.io/badge/OpenRouter-Qwen%203.7%20VL-purple?style=for-the-badge&logo=openai&logoColor=white" alt="Qwen 3.7 VL" />
<img src="https://img.shields.io/badge/Google-Gemini%202.0%20Flash-4285F4?style=for-the-badge&logo=google&logoColor=white" alt="Gemini" />
</p>
---
## 🏆 Why SID-AI Outperforms Existing Solutions
Traditional P&ID parsing tools and general-purpose Vision-LLMs suffer from high hallucination rates, inability to trace line topologies, and slow processing times. **SID-AI** (*System for Intelligent Engineering Diagrams*) was engineered specifically to solve these fundamental flaws in industrial drawing digitization.
| Feature / Capability | Conventional P&ID Parsers / General Vision LLMs | 🚀 SID-AI Intelligence Engine |
| :--- | :--- | :--- |
| 🏗️ **Architectural Topology** | **Sequential / Single-Pass**: Evaluates entire drawing in a single LLM prompt, causing token overflow and missing minor tags. | **LangGraph 3-Agent Parallel Perception**: Runs dedicated concurrent perception sub-graphs (**Text**, **Symbol**, and **Line Topology**) simultaneously. |
| 📐 **Domain Standards** | **Generic Document OCR**: Mistakes instrument bubbles for basic circles and misses line rating specifications. | **ISA 5.1 & Multi-Discipline Native**: Built-in ISA 5.1 tag rules, line rating specs, electrical SLD, earthing layout, and HVAC schematics logic. |
| 🔍 **Completeness & Accuracy** | **No Verification**: Returns unverified extraction without checking for missing instruments or broken pipelines. | **Self-Healing Loop**: Automated `CompletenessAgent` & `ReExtractorAgent` detect missing items and trigger targeted spatial re-extractions automatically. |
| ⚡ **Execution Latency** | **Extremely Slow (5–15 mins)**: Heavy multi-pass prompts lead to excessive API wait times and UI timeouts. | **Ultra-Fast (< 15 Seconds)**: Pre-rasterized tile caching & sub-crop title block OCR reduce full execution down to **13.78 seconds**. |
| 📦 **Digital Twin Outputs** | **Basic CSV / Markdown**: Requires manual data cleaning before importing into enterprise engineering software. | **Native Enterprise Exports**: Immediate export to **AVEVA Diagrams XML**, **Siemens COMOS JSON**, **SmartPlant P&ID CSV**, and **Styled Excel**. |
| 🌐 **Multi-Discipline Intelligence** | **P&ID Only**: Rigidly restricted to standard piping diagrams. | **Universal Support**: P&ID, Electrical SLD, Earthing/Lighting Layouts, HVAC, Cable Schedules, and General Engineering Schematics. |
---
## 📌 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**.
**SID-AI** is an agentic AI digital twin compilation platform designed to extract, reason over, validate, and export structured engineering graphs from complex engineering blueprints.
Unlike conventional fixed P&ID parsers, **SID-AI** features a **parallel perception 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**).
By replacing monolithic single-prompt extraction with a stateful **LangGraph Parallel Perception Sub-Graph**, SID-AI breaks down visual engineering drawings into distinct topological layers. It seamlessly fuses optical character recognition (OCR), deep object detection, and computer-vision line-tracing to synthesize standard plant software representations (**AVEVA**, **Siemens COMOS**, **Intergraph SmartPlant**, **Excel Workbooks**, and **JSON Knowledge Graphs**).
---
## ✨ Key Features & Capabilities
## 🏗️ System Architecture
### 🌐 1. Pathnovo ISA 5.1 Native Extraction API Integration
Native integration with the **Pathnovo P&ID Extraction API**, trained on ISA 5.1 instrumentation standards:
* **Instrument Function Bubbles & Loop IDs**: Pulls exact loop numbers (`9054`, `9055`, `9077`) directly from spatial image coordinates inside symbol bubbles.
* **Piping Line Sizes & Specs**: Parses nominal line sizes (`8"`, `6"`, `4"`), service codes (`PV`, `VF`, `DC`), and piping specs (`FC11S`, `GC11S`, `AS20S`).
* **Valve Specifications**: Detects valve types (`Check Valve`, `Gate Valve`, `Control Valve`) and pressure rating classes (`150#`, `300#`, `2500#`).
SID-AI is orchestrated using a stateful **LangGraph DAG (Directed Acyclic Graph)** topology featuring a multi-agent orchestration architecture:
```mermaid
flowchart TD
A[📄 Raw Engineering Drawing PDF/Image] --> B[⚙️ IngestionAgent]
B --> C[📚 ContextLoaderAgent]
C --> D[🎯 SupervisorAgent & Drawing Type Classifier]
subgraph Parallel Perception Sub-Graph 👁️
D --> E1[🔤 TextRecognitionAgent\nLayer 1 & Layer 2 OCR + Specs]
D --> E2[🎯 SymbolRecognitionAgent\nISA 5.1 & Object Detection]
D --> E3[⚡ PipelineRecognitionAgent\nLine Tracing & Connectivity]
end
E1 --> F[🧱 CompilerAgent\nKnowledge Graph Builder]
E2 --> F
E3 --> F
F --> G[✅ ValidationAgent\nISA 5.1 & Schema Rule Engine]
G --> H[🔍 CompletenessAgent\nMissing Tag & Pipeline Router]
H -- Missing Items Found (Retries < Max) --> I[🔄 ReExtractorAgent\nTargeted Spatial Zoom Re-Extraction]
I --> F
H -- Complete / Max Retries Reached --> J[📦 OutputGeneratorAgent]
J --> K1[📊 Excel Workbook .xlsx]
J --> K2[📐 AVEVA Diagrams / SP3D .xml]
J --> K3[🔧 Siemens COMOS .json]
J --> K4[🗃️ SmartPlant P&ID .csv]
J --> K5[🕸️ Master JSON Graph .json]
```
### 🧠 Core Agent Roles & Modules
1. **IngestionAgent** ([ingestion.py](file:///c:/Users/ADMIN/Downloads/pid_project/src/agents/ingestion.py)) ⚙️
- Fast pre-rasterization of PDF drawings into high-resolution canvas images (300 DPI).
- Extracts title block metadata (Drawing No, Revision, Plant Location, Sheet No) in **0.052s**.
2. **ContextLoaderAgent** ([context_loader.py](file:///c:/Users/ADMIN/Downloads/pid_project/src/agents/context_loader.py)) 📚
- Injects historical extraction context, project standards, and custom symbol reference tables.
3. **SupervisorAgent** ([supervisor.py](file:///c:/Users/ADMIN/Downloads/pid_project/src/agents/supervisor.py)) 🎯
- Uses `DrawingTypeDetector` to classify drawings into P&ID, SLD, Earthing, HVAC, or Cable Schedules and dynamically configures downstream perception parameters.
4. **Parallel Perception Nodes** ([parallel_vision.py](file:///c:/Users/ADMIN/Downloads/pid_project/src/agents/parallel_vision.py)) 👁️
- **TextRecognitionAgent** 🔤: Multi-tier OCR processing using Pathnovo ISA 5.1 API, PaddleOCR, PyMuPDF, and Qwen 3.7 VL / Gemini 2.0.
- **SymbolRecognitionAgent** 🎯: Detects valves, pumps, instruments, breakers, transformers, and junction boxes.
- **PipelineRecognitionAgent** ⚡: Computer-vision line tracer + VLM topology reasoning for piping runs, busbars, and signal lines.
5. **CompilerAgent** ([compiler.py](file:///c:/Users/ADMIN/Downloads/pid_project/src/agents/compiler.py)) 🧱
- Fuses bounding boxes, text tags, and line vectors into a single unified `GraphState` schema.
6. **ValidationAgent** ([validation.py](file:///c:/Users/ADMIN/Downloads/pid_project/src/agents/validation.py)) ✅
- Enforces ISA 5.1 naming conventions, line size formatting, and electrical rating constraints.
7. **CompletenessAgent & ReExtractorAgent** ([completeness.py](file:///c:/Users/ADMIN/Downloads/pid_project/src/agents/completeness.py), [re_extractor.py](file:///c:/Users/ADMIN/Downloads/pid_project/src/agents/re_extractor.py)) 🔍 🔄
- Self-correction loop: Detects orphan components or incomplete loop IDs and performs high-resolution sub-crop re-extractions.
8. **OutputGeneratorAgent** ([output_generator.py](file:///c:/Users/ADMIN/Downloads/pid_project/src/agents/output_generator.py)) 📦
- Renders multi-format deliverables ready for industrial software ingestion.
---
### ⚡ 2. High-Performance Parallel Perception Sub-Graph
Features 3 dedicated, parallel perception agents running concurrently:
* 🔤 **TextRecognitionAgent**: 2-Layer OCR Reading & Deep Reasoning Engine (Pathnovo ISA 5.1 OCR, PaddleOCR, PyMuPDF, Qwen 3.7-VL, Gemini).
* 🎯 **SymbolRecognitionAgent**: Component & Symbol Detector (Pathnovo ISA 5.1 Engine, Multimodal VLM, RF-DETR).
* ⚡ **PipelineRecognitionAgent**: Topological Connectivity & Line Spec Tracer (Pathnovo Line & Loop Tracer, OpenCV CV Line Tracer + VLM).
## 🔄 End-to-End Workflow Pipeline
```mermaid
flowchart LR
subgraph Stage 1 📄
A[Ingestion & Title Block OCR]
end
subgraph Stage 2 🎯
B[Drawing Classification P&ID / SLD / HVAC]
end
subgraph Stage 3 👁️
C[Parallel Vision Processing Text, Symbols, Lines]
end
subgraph Stage 4 🧱
D[Digital Twin Graph Synthesis]
end
subgraph Stage 5 🔍
E[Validation & Re-Extraction Loop]
end
subgraph Stage 6 📦
F[AVEVA / COMOS / Excel Exports]
end
A --> B --> C --> D --> E --> F
E -- Loop Retry --> C
```
1. **Ingestion & Title Block Parsing 📄**: The input PDF/Image is cached and preprocessed. The title block is isolated to establish drawing context.
2. **Drawing Type Classification 🎯**: Machine learning and pattern heuristic rules classify the document type (P&ID, SLD, Earthing, etc.).
3. **Parallel Perception Execution 👁️**: The 3 vision agents run concurrently to harvest text labels, symbols, and connectivity paths.
4. **Digital Twin Assembly 🧱**: Line segments are linked to nearby instruments and valves, producing a complete graph representation.
5. **Validation & Self-Correction 🔍**: The output is validated against engineering rules. If gaps are found, the system auto-executes targeted zoom-in re-extraction.
6. **Deliverable Export 📦**: Generates compliant XML, JSON, CSV, and Excel deliverables instantly.
---
### 🚀 3. Ultra-Fast Performance & Latency Elimination
* **0.052s Ingestion Agent**: Pre-rasterized page caching and sub-crop title block OCR.
* **13.78s Total Pipeline Execution**: Latency optimization reducing total pipeline runtime from 11m49s to 13.78 seconds.
* **Auto-Routing Vision Models**: Automatically remaps text-only LLM requests to multimodal vision models (`qwen/qwen-3.7-vl`).
## 🛠️ How to Run & Setup Guide
---
### 📦 4. 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 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.
---
## 🛠️ Setup & Execution Guide
### 1. Prerequisites
* **Python**: 3.11, 3.12, or 3.13
* **OS**: Windows, macOS, or Linux
### 1. System Requirements & Prerequisites
- **Python**: Version 3.11, 3.12, or 3.13
- **Operating System**: Windows 10/11, macOS, or Linux
- **Poppler & OpenCV Utilities**: Automatically supported via standard packages
### 2. Environment Setup
```bash
# Clone the repository
# 1. Clone the project repository
git clone https://github.com/AbhinavEliac/MTO2Doc.git
cd pid_project
# Activate virtual environment
# 2. Create and activate a Python virtual environment
# Windows:
python -m venv pid_env
pid_env\Scripts\activate
# Install requirements
# macOS / Linux:
python3 -m venv pid_env
source pid_env/bin/activate
# 3. Install required dependencies
pip install -r requirements.txt
```
### 3. Launch Interactive Dashboard
### 3. API Key Configuration
Create a `.env` file in the root directory (or copy `.env.example`):
```bash
cp .env.example .env
```
Edit `.env` to configure your vision model API credentials:
```env
# Required API Keys
GEMINI_API_KEY=your_gemini_api_key_here
OPENROUTER_API_KEY=sk-or-v1-your_openrouter_api_key_here
# Model Selection Defaults
GEMINI_MODEL=gemini-2.0-flash
QWEN_MODEL=qwen/qwen-2.5-72b-instruct
```
### 4. Launch the Interactive Dashboard
Start the Streamlit application:
```bash
streamlit run app.py
```
Open your browser at `http://localhost:8501` to view the interactive dashboard.
---
## 📞 Author & Contact
## 📁 Repository Structure
```
pid_project/
├── app.py # Main Streamlit Dashboard Application
├── requirements.txt # Python Dependencies
├── .env.example # Template for Environment Credentials
├── .gitignore # Git Exclusion Configuration
├── README.md # Project Documentation
├── src/
│ ├── graph.py # LangGraph StateGraph Execution Pipeline
│ ├── state.py # State Schemas & Data Structures
│ ├── config.py # Global App Configuration & Model Settings
│ ├── db.py # SQLite Execution History Database
│ ├── models.py # Pydantic Schemas for Engineering Entities
│ ├── agents/
│ │ ├── base.py # Agent Base Classes & Utilities
│ │ ├── ingestion.py # PDF & Rasterization Ingestion Agent
│ │ ├── context_loader.py # Drawing Standards & Context Agent
│ │ ├── supervisor.py # Workflow Orchestrator & Router
│ │ ├── parallel_vision.py # Text, Symbol & Line Perception Agents
│ │ ├── compiler.py # Knowledge Graph Synthesizer
│ │ ├── validation.py # ISA 5.1 Validation Rule Engine
│ │ ├── completeness.py # Completeness & Quality Router
│ │ ├── re_extractor.py # Focused Zoom Re-Extraction Agent
│ │ └── output_generator.py # Enterprise File Exporter
│ └── utils/
│ ├── drawing_type_detector.py # Drawing Classification Engine
│ ├── tag_classifier.py # ISA 5.1 Tag Parsing Rules
│ ├── line_tracer.py # Computer Vision Pipeline Line Tracer
│ ├── paddle_ocr.py # PaddleOCR Integration Wrappers
│ └── pathnovo_api.py # Native ISA 5.1 Pathnovo Extraction API
```
---
## 📦 Supported Deliverable Formats
- 📊 **Excel Workbook (`.xlsx`)**: Structured multi-tab spreadsheet featuring Component Tags, Line Schedules, Loop Summaries, and Delta Revision Highlighting.
- 📐 **AVEVA Diagrams XML (`.xml`)**: Schema-compliant XML tree ready for import into AVEVA Diagrams and Smart 3D (SP3D).
- 🔧 **Siemens COMOS JSON (`.json`)**: Hierarchical structure (`Project -> Unit -> Location -> Object`) for Siemens COMOS platform.
- 🗃️ **SmartPlant P&ID CSV (`.csv`)**: Relational database import format for Intergraph SmartPlant.
- 🕸️ **Master Knowledge Graph (`.json`)**: Full topological node-edge graph representation of the engineering blueprint.
---
## 👤 Author & Contact
**Developer**: Abhinav Gupta
**Email**: [abhinavgupta15.ag@gmail.com](mailto:abhinavgupta15.ag@gmail.com)