-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.py
More file actions
87 lines (69 loc) · 2.5 KB
/
example.py
File metadata and controls
87 lines (69 loc) · 2.5 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/env python3
"""
Example script demonstrating SmartOrderReader usage.
This can be used as a starting point for integrating SmartOrderReader
into your own applications.
"""
from order_reader import OrderDataExtractor, format_output, save_csv
def example_usage():
"""Example of using SmartOrderReader programmatically."""
# Initialize the extractor
# Use 'eng' for English only, 'eng+urd' for English + Urdu
extractor = OrderDataExtractor(lang='eng')
# Example: Process a single image
print("Example 1: Processing a single image")
print("-" * 50)
image_path = "sample_invoice.jpg"
# result = extractor.process_image(image_path)
# print(f"Filename: {result['Image File Name']}")
# print(f"Order Number: {result['Order Number']}")
# print(f"Order Date: {result['Order Date']}")
print("(Uncomment the code above when you have a real image)")
print("\n")
# Example: Process multiple images
print("Example 2: Processing multiple images")
print("-" * 50)
image_paths = [
"invoice1.jpg",
"invoice2.png",
"receipt.jpg"
]
# results = extractor.process_images(image_paths)
#
# # Display formatted output
# output = format_output(results)
# print(output)
#
# # Save to CSV
# save_csv(results, "extracted_data.csv")
print("(Uncomment the code above when you have real images)")
print("\n")
# Example: Access individual results
print("Example 3: Working with results programmatically")
print("-" * 50)
# Example result structure
example_results = [
{
'Image File Name': 'invoice1.jpg',
'Order Number': 'ABC12345',
'Order Date': '12/25/2023'
},
{
'Image File Name': 'invoice2.png',
'Order Number': 'Not Found',
'Order Date': '01/15/2024'
}
]
print("Example of iterating through results:")
for result in example_results:
print(f"\nFile: {result['Image File Name']}")
if result['Order Number'] != 'Not Found':
print(f" ✓ Order Number: {result['Order Number']}")
else:
print(f" ✗ Order Number: {result['Order Number']}")
if result['Order Date'] != 'Not Found':
print(f" ✓ Order Date: {result['Order Date']}")
else:
print(f" ✗ Order Date: {result['Order Date']}")
if __name__ == '__main__':
example_usage()