Update information_extraction.py
Browse files- information_extraction.py +38 -38
information_extraction.py
CHANGED
|
@@ -67,41 +67,41 @@ def extract_invoice(image_path:str)->str:
|
|
| 67 |
)
|
| 68 |
|
| 69 |
|
| 70 |
-
## Task 1 extraction task
|
| 71 |
-
|
| 72 |
-
extraction_task = Task (
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
### Task 2 JSON
|
| 83 |
-
|
| 84 |
-
formatting_task = Task (
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
crew = Crew(
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
return crew.kickoff()
|
|
|
|
| 67 |
)
|
| 68 |
|
| 69 |
|
| 70 |
+
## Task 1 extraction task
|
| 71 |
+
|
| 72 |
+
extraction_task = Task (
|
| 73 |
+
description = (
|
| 74 |
+
f"Use the Invoice Reader tool to read the invoice image "
|
| 75 |
+
f"at the path '{image_path}'. extract the vendor name , tax id, invoice number, "
|
| 76 |
+
f"date, item rows, total gross"
|
| 77 |
+
),
|
| 78 |
+
expected_output = "structured invoice text",
|
| 79 |
+
agent = visual_reader
|
| 80 |
+
)
|
| 81 |
+
|
| 82 |
+
### Task 2 JSON
|
| 83 |
+
|
| 84 |
+
formatting_task = Task (
|
| 85 |
+
description = (
|
| 86 |
+
"Convert the extracted invoice text into JSON. \n\n"
|
| 87 |
+
"{\n"
|
| 88 |
+
"'invoice_no' : str, \n"
|
| 89 |
+
"'date': 'YYYY-MM-DD',\n"
|
| 90 |
+
" 'vendor':{'name':str,'tax_id':str},\n "
|
| 91 |
+
" 'items' :[{'description':str,'quantity':float,'net_price':float}] ,\n"
|
| 92 |
+
"}\n\n"
|
| 93 |
+
"Rules:\n"
|
| 94 |
+
"- if missing value use null \n"
|
| 95 |
+
" - Output only JSON"
|
| 96 |
+
),
|
| 97 |
+
expected_output = "Valid JSON Only",
|
| 98 |
+
agent = json_architect,
|
| 99 |
+
context = [extraction_task]
|
| 100 |
+
)
|
| 101 |
+
crew = Crew(
|
| 102 |
+
agents = [visual_reader,json_architect],
|
| 103 |
+
tasks = [extraction_task,formatting_task],
|
| 104 |
+
process = Process.sequential,
|
| 105 |
+
verbose =True)
|
| 106 |
+
|
| 107 |
+
return crew.kickoff()
|