Commit
·
9a910af
1
Parent(s):
c1fe10d
Update README.md
Browse files
README.md
CHANGED
@@ -2,54 +2,88 @@
|
|
2 |
tags:
|
3 |
- trocr
|
4 |
- image-to-text
|
|
|
|
|
5 |
---
|
6 |
|
7 |
-
#
|
8 |
|
9 |
-
|
10 |
|
11 |
-
|
12 |
|
13 |
-
##
|
14 |
|
15 |
-
The
|
16 |
|
17 |
-
|
18 |
|
19 |
-
|
20 |
|
21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
-
### How to use
|
24 |
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
|
27 |
```python
|
28 |
-
|
29 |
-
from
|
30 |
-
import requests
|
|
|
|
|
|
|
|
|
|
|
31 |
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
|
36 |
-
|
37 |
-
|
38 |
-
|
|
|
|
|
39 |
|
40 |
-
|
41 |
-
|
|
|
|
|
42 |
```
|
43 |
|
44 |
-
|
45 |
-
|
46 |
-
```
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
}
|
55 |
-
```
|
|
|
2 |
tags:
|
3 |
- trocr
|
4 |
- image-to-text
|
5 |
+
- endpoints-template
|
6 |
+
library_name: generic
|
7 |
---
|
8 |
|
9 |
+
# Fork of [microsoft/trocr-base-printed](https://huggingface.co/microsoft/trocr-base-printed) for an `OCR` Inference endpoint.
|
10 |
|
11 |
+
This repository implements a `custom` task for `ocr-detection` for 🤗 Inference Endpoints. The code for the customized pipeline is in the [pipeline.py](https://huggingface.co/philschmid/trocr-base-printed/blob/main/pipeline.py).
|
12 |
|
13 |
+
To use deploy this model as an Inference Endpoint, you have to select `Custom` as the task to use the `pipeline.py` file. -> _double check if it is selected_
|
14 |
|
15 |
+
## Run Request
|
16 |
|
17 |
+
The endpoint expects the image to be served as `binary`. Below is an curl and python example
|
18 |
|
19 |
+
#### cURL
|
20 |
|
21 |
+
1. get image
|
22 |
|
23 |
+
```bash
|
24 |
+
wget https://fki.tic.heia-fr.ch/static/img/a01-122-02-00.jpg -O test.jpg
|
25 |
+
```
|
26 |
+
|
27 |
+
2. send cURL request
|
28 |
+
|
29 |
+
```bash
|
30 |
+
curl --request POST \
|
31 |
+
--url https://{ENDPOINT}/ \
|
32 |
+
--header 'Content-Type: image/jpg' \
|
33 |
+
--header 'Authorization: Bearer {HF_TOKEN}' \
|
34 |
+
--data-binary '@test.jpg'
|
35 |
+
```
|
36 |
+
|
37 |
+
3. the expected output
|
38 |
+
|
39 |
+
```json
|
40 |
+
{"text": "INDLUS THE"
|
41 |
+
```
|
42 |
+
|
43 |
+
#### Python
|
44 |
|
|
|
45 |
|
46 |
+
1. get image
|
47 |
+
|
48 |
+
```bash
|
49 |
+
wget https://fki.tic.heia-fr.ch/static/img/a01-122-02-00.jpg -O test.jpg
|
50 |
+
```
|
51 |
+
|
52 |
+
2. run request
|
53 |
|
54 |
```python
|
55 |
+
import json
|
56 |
+
from typing import List
|
57 |
+
import requests as r
|
58 |
+
import base64
|
59 |
+
|
60 |
+
ENDPOINT_URL = ""
|
61 |
+
HF_TOKEN = ""
|
62 |
+
|
63 |
|
64 |
+
def predict(path_to_image: str = None, candiates: List[str] = None):
|
65 |
+
with open(path_to_image, "rb") as i:
|
66 |
+
b64 = base64.b64encode(i.read())
|
67 |
|
68 |
+
payload = {"inputs": {"image": b64.decode("utf-8"), "candiates": candiates}}
|
69 |
+
response = r.post(
|
70 |
+
ENDPOINT_URL, headers={"Authorization": f"Bearer {HF_TOKEN}"}, json=payload
|
71 |
+
)
|
72 |
+
return response.json()
|
73 |
|
74 |
+
|
75 |
+
prediction = predict(
|
76 |
+
path_to_image="palace.jpg", candiates=["sea", "palace", "car", "ship"]
|
77 |
+
)
|
78 |
```
|
79 |
|
80 |
+
expected output
|
81 |
+
|
82 |
+
```python
|
83 |
+
[{'label': 'palace', 'score': 0.9996134638786316},
|
84 |
+
{'label': 'car', 'score': 0.0002602009626571089},
|
85 |
+
{'label': 'ship', 'score': 0.00011758189066313207},
|
86 |
+
{'label': 'sea', 'score': 8.666840585647151e-06}]
|
87 |
+
```
|
88 |
+
|
89 |
+
|
|
|
|