mirror of
https://github.com/run-llama/invoice-extraction-vibe-coding.git
synced 2026-06-30 21:27:54 -04:00
cr
This commit is contained in:
@@ -20,190 +20,3 @@ agent = extract.get_agent(name="kaggle_invoice_agent")
|
||||
result = agent.extract("batch1-0274.jpg")
|
||||
result.data # outputs json of the extracted output according to the schema defined in the agent
|
||||
|
||||
|
||||
|
||||
#### NOTE: HERE IS THE SCHEMA DEFINITION
|
||||
# {
|
||||
# "additionalProperties": false,
|
||||
# "properties": {
|
||||
# "invoice_number": {
|
||||
# "description": "The unique identifier for the invoice.",
|
||||
# "type": "string"
|
||||
# },
|
||||
# "issue_date": {
|
||||
# "description": "The date the invoice was issued, formatted as MM/DD/YYYY.",
|
||||
# "type": "string"
|
||||
# },
|
||||
# "seller": {
|
||||
# "additionalProperties": false,
|
||||
# "description": "Information about the seller.",
|
||||
# "properties": {
|
||||
# "name": {
|
||||
# "description": "The name of the seller.",
|
||||
# "type": "string"
|
||||
# },
|
||||
# "address": {
|
||||
# "description": "The address of the seller.",
|
||||
# "type": "string"
|
||||
# },
|
||||
# "tax_id": {
|
||||
# "description": "The tax identification number of the seller.",
|
||||
# "type": "string"
|
||||
# },
|
||||
# "iban": {
|
||||
# "description": "The International Bank Account Number of the seller.",
|
||||
# "type": "string"
|
||||
# }
|
||||
# },
|
||||
# "required": [
|
||||
# "name",
|
||||
# "address",
|
||||
# "tax_id",
|
||||
# "iban"
|
||||
# ],
|
||||
# "type": "object"
|
||||
# },
|
||||
# "client": {
|
||||
# "additionalProperties": false,
|
||||
# "description": "Information about the client.",
|
||||
# "properties": {
|
||||
# "name": {
|
||||
# "description": "The name of the client.",
|
||||
# "type": "string"
|
||||
# },
|
||||
# "address": {
|
||||
# "description": "The address of the client.",
|
||||
# "type": "string"
|
||||
# },
|
||||
# "tax_id": {
|
||||
# "description": "The tax identification number of the client.",
|
||||
# "type": "string"
|
||||
# }
|
||||
# },
|
||||
# "required": [
|
||||
# "name",
|
||||
# "address",
|
||||
# "tax_id"
|
||||
# ],
|
||||
# "type": "object"
|
||||
# },
|
||||
# "items": {
|
||||
# "description": "A list of items included in the invoice.",
|
||||
# "items": {
|
||||
# "additionalProperties": false,
|
||||
# "properties": {
|
||||
# "item_number": {
|
||||
# "description": "The item number or identifier.",
|
||||
# "type": "string"
|
||||
# },
|
||||
# "description": {
|
||||
# "description": "A description of the item.",
|
||||
# "type": "string"
|
||||
# },
|
||||
# "quantity": {
|
||||
# "description": "The quantity of the item.",
|
||||
# "type": "number"
|
||||
# },
|
||||
# "unit_of_measure": {
|
||||
# "description": "The unit of measure for the item (e.g., each, kg, liter).",
|
||||
# "type": "string"
|
||||
# },
|
||||
# "net_price": {
|
||||
# "description": "The net price of the item.",
|
||||
# "type": "number"
|
||||
# },
|
||||
# "net_worth": {
|
||||
# "description": "The net worth of the item (quantity * net_price).",
|
||||
# "type": "number"
|
||||
# },
|
||||
# "vat_percentage": {
|
||||
# "description": "The VAT percentage applied to the item.",
|
||||
# "type": "string"
|
||||
# },
|
||||
# "gross_worth": {
|
||||
# "description": "The gross worth of the item (including VAT).",
|
||||
# "type": "number"
|
||||
# }
|
||||
# },
|
||||
# "required": [
|
||||
# "item_number",
|
||||
# "description",
|
||||
# "quantity",
|
||||
# "unit_of_measure",
|
||||
# "net_price",
|
||||
# "net_worth",
|
||||
# "vat_percentage",
|
||||
# "gross_worth"
|
||||
# ],
|
||||
# "type": "object"
|
||||
# },
|
||||
# "type": "array"
|
||||
# },
|
||||
# "summary": {
|
||||
# "additionalProperties": false,
|
||||
# "description": "Summary of the invoice amounts.",
|
||||
# "properties": {
|
||||
# "vat_summary": {
|
||||
# "description": "Summary of VAT amounts for different VAT percentages.",
|
||||
# "items": {
|
||||
# "additionalProperties": false,
|
||||
# "properties": {
|
||||
# "vat_percentage": {
|
||||
# "description": "The VAT percentage.",
|
||||
# "type": "string"
|
||||
# },
|
||||
# "net_worth": {
|
||||
# "description": "The total net worth for this VAT percentage.",
|
||||
# "type": "number"
|
||||
# },
|
||||
# "vat": {
|
||||
# "description": "The total VAT amount for this VAT percentage.",
|
||||
# "type": "number"
|
||||
# },
|
||||
# "gross_worth": {
|
||||
# "description": "The total gross worth for this VAT percentage.",
|
||||
# "type": "number"
|
||||
# }
|
||||
# },
|
||||
# "required": [
|
||||
# "vat_percentage",
|
||||
# "net_worth",
|
||||
# "vat",
|
||||
# "gross_worth"
|
||||
# ],
|
||||
# "type": "object"
|
||||
# },
|
||||
# "type": "array"
|
||||
# },
|
||||
# "total_net_worth": {
|
||||
# "description": "The total net worth of the invoice.",
|
||||
# "type": "number"
|
||||
# },
|
||||
# "total_vat": {
|
||||
# "description": "The total VAT amount for the invoice.",
|
||||
# "type": "number"
|
||||
# },
|
||||
# "total_gross_worth": {
|
||||
# "description": "The total gross worth of the invoice.",
|
||||
# "type": "number"
|
||||
# }
|
||||
# },
|
||||
# "required": [
|
||||
# "vat_summary",
|
||||
# "total_net_worth",
|
||||
# "total_vat",
|
||||
# "total_gross_worth"
|
||||
# ],
|
||||
# "type": "object"
|
||||
# }
|
||||
# },
|
||||
# "required": [
|
||||
# "invoice_number",
|
||||
# "issue_date",
|
||||
# "seller",
|
||||
# "client",
|
||||
# "items",
|
||||
# "summary"
|
||||
# ],
|
||||
# "type": "object"
|
||||
# }
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 206 KiB |
@@ -0,0 +1,56 @@
|
||||
from pydantic import BaseModel
|
||||
from typing import List
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
class Seller(BaseModel):
|
||||
"""Information about the seller."""
|
||||
name: str
|
||||
address: str
|
||||
tax_id: str
|
||||
iban: str
|
||||
|
||||
|
||||
class Client(BaseModel):
|
||||
"""Information about the client."""
|
||||
name: str
|
||||
address: str
|
||||
tax_id: str
|
||||
|
||||
|
||||
class Item(BaseModel):
|
||||
"""Individual item in the invoice."""
|
||||
item_number: str
|
||||
description: str
|
||||
quantity: float
|
||||
unit_of_measure: str
|
||||
net_price: float
|
||||
net_worth: float
|
||||
vat_percentage: str
|
||||
gross_worth: float
|
||||
|
||||
|
||||
class VatSummaryEntry(BaseModel):
|
||||
"""VAT summary for a specific VAT percentage."""
|
||||
vat_percentage: str
|
||||
net_worth: float
|
||||
vat: float
|
||||
gross_worth: float
|
||||
|
||||
|
||||
class Summary(BaseModel):
|
||||
"""Summary of the invoice amounts."""
|
||||
vat_summary: List[VatSummaryEntry]
|
||||
total_net_worth: float
|
||||
total_vat: float
|
||||
total_gross_worth: float
|
||||
|
||||
|
||||
class Invoice(BaseModel):
|
||||
"""Complete invoice model."""
|
||||
invoice_number: str
|
||||
issue_date: str # Formatted as MM/DD/YYYY
|
||||
seller: Seller
|
||||
client: Client
|
||||
items: List[Item]
|
||||
summary: Summary
|
||||
@@ -1,90 +0,0 @@
|
||||
{
|
||||
"invoice_number": "65123866",
|
||||
"issue_date": "11/20/2012",
|
||||
"seller": {
|
||||
"name": "Potts, Pittman and Beck",
|
||||
"address": "USNV Stone\nFPO AE 65337",
|
||||
"tax_id": "970-95-1799",
|
||||
"iban": "GB55YMCM02538391714621"
|
||||
},
|
||||
"client": {
|
||||
"name": "Garcia-Perkins",
|
||||
"address": "897 Gonzalez Junction Apt. 934\nJesseburgh, MN 12053",
|
||||
"tax_id": "992-87-3315"
|
||||
},
|
||||
"items": [
|
||||
{
|
||||
"item_number": "1.",
|
||||
"description": "The Four Agreements: A Practical Guide to Personal Freedom by Don Miguel Ruiz",
|
||||
"quantity": 1.0,
|
||||
"unit_of_measure": "each",
|
||||
"net_price": 3.3,
|
||||
"net_worth": 3.3,
|
||||
"vat_percentage": "10%",
|
||||
"gross_worth": 3.63
|
||||
},
|
||||
{
|
||||
"item_number": "2.",
|
||||
"description": "The World of Van Gogh from Time Life Library of Art",
|
||||
"quantity": 4.0,
|
||||
"unit_of_measure": "each",
|
||||
"net_price": 14.97,
|
||||
"net_worth": 59.88,
|
||||
"vat_percentage": "10%",
|
||||
"gross_worth": 65.87
|
||||
},
|
||||
{
|
||||
"item_number": "3.",
|
||||
"description": "Principles of Virology, 2 Volume Set (ASM Books)",
|
||||
"quantity": 5.0,
|
||||
"unit_of_measure": "each",
|
||||
"net_price": 121.9,
|
||||
"net_worth": 609.5,
|
||||
"vat_percentage": "10%",
|
||||
"gross_worth": 670.45
|
||||
},
|
||||
{
|
||||
"item_number": "4.",
|
||||
"description": "A boy who grew up eating nightmare It's Okay to Not Be Okay Picturebook",
|
||||
"quantity": 3.0,
|
||||
"unit_of_measure": "each",
|
||||
"net_price": 19.5,
|
||||
"net_worth": 58.5,
|
||||
"vat_percentage": "10%",
|
||||
"gross_worth": 64.35
|
||||
},
|
||||
{
|
||||
"item_number": "5.",
|
||||
"description": "The Value Of Time",
|
||||
"quantity": 5.0,
|
||||
"unit_of_measure": "each",
|
||||
"net_price": 17.73,
|
||||
"net_worth": 88.65,
|
||||
"vat_percentage": "10%",
|
||||
"gross_worth": 97.52
|
||||
},
|
||||
{
|
||||
"item_number": "6.",
|
||||
"description": "The Home Stretch",
|
||||
"quantity": 2.0,
|
||||
"unit_of_measure": "each",
|
||||
"net_price": 5.38,
|
||||
"net_worth": 10.76,
|
||||
"vat_percentage": "10%",
|
||||
"gross_worth": 11.84
|
||||
}
|
||||
],
|
||||
"summary": {
|
||||
"vat_summary": [
|
||||
{
|
||||
"vat_percentage": "10%",
|
||||
"net_worth": 830.59,
|
||||
"vat": 83.06,
|
||||
"gross_worth": 913.65
|
||||
}
|
||||
],
|
||||
"total_net_worth": 830.59,
|
||||
"total_vat": 83.06,
|
||||
"total_gross_worth": 913.65
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user