File size: 1,904 Bytes
e2eec89
7a6af4c
 
 
e2eec89
7a6af4c
 
 
 
 
b6beb2d
7a6af4c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
"""Quick manual smoke script: run process_document on a real document.

Usage:
    uv run python scripts/smoke_gemini.py path/to/receipt.jpg
    uv run python scripts/smoke_gemini.py path/to/invoice.pdf
"""

import sys
from pathlib import Path

from docfield.core import process_document


def main() -> None:
    """Run the pipeline on a single image and print the result."""
    if len(sys.argv) != 2:
        print("Usage: uv run python scripts/smoke_gemini.py <image_path>")
        sys.exit(1)

    path = Path(sys.argv[1])
    if not path.exists():
        print(f"File not found: {path}")
        sys.exit(1)

    print(f"Processing: {path}")
    result = process_document(path)

    print(f"\ndecision     : {result.decision}")
    print(f"confidence   : {result.confidence:.3f}")
    print(f"backend      : {result.backend_name}")
    print(f"modality     : {result.modality}")
    if result.error:
        print(f"error        : {result.error}")

    doc = result.document
    print("\n--- extracted fields ---")
    print(f"doc_type     : {doc.doc_type}")
    print(f"vendor_name  : {doc.vendor_name}")
    print(f"invoice_num  : {doc.invoice_number}")
    print(f"date         : {doc.document_date}")
    print(f"currency     : {doc.currency}")
    print(f"subtotal     : {doc.subtotal}")
    print(f"tax          : {doc.tax}")
    print(f"total        : {doc.total}")
    print(f"line_items   : {len(doc.line_items)} item(s)")
    for item in doc.line_items:
        print(f"  {item.description}  qty={item.quantity}  price={item.unit_price}  amt={item.amount}")

    print("\n--- validation ---")
    v = result.report
    print(f"hard_failed  : {v.hard_failed}")
    if v.hard_failures:
        print(f"hard failures: {[r.code for r in v.hard_failures]}")
    if v.soft_failures:
        print(f"soft failures: {[r.code for r in v.soft_failures]}")


if __name__ == "__main__":
    main()