-
Notifications
You must be signed in to change notification settings - Fork 126
Expand file tree
/
Copy pathexample.py
More file actions
67 lines (35 loc) · 1.18 KB
/
example.py
File metadata and controls
67 lines (35 loc) · 1.18 KB
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
61
62
63
64
65
66
67
from docstrange import DocumentExtractor
file_path = "sample_documents/invoice.pdf"
extractor = DocumentExtractor()
result = extractor.extract(file_path).extract_data(specified_fields=[
"total_amount",
"date",
"vendor_name",
"invoice_number"
])
print(result)
exit()
print("📝=============================== JSON Output:===============================")
result = extractor.extract(file_path).extract_data()
print(result)
print("\n📝=============================== Specific Field :===============================")
result = extractor.extract(file_path)
specific_fields = result.extract_data(specified_fields=[
"total_amount",
"date",
"vendor_name",
"invoice_number"
])
print(specific_fields)
print("\n📝=============================== JSON Schema Extraction:===============================")
schema = {
"invoice_number": "string",
"total_amount": "number",
"vendor_name": "string",
"items": [{
"description": "string",
"amount": "number"
}]
}
structured_data = result.extract_data(json_schema=schema)
print(structured_data)