Downloads · 30 days
58
4% of all-time downloads
philschmid/donut-base-finetuned-cord-v2
donut-base-finetuned-cord-v2 is a image-to-text model from philschmid. Use it when you need a caption or text from an image. It is set up for transformers. The card lists the license as mit.
This is fork of naver-clova-ix/donut-base-finetuned-cord-v2 implementing a custom handler.py as an example for how to use donut models with inference-endpoints
Downloads · 30 days
58
4% of all-time downloads
All-time downloads
1.4K
Public
Repo size
1.6 GB
Likes
6
Public
Click a slice to open those files.
.bin806 MB · 99%
From the Hugging Face model README
This is fork of naver-clova-ix/donut-base-finetuned-cord-v2 implementing a custom
handler.pyas an example for how to usedonutmodels with inference-endpoints
Donut model fine-tuned on CORD. It was introduced in the paper OCR-free Document Understanding Transformer by Geewok et al. and first released in this repository.
Donut consists of a vision encoder (Swin Transformer) and a text decoder (BART). Given an image, the encoder first encodes the image into a tensor of embeddings (of shape batch_size, seq_len, hidden_size), after which the decoder autoregressively generates text, conditioned on the encoding of the encoder.
Hugging Face Inference endpoints can directly work with binary data, this means that we can directly send our image from our document to the endpoint. We are going to use requests to send our requests. (make your you have it installed pip install requests)

load sample image
wget https://huggingface.co/philschmid/donut-base-finetuned-cord-v2/resolve/main/sample.png
send request to endpoint
import json
import requests as r
import mimetypes
ENDPOINT_URL="" # url of your endpoint
HF_TOKEN="" # organization token where you deployed your endpoint
def predict(path_to_image:str=None):
with open(path_to_image, "rb") as i:
b = i.read()
headers= {
"Authorization": f"Bearer {HF_TOKEN}",
"Content-Type": mimetypes.guess_type(path_to_image)[0]
}
response = r.post(ENDPOINT_URL, headers=headers, data=b)
return response.json()
prediction = predict(path_to_image="sample.png")
print(prediction)
# {'menu': [{'nm': '0571-1854 BLUS WANITA',
# 'unitprice': '@120.000',
# 'cnt': '1',
# 'price': '120,000'},
# {'nm': '1002-0060 SHOPPING BAG', 'cnt': '1', 'price': '0'}],
# 'total': {'total_price': '120,000',
# 'changeprice': '0',
# 'creditcardprice': '120,000',
# 'menuqty_cnt': '1'}}
curl example
curl https://ak7gduay2ypyr9vp.us-east-1.aws.endpoints.huggingface.cloud \
-X POST \
--data-binary 'sample.png' \
-H "Authorization: Bearer XXX" \
-H "Content-Type: null"