LayoutLM Document QA
A multimodal model that takes an image of a document or invoice and answers questions about the document in natural language.
Deploy LayoutLM Document QA behind an API endpoint in seconds.
Deploy modelExample usage
This code example shows how to invoke the model using the requests library in Python. The model has two inputs:
url
: The URL for the input imageprompt
: The input text sent to the model
The output is a list containing a JSON object. Inside the JSON object the key called answer
contains the output of the model.
1import requests
2import os
3
4# Replace the empty string with your model id below
5model_id = ""
6baseten_api_key = os.environ["BASETEN_API_KEY"]
7
8data = {
9 "url": "https://templates.invoicehome.com/invoice-template-us-neat-750px.png",
10 "prompt": "What is the invoice number?"
11}
12
13# Call model endpoint
14res = requests.post(
15 f"https://model-{model_id}.api.baseten.co/production/predict",
16 headers={"Authorization": f"Api-Key {baseten_api_key}"},
17 json=data
18)
19
20# Print the output of the model
21print(res.json())
1[
2 {
3 "score": 0.34037861227989197,
4 "answer": "us-001",
5 "start": 16,
6 "end": 16
7 }
8]