Skip to content

feat: Static PDF filling for ICS-214 (CAL fire) forms . (Scan Once, Fill Forever)#437

Open
utkarshqz wants to merge 16 commits into
fireform-core:mainfrom
utkarshqz:feat/vision-model-all
Open

feat: Static PDF filling for ICS-214 (CAL fire) forms . (Scan Once, Fill Forever)#437
utkarshqz wants to merge 16 commits into
fireform-core:mainfrom
utkarshqz:feat/vision-model-all

Conversation

@utkarshqz
Copy link
Copy Markdown

@utkarshqz utkarshqz commented Apr 15, 2026

Description

FireForm can now populate static, non-fillable scanned PDFs — including the CAL FIRE ICS-214 Activity Log — from a single voice or text transcript.

Before this PR, the pipeline was completely blocked for any PDF without embedded AcroForm fields. This is the reality for most rural emergency response stations — the CAL FIRE ICS-214 Activity Log, one of the most critical wildland firefighting forms, exists largely as a static flat scan in most department archives. Uploading it to FireForm previously resulted in 0 fields detected and a completely empty output.

This PR introduces a three-path deterministic scan cascade that makes FireForm format-agnostic:

Path 1 — AcroForm (pdfrw): Existing digital fillable PDFs continue to work unchanged, zero regression.

Path 2 — OCR Bounding-Box Scan (Tesseract + OpenCV): If no AcroForm fields are found, pytesseract visually maps the bounding geometry (X, Y, W, H) of blank lines and input zones on the static page image. PyMuPDF (fitz) then stamps the extracted text directly at those coordinates, auto-wrapping text strictly within each bounding box to prevent overflow or line bleeding.

Path 3 — Gemma3 Vision Fallback (gemma3:4b via Ollama): If Tesseract confidence falls below threshold, the page image is passed directly to gemma3:4b running locally via Ollama. The model infers the logical field zones from the visual layout natively — completely offline, no cloud dependency.

Fixes : #432

The "Scan Once, Fill Forever" Architecture

The core insight driving this pipeline is that bounding-box detection is a one-time setup cost per template. After the first scan, the detected coordinate schema is persisted permanently into the Master Incident Data Lake (see PR #385). The Dynamic AI Semantic Mapper (see PR #386) then bridges universally — mapping the Data Lake's canonical incident JSON to the static PDF's exact pixel coordinate map, regardless of how the PDF's blank spaces are labelled or structured.

This means:

  • Scan once → coordinates stored in Data Lake → never scanned again
  • Every subsequent report fill for that template is instant
  • Works across every incident, every responder, every shift — with zero re-scan cost

Real-World Target: CAL FIRE ICS-214

The ICS-214 (Activity Log) is a mandatory document for all CAL FIRE incident operations. It tracks resources, tasks, and activity across the operational period. Because it is distributed and archived as a flat non-fillable PDF at most stations, FireForm could not support it until now. This PR directly enables a CAL FIRE responder to speak naturally into the app and receive a completed, stamped ICS-214 output.


Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

How Has This Been Tested?

Tested locally on Windows 11 with gemma3:4b running via Ollama (OLLAMA_HOST=http://localhost:11434, CPU-only, no GPU required).

Test results:

  • AcroForm PDFs continue to fill correctly via existing pdfrw path ✅
  • Static flat PDFs: coordinates detected via Tesseract OCR, stamped via PyMuPDF fitz
  • Gemma3 vision fallback activates correctly when Tesseract confidence is below threshold ✅
  • Data Lake coordinate persistence: re-uploads of the same template skip OCR scan entirely ✅
Picture1-fghjfg Picture2-dfyhfhx

using gemma 3 :
Screenshot 2026-04-03 151053

using gemma 3 + Tesseract OCR + pymupdf (and also using data lake #385 ):
Screenshot 2026-04-09 223946

Test Configuration:

  • OS: Windows 11
  • Model: gemma3:4b via Ollama (CPU-only)
  • PDF target: CAL FIRE ICS-214 (static flat scan)

Files Changed

File Change
api/routes/templates.py Added scan_static_template() three-path cascade with Tesseract + Gemma3
src/llm.py Context stability limiter for large multi-page form extraction
requirements.txt Added pytesseract, Pillow; removed legacy pdfplumber
frontend/index.html Updated inference state labels to "FireForm AI"

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

@utkarshqz
Copy link
Copy Markdown
Author

@marcvergees @vharkins1 @jansans04 @juanalvv please check this .

@utkarshqz utkarshqz force-pushed the feat/vision-model-all branch from 926cc34 to 343dbe4 Compare April 19, 2026 07:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEAT]: Universal Support for Static (Non-Fillable) Scanned PDF Operations

1 participant