File size: 1,765 Bytes
3419651
 
 
 
9a910af
 
3419651
 
9a910af
3419651
9a910af
3419651
9a910af
3419651
9a910af
3419651
9a910af
3419651
9a910af
3419651
9a910af
3419651
9a910af
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2804c96
9a910af
 
 
3419651
 
9a910af
 
 
 
 
 
 
3419651
 
9a910af
 
 
 
 
2804c96
 
9a910af
2804c96
9a910af
2804c96
 
 
 
 
 
9a910af
3419651
2804c96
9a910af
2804c96
3419651
 
9a910af
 
 
2804c96
9a910af
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
---
tags:
- trocr
- image-to-text
- endpoints-template
library_name: generic
---

# Fork of [microsoft/trocr-base-printed](https://huggingface.co/microsoft/trocr-base-printed) for an `OCR` Inference endpoint.

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).

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_

## Run Request 

The endpoint expects the image to be served as `binary`. Below is an curl and python example

#### cURL 

1. get image 

```bash
wget https://fki.tic.heia-fr.ch/static/img/a01-122-02-00.jpg -O test.jpg
```

2. send cURL request

```bash
curl --request POST \
  --url https://{ENDPOINT}/ \
  --header 'Content-Type: image/jpg' \
  --header 'Authorization: Bearer {HF_TOKEN}' \
  --data-binary '@test.jpg'
```

3. the expected output

```json
{"text": "INDLUS THE"}
```

#### Python 


1. get image 

```bash
wget https://fki.tic.heia-fr.ch/static/img/a01-122-02-00.jpg -O test.jpg
```

2. run request

```python
import json
from typing import List
import requests as r
import base64

ENDPOINT_URL=""
HF_TOKEN=""

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": "image/jpeg" # content type of image
    }
    response = r.post(ENDPOINT_URL, headers=headers, data=b)
    return response.json()

prediction = predict(path_to_image="test.jpg")

prediction
```

expected output

```python
{"text": "INDLUS THE"}
```