Skip to main content

Reading an Invoice

The following code snippet demonstrates how to extract information from an invoice. It uses a form to read the invoice file and then prompts the AI to extract specific details such as the value of the service and the CNPJ (a Brazilian tax identification number).

from abstra.forms import FileInput, run
from abstra.ai import prompt

page = [FileInput("Update your invoice here", key="invoice")]
res = run([page])

ans = prompt(
["Here is an invoice", page["invoice"]],
format={
"value": { "type": "number", "description": "Value of the service in dollars" },
"CNPJ": { "type": "string" }
}
)

value = ans["value"]
cnpj = ans["CNPJ"]