# βοΈ SID-AI β Universal Engineering Drawing Intelligence Platform
---
## π 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** is an agentic AI digital twin compilation platform designed to extract, reason over, validate, and export structured engineering graphs from complex engineering blueprints.
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**).
---
## ποΈ System Architecture
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.
---
## π 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.
---
## π οΈ How to Run & Setup Guide
### 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
# 1. Clone the project repository
git clone https://github.com/AbhinavEliac/MTO2Doc.git
cd pid_project
# 2. Create and activate a Python virtual environment
# Windows:
python -m venv pid_env
pid_env\Scripts\activate
# macOS / Linux:
python3 -m venv pid_env
source pid_env/bin/activate
# 3. Install required dependencies
pip install -r requirements.txt
```
### 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.
---
## π 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.
---
---
Built with β€οΈ using Python, LangGraph, Streamlit, Pathnovo ISA 5.1 API, OpenRouter Qwen 3.7 VL, and Google Gemini.