Add crop refinement, finger removal, and local LLM naming

- vision/refine.py: tighten crops to the paper band (removes mat
  margins and hands beside receipts) and inpaint border-connected
  skin regions so fingers disappear from output
- llm/vision.py: identify documents with a local Ollama vision model
  (qwen2.5vl); extracts vendor/date/total/form code and flags quality
  issues (fingers, blur, glare); falls back to Tesseract when down
- pipeline: drop blank pages, dedupe consecutive captures of the same
  document, record refine/LLM fields in report and export summary
This commit is contained in:
2026-07-08 18:23:50 -04:00
parent 2c28a623fb
commit a43ab20df6
22 changed files with 1497 additions and 111 deletions
+16
View File
@@ -46,6 +46,22 @@ def test_build_name_nothing_found():
assert result.source == "none"
def test_build_name_tax_form_with_year_and_org():
dt = datetime(2026, 1, 1, 12, 0, 0)
result = build_name(
None, "T4 YORK UNIVERSITY", dt,
form_code="T4", tax_year="2023", org_name="YORK UNIVERSITY",
)
assert result.stem == "2023_T4_york_university"
assert result.source == "ocr"
def test_build_name_tax_form_year_only():
dt = datetime(2026, 1, 1, 12, 0, 0)
result = build_name(None, "T4", dt, form_code="T4", tax_year="2023")
assert result.stem == "2023_T4"
def test_dedupe_stem_no_collision():
used: set[str] = set()
assert dedupe_stem("2023-03-14_metro", used) == "2023-03-14_metro"