-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain_claude_invoice_format_ocr.py
41 lines (31 loc) · 1.36 KB
/
main_claude_invoice_format_ocr.py
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
import os
from datetime import datetime
import json
from agents.ocr.claude_invoice_format_ocr import extract_text_from_image
def main():
data_folder = "data/input_images"
image_files = [f for f in os.listdir(data_folder) if f.lower().endswith(('.png', '.jpg', '.jpeg', '.gif', '.bmp'))]
if not image_files:
print("No image files found in the data folder.")
return
output_folder = "data/extracted_text"
os.makedirs(output_folder, exist_ok=True)
for image_file in image_files:
image_path = os.path.join(data_folder, image_file)
print(f"Processing image: {image_file}")
try:
result = extract_text_from_image(image_path)
print("Extracted text:")
print(result)
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
output_filename = f"{timestamp}_{os.path.splitext(image_file)[0]}.json"
output_path = os.path.join(output_folder, output_filename)
with open(output_path, 'w', encoding='utf-8') as f:
json.dump(result, f, indent=2)
print(f"Saved extracted data to: {output_path}")
print("-" * 50)
except Exception as e:
print(f"Error processing {image_file}: {str(e)}")
print("-" * 50)
if __name__ == "__main__":
main()