File size: 925 Bytes
c1b1f3a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from typing import List, Dict, Optional, Any
from pydantic import BaseModel, Field

class OCRWord(BaseModel):
    text: str
    bbox: List[int] = Field(default_factory=lambda: [0, 0, 0, 0])  # [xmin, ymin, xmax, ymax]
    conf: float = 1.0

class DocumentRecord(BaseModel):
    doc_id: str
    source_dataset: str
    doc_class: str  # "invoice" | "receipt" | "application_form"
    image_path: str
    ocr_words: List[OCRWord] = Field(default_factory=list)
    fields: Dict[str, Optional[Any]] = Field(default_factory=dict)

CLASS_FIELD_SCHEMAS = {
    "invoice": [
        "invoice_number",
        "invoice_date",
        "seller_name",
        "buyer_name",
        "total_amount"
    ],
    "receipt": [
        "company_name",
        "date",
        "address",
        "total_amount"
    ],
    "application_form": [
        "applicant_name",
        "date",
        "address",
        "other_key_value_pairs"
    ]
}