philschmid HF staff commited on
Commit
2804c96
1 Parent(s): af4c8c5

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +13 -18
README.md CHANGED
@@ -37,7 +37,7 @@ curl --request POST \
37
  3. the expected output
38
 
39
  ```json
40
- {"text": "INDLUS THE"
41
  ```
42
 
43
  #### Python
@@ -57,33 +57,28 @@ 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
 
 
37
  3. the expected output
38
 
39
  ```json
40
+ {"text": "INDLUS THE"}
41
  ```
42
 
43
  #### Python
 
57
  import requests as r
58
  import base64
59
 
60
+ ENDPOINT_URL=""
61
+ HF_TOKEN=""
62
 
63
+ def predict(path_to_image:str=None):
 
64
  with open(path_to_image, "rb") as i:
65
+ b = i.read()
66
+ headers= {
67
+ "Authorization": f"Bearer {HF_TOKEN}",
68
+ "Content-Type": "image/jpeg" # content type of image
69
+ }
70
+ response = r.post(ENDPOINT_URL, headers=headers, data=b)
71
  return response.json()
72
 
73
+ prediction = predict(path_to_image="test.jpg")
74
 
75
+ prediction
 
 
76
  ```
77
 
78
  expected output
79
 
80
  ```python
81
+ {"text": "INDLUS THE"}
 
 
 
82
  ```
83
 
84