Invoice Extraction
Extract structured invoice data from images and PDFs using GLM-OCR and Sinapsis Agents.
Source: Invoice Extraction — GitHub
This demo extracts invoice information from an uploaded image or PDF and presents the result as JSON. It uses Sinapsis to configure the document-loading and inference steps, with a Gradio interface for selecting an input and downloading the output.
The executable implementation is in sinapsis-demos/invoice-extraction. All YAML configurations, OCR prompts, sample invoices, screenshots, and Docker assets remain in that repository.
What it demonstrates
Ingestion of PDF and image invoices using dedicated Templates.
GPU-backed invoice understanding with the
zai-org/GLM-OCRmodel.Structured extraction of fields including invoice identifiers, parties, line items, payment information, taxes and totals.
A PDF path that additionally uses a batch OCR Template and a structured-output LLM stage.
Export of results as JSON through a Gradio application.
Application flow
The UI chooses one of two Agent configurations according to the uploaded file type. They are separate declarative Agents invoked by the application, not an implicit branch within one Agent.
flowchart TD
UPLOAD([Upload invoice]) --> SELECT{PDF or image?}
SELECT -->|Image| IMG[Image Agent<br/>FolderImageDatasetCV2]
IMG --> IMG_OCR[GLMOCRInference]
SELECT -->|PDF| PDF[PDF Agent<br/>PDFToImage]
PDF --> BATCH[GLMOCRBatchInference]
BATCH --> CONV[TextToLLMConversation]
CONV --> LLM[LLaMACPPTextCompletion]
IMG_OCR --> JSON[Parse structured result as JSON]
LLM --> JSON
JSON --> OUT([Display and download JSON])
Green-bordered nodes reference Sinapsis templates. Hover or focus them to fetch documentation.
View Mermaid source
flowchart TD
UPLOAD([Upload invoice]) --> SELECT{PDF or image?}
SELECT -->|Image| IMG[Image Agent<br/>FolderImageDatasetCV2]
IMG --> IMG_OCR[GLMOCRInference]
SELECT -->|PDF| PDF[PDF Agent<br/>PDFToImage]
PDF --> BATCH[GLMOCRBatchInference]
BATCH --> CONV[TextToLLMConversation]
CONV --> LLM[LLaMACPPTextCompletion]
IMG_OCR --> JSON[Parse structured result as JSON]
LLM --> JSON
JSON --> OUT([Display and download JSON])
webapp.py selects configs/inference_invoice_image.yaml for image files and configs/inference_batch_invoice.yaml for PDFs. Another config, configs/inference_invoice_pdf.yaml, provides a simpler PDF-to-GLMOCRInference path but is not the PDF config selected by this web application. The diagram follows the application's actual configuration choices.
Source files
| File | Purpose |
|---|---|
README.md | Overview, prerequisites and UI instructions. |
webapp.py | File handling, Agent selection and JSON display/download. |
configs/inference_invoice_image.yaml | Image ingestion and GLM-OCR. |
configs/inference_batch_invoice.yaml | PDF batch OCR with a later LLM extraction stage. |
configs/inference_invoice_pdf.yaml | Alternative standalone PDF OCR configuration. |
artifacts/invoice_example.png | Example image input. |
artifacts/invoice_sample.pdf | Example PDF input. |
docker/Dockerfile | GPU runtime dependencies. |
docker/compose_test.yaml | Development deployment. |
instructions/webapp.png | Screenshot of the web interface. |
The source examples contain extraction prompts and schemas. Instead of duplicating those large schemas here, follow the linked YAML for the authoritative set of requested JSON fields.
Requirements and running the demo
The source README calls for Docker/Compose with BuildKit, an NVIDIA GPU/NVIDIA Container Toolkit, the sinapsis-nvidia:base image, and access to the model and build dependencies. It gives the following commands:
cd invoice-extraction/dockerDOCKER_BUILDKIT=1 docker compose -f compose_test.yaml build --no-cache --ssh defaultdocker compose -f compose_test.yaml upOpen http://localhost:7860 on the Docker host. In Gradio, upload a PDF, PNG or JPG invoice and select Run Agent. The application displays JSON and makes an output file available for download.
This is the source-provided setup, not a tested public quickstart. Building requires access to some SSH-installed repositories, GPU dependencies and model weights.
See Templates and Agent Model for the computation model behind these flows.
Published from Git revision 7b7ba25d627b