Views
No views yet
This is fork of naver-clova-ix/donut-base-finetuned-cord-v2 implementing a customhandler.pyas an example for how to usedonutmodels with inference-endpoints
pip install requests)
wget https://huggingface.co/philschmid/donut-base-finetuned-cord-v2/resolve/main/sample.png1import json
2import requests as r
3import mimetypes
4
5ENDPOINT_URL="" # url of your endpoint
6HF_TOKEN="" # organization token where you deployed your endpoint
7
8def predict(path_to_image:str=None):
9 with open(path_to_image, "rb") as i:
10 b = i.read()
11 headers= {
12 "Authorization": f"Bearer {HF_TOKEN}",
13 "Content-Type": mimetypes.guess_type(path_to_image)[0]
14 }
15 response = r.post(ENDPOINT_URL, headers=headers, data=b)
16 return response.json()
17
18prediction = predict(path_to_image="sample.png")
19
20print(prediction)
21# {'menu': [{'nm': '0571-1854 BLUS WANITA',
22# 'unitprice': '@120.000',
23# 'cnt': '1',
24# 'price': '120,000'},
25# {'nm': '1002-0060 SHOPPING BAG', 'cnt': '1', 'price': '0'}],
26# 'total': {'total_price': '120,000',
27# 'changeprice': '0',
28# 'creditcardprice': '120,000',
29# 'menuqty_cnt': '1'}}1curl https://ak7gduay2ypyr9vp.us-east-1.aws.endpoints.huggingface.cloud \
2-X POST \
3--data-binary 'sample.png' \
4-H "Authorization: Bearer XXX" \
5-H "Content-Type: null"