-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrequest.py
More file actions
28 lines (18 loc) · 755 Bytes
/
request.py
File metadata and controls
28 lines (18 loc) · 755 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
# import the necessary packages
import requests
# initialize the Keras REST API endpoint URL along with the input
REST_API_URL = "http://localhost:8080/predict?model=LinearSVC"
# load the input image and construct the payload for the request
# submit the request
json_data = {"data":[{"sepal_length":6.3,"sepal_width":2.3,"petal_length":4.4,"petal_width":1.3}]}
json_string = json.dumps(json_data)
r = requests.post(REST_API_URL, data=json_string).json()
# ensure the request was sucessful
if r["success"]:
# loop over the predictions and display them
for (i, result) in enumerate(r["predictions"]):
print(" {} -- {}".format( result["prediction_0"],
result["prediction_1"]))
# otherwise, the request failed
else:
print("Request failed")