philschmid HF staff commited on
Commit
7d2aaba
1 Parent(s): 3b9d5ee

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +32 -1
README.md CHANGED
@@ -25,7 +25,38 @@ Also make sure to add `server_name="0.0.0.0"` in your `launch()` call to make su
25
 
26
  ### Example API Request Payload
27
 
28
- ```json
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
 
30
  ```
31
 
 
25
 
26
  ### Example API Request Payload
27
 
28
+ get a image you want to use, e.g.
29
+
30
+ ```bash
31
+ !wget https://datasets-server.huggingface.co/assets/naver-clova-ix/cord-v2/--/naver-clova-ix--cord-v2/train/0/image/image.jpg
32
+ ```
33
+
34
+ run inference
35
+
36
+ ```python
37
+ import requests as r
38
+ import base64
39
+
40
+ ENDPOINT_URL = ""
41
+ HF_TOKEN = ""
42
+
43
+ def predict(path_to_image: str = None):
44
+ ext = path_to_image.split('.')[-1]
45
+ prefix = f'data:image/{ext};base64,'
46
+ with open(path_to_image, 'rb') as f:
47
+ img = f.read()
48
+
49
+ payload = {"data": [prefix + base64.b64encode(img).decode('utf-8')]}
50
+ response = r.post(
51
+ f"{ENDPOINT_URL}/api/predict", headers={"Authorization": f"Bearer {HF_TOKEN}"}, json=payload
52
+ )
53
+ if response.status_code == 200:
54
+ return response.json()
55
+ else:
56
+ raise Exception(f"Error: {response.status_code}")
57
+
58
+
59
+ prediction = predict(path_to_image="image.jpg")
60
 
61
  ```
62