invoice_ocr.py
1 #!/usr/bin/env python3 2 # _*_ coding: utf-8 _*_ 3 4 """ 5 @Time : 2023/9/21 21:40:57 6 @Author : Stitch-z 7 @File : invoice_ocr.py 8 """ 9 10 import asyncio 11 from pathlib import Path 12 13 from metagpt.roles.invoice_ocr_assistant import InvoiceOCRAssistant, InvoicePath 14 from metagpt.schema import Message 15 16 17 async def main(): 18 relative_paths = [ 19 Path("../tests/data/invoices/invoice-1.pdf"), 20 Path("../tests/data/invoices/invoice-2.png"), 21 Path("../tests/data/invoices/invoice-3.jpg"), 22 Path("../tests/data/invoices/invoice-4.zip"), 23 ] 24 # The absolute path of the file 25 absolute_file_paths = [Path.cwd() / path for path in relative_paths] 26 27 for path in absolute_file_paths: 28 role = InvoiceOCRAssistant() 29 await role.run(Message(content="Invoicing date", instruct_content=InvoicePath(file_path=path))) 30 31 32 if __name__ == "__main__": 33 asyncio.run(main())