Commit
·
84facbd
1
Parent(s):
a0a6251
Update README.md
Browse files
README.md
CHANGED
|
@@ -1,3 +1,79 @@
|
|
| 1 |
---
|
| 2 |
license: apache-2.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
license: apache-2.0
|
| 3 |
+
tags:
|
| 4 |
+
- trocr
|
| 5 |
+
- image-to-text
|
| 6 |
+
- endpoints-template
|
| 7 |
+
library_name: generic
|
| 8 |
---
|
| 9 |
+
|
| 10 |
+
## Run Request
|
| 11 |
+
|
| 12 |
+
The endpoint expects the image to be served as `binary`. Below is an curl and python example
|
| 13 |
+
|
| 14 |
+
#### cURL
|
| 15 |
+
|
| 16 |
+
1. get image
|
| 17 |
+
|
| 18 |
+
```bash
|
| 19 |
+
wget https://fki.tic.heia-fr.ch/static/img/a01-122-02-00.jpg -O test.jpg
|
| 20 |
+
```
|
| 21 |
+
|
| 22 |
+
2. send cURL request
|
| 23 |
+
|
| 24 |
+
```bash
|
| 25 |
+
curl --request POST \
|
| 26 |
+
--url https://{ENDPOINT}/ \
|
| 27 |
+
--header 'Content-Type: image/jpg' \
|
| 28 |
+
--header 'Authorization: Bearer {HF_TOKEN}' \
|
| 29 |
+
--data-binary '@test.jpg'
|
| 30 |
+
```
|
| 31 |
+
|
| 32 |
+
3. the expected output
|
| 33 |
+
|
| 34 |
+
```json
|
| 35 |
+
{"text": "INDLUS THE"}
|
| 36 |
+
```
|
| 37 |
+
|
| 38 |
+
#### Python
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
1. get image
|
| 42 |
+
|
| 43 |
+
```bash
|
| 44 |
+
wget https://fki.tic.heia-fr.ch/static/img/a01-122-02-00.jpg -O test.jpg
|
| 45 |
+
```
|
| 46 |
+
|
| 47 |
+
2. run request
|
| 48 |
+
|
| 49 |
+
```python
|
| 50 |
+
import json
|
| 51 |
+
from typing import List
|
| 52 |
+
import requests as r
|
| 53 |
+
import base64
|
| 54 |
+
|
| 55 |
+
ENDPOINT_URL=""
|
| 56 |
+
HF_TOKEN=""
|
| 57 |
+
|
| 58 |
+
def predict(path_to_image:str=None):
|
| 59 |
+
with open(path_to_image, "rb") as i:
|
| 60 |
+
b = i.read()
|
| 61 |
+
headers= {
|
| 62 |
+
"Authorization": f"Bearer {HF_TOKEN}",
|
| 63 |
+
"Content-Type": "image/jpeg" # content type of image
|
| 64 |
+
}
|
| 65 |
+
response = r.post(ENDPOINT_URL, headers=headers, data=b)
|
| 66 |
+
return response.json()
|
| 67 |
+
|
| 68 |
+
prediction = predict(path_to_image="test.jpg")
|
| 69 |
+
|
| 70 |
+
prediction
|
| 71 |
+
```
|
| 72 |
+
|
| 73 |
+
expected output
|
| 74 |
+
|
| 75 |
+
```python
|
| 76 |
+
{"text": "INDLUS THE"}
|
| 77 |
+
```
|
| 78 |
+
|
| 79 |
+
|