-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimple_request.py
More file actions
38 lines (28 loc) · 920 Bytes
/
simple_request.py
File metadata and controls
38 lines (28 loc) · 920 Bytes
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
# USAGE
# python simple_request.py
# import the necessary packages
import requests
# initialize the Keras REST API endpoint URL along with the input
# image path
KERAS_REST_API_URL = "https://work-in-my-machine.herokuapp.com/predict"
IMAGE_PATH = './test_dog.jpg'
def main():
# load the input image and construct the payload for the request
image = open(IMAGE_PATH, "rb").read()
payload = {"image": image}
# submit the request
r = requests.post(KERAS_REST_API_URL, files=payload)
# ensure the request was sucessful
if r.status_code == 200:
# loop over the predictions and display them
# for (i, result) in enumerate(r["predictions"]):
# print("{}. {}: {:.4f}".format(i + 1, result["label"],
# result["probability"]))
print(r.json())
elif r.status_code == 500:
print("App failed.")
# otherwise, the request failed
else:
print("Request failed.")
if __name__ == '__main__':
main()