IsoMTO is a full-stack web application designed to automate the generation of a Material Take-Off (MTO) from piping isometric drawings. By leveraging a Google Gemini Vision LLM pipeline, the application processes drawings, extracts engineering metadata, identifies piping materials (pipes, fittings, flanges, valves, gaskets, and bolt sets), and displays them side-by-side with the drawing for verification.
Preparing piping MTOs is traditionally a manual, slow, and error-prone process. IsoMTO automates this workflow by taking an unstructured engineering drawing (PDF or image) and generating a structured, validated bill of materials.
+----------------------------------------+
| Piping Isometric Drawing |
| (PDF, PNG, JPG) |
+-------------------+--------------------+
|
v
+-------------------+--------------------+
| Next.js Frontend |
| (File validation, Upload UI) |
+-------------------+--------------------+
|
| Multipart Upload
v
+-------------------+--------------------+
| FastAPI Backend |
| (CORS, Server validation) |
+-------------------+--------------------+
|
+---------------------+---------------------+
| |
| If API Key Configured | If No Key (Mock Mode)
v v
+------------+-------------+ +-------------+-------------+
| PDF Preprocessing | | Mock MTO Generator |
| (Render to 3x Zoom PNG) | | (Returns sample schemas) |
+------------+-------------+ +-------------+-------------+
| |
v |
+------------+-------------+ |
| Gemini Vision API | |
| (JSON Structured Output) | |
+------------+-------------+ |
| |
v |
+------------+-------------+ |
| Pydantic Validation | |
| (Validate schema models) | |
+------------+-------------+ |
| |
v |
+------------+-------------+ |
| Heuristic Derivations | |
| (Compute bolts/gaskets) | |
+------------+-------------+ |
| |
+---------------------+---------------------+
|
v
+-------------------+--------------------+
| Structured MTO Output |
| (Interactive Table, CSV) |
+----------------------------------------+
- User Interface: Designed with custom responsive CSS styling (sleek dark mode, glassmorphism panel styles, and themed badge pills).
- Upload Mechanism: Implemented a drag-and-drop area + file-picker with client-side type and size validation (maximum 20MB).
- Verification & Export: Results are shown side-by-side with the uploaded drawing. The tabular items feature confidence metrics, category color-coding, and a "Export as CSV" button linked directly to the download stream endpoint.
- PDF-to-Image Preprocessing: Raw PDFs are intercepted and processed using
PyMuPDF(fitz). The first page is rendered to a high-resolution PNG at a 3.0x zoom factor (approx216 DPI). This is crucial for structural text legibility, enabling the vision model to read tiny print annotations. - SDK Version & KeyError Safeguard: In older versions of
google-generativeai, passing Pydantic models directly toresponse_schemaraises aKeyError: 'properties'because of nested enums or$defsin Pydantic v2. A customresolve_schemamethod was implemented to programmatically resolve, flatten, and clean$ref/allOf/anyOfJSON schema properties before passing the config as a dictionary to Gemini. - Heuristic Derivation: In accordance with piping conventions, the backend automatically computes derived consumables: it appends 1 gasket and 1 bolt set per flanged joint based on the total flange quantities.
- Graceful Mock Fallback: If
API_KEYis not present in.env, the pipeline gracefully falls back to returning a schema-valid mock MTO response, keeping the app 100% testable out-of-the-box.
- Node.js: v18.0.0 or higher
- Python: v3.10.0 or higher
- Open your terminal and navigate to the
backenddirectory:cd backend - Create and activate a Python virtual environment:
# Create virtual environment python -m venv .venv # Activate on Windows (PowerShell) .\.venv\Scripts\Activate.ps1 # Activate on macOS/Linux source .venv/bin/activate
- Install the dependencies:
pip install -r requirements.txt
- Create a
.envfile from the example:Editcopy .env.example .env
.envand fill in your Gemini API key:API_KEY=your_gemini_api_key_here
- Start the FastAPI server using the virtual environment interpreter:
The backend API will run at
uvicorn app.main:app --reload
http://127.0.0.1:8000. You can inspect the Swagger documentation athttp://127.0.0.1:8000/docs.
- Open a new terminal and navigate to the
frontenddirectory:cd frontend - Install the Node packages:
npm install
- Create a
.env.localfile from the example:Keep the default backend URL proxy setup:copy .env.example .env.local
BACKEND_API_URL=http://127.0.0.1:8000
- Run the Next.js development server:
Open your browser and navigate to
npm run dev
http://localhost:3000to access the workspace.
To run the backend test suite:
cd backend
.\.venv\Scripts\python -m pytestAPI_KEY=AIzaSy... # Google Gemini API key (optional: activates mock fallback if missing)BACKEND_API_URL=http://127.0.0.1:8000 # FastAPI backend host address- Single Sheet Scope: Each uploaded file represents one piping isometric drawing sheet.
- Standard MTO Rules: Pipe items are quantified by total cumulative length in meters (
M), while fittings, valves, and flanges are quantified by piece count (EA). - Consumable Heuristics: Derives 1 gasket and 1 bolt set per flanged joint directly based on the count of flanged connections.
- Dense Layouts: Hand-drawn isometrics or scans with dense, overlapping lines and very small annotations can reduce extraction accuracy.
- Text Orientation: Blueprints containing heavily rotated text can occasionally be misread by generic vision models.
- PDF Scope: Preprocessing renders the first page of multi-sheet PDF documents.
- Symbol Bounding Boxes: Detect and draw bounding-box highlights over inline components (valves, flanges) on the preview canvas.
- Job Queue (Async Processing): Shift the extraction pipeline to an asynchronous task queue (e.g., Celery/Redis) with WebSockets to query job status, which is ideal for production and batch uploads.
- BOM-to-Drawing Verification: Add a validation step that automatically reconciles the drawing's built-in BOM text table against the model's visual symbol extractions, highlighting discrepancies.
- Excel Export: Add custom styling formatting options during downloads (e.g.
.xlsxexport with sheets/grouping).
