This project uses RolmOCR (served locally via LM Studio OpenAI-compatible API) to:
- OCR invoices (PDF or image)
- Classify the invoice:
- Sector
- Use-case
- Output the JSON Schema for the predicted sector × use-case
- Detect invoice section bounding boxes and (optionally) write annotated images with boxes drawn:
vendor_block,buyer_block,invoice_meta,line_items,totals,payment,terms_notes
- Download a RolmOCR GGUF model in LM Studio (for example:
mradermacher/rolmocr) - Make sure vision works in LM Studio for that model (mmproj if required)
- Start Local Server and enable OpenAI-compatible API
- Endpoint is typically:
http://127.0.0.1:1234/v1
- Endpoint is typically:
- Confirm the server sees your model:
curl http://127.0.0.1:1234/v1/modelscd rolmoocr_invoice_project
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txtCreate a .env in the project root:
LMSTUDIO_BASE_URL=http://127.0.0.1:1234/v1
LMSTUDIO_MODEL=mradermacher/rolmocr
# keep outputs short (reduces context pressure)
MAX_TOKENS=512
TEMPERATURE=0
# render dpi (lower = fewer vision tokens)
DPI=150python3 -m invoice_rolmoocr.cli --input invoice22.pdf --out ./outOptional flags:
# disable bbox detection
python3 -m invoice_rolmoocr.cli --input invoice22.pdf --out ./out --no-bboxes
# disable annotated images
python3 -m invoice_rolmoocr.cli --input invoice22.pdf --out ./out --no-annotate
# (experimental) extraction to JSON using the selected schema
python3 -m invoice_rolmoocr.cli --input invoice22.pdf --out ./out --extractOutputs (in --out folder):
classification.jsonschema.jsonocr_text.txtbboxes.json(if enabled)page_0_annotated.png,page_1_annotated.png, ... (if enabled)
We do not rely on “anchor phrase bbox” (it only boxes labels).
Instead:
- Extract PDF words with PyMuPDF (
get_text("words")) - Build text blocks using PyMuPDF
block_nogrouping - Ask RolmOCR (text-only) to label each block into one of the standard sections
- Union the labeled block rectangles into a single bbox per section
- Small heuristic merges the right-side “values” column into
invoice_metawhen needed
- Render page to image
- Use a CV layout detector to propose regions
- OCR each region (RolmOCR)
- Ask RolmOCR to map region IDs to sections
- Union regions per section → bbox
This project prints LM Studio’s full error body. Common causes:
- Context overflow → reduce
DPIandMAX_TOKENS, or increase context length in LM Studio - Model does not support vision → attach the required mmproj and restart the server
