-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathrequest.py
More file actions
28 lines (23 loc) · 789 Bytes
/
Copy pathrequest.py
File metadata and controls
28 lines (23 loc) · 789 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
# USAGE
# python request.py
# Also try
# curl -X POST -F image=@test.jpeg "ENDPOINT_URL"
# Import the necessary packages
import requests
# Initialize the REST API endpoint URL along with the input
# image path
REST_API_URL = "http://127.0.0.1:8000/api/predict" # for local dev
IMAGE_PATH = "test1.jpeg" # example image
# 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(REST_API_URL, files=payload).json()
# Ensure the request was sucessful
if r["success"]:
# Loop over the predictions and display them
for (i, result) in enumerate(r["predictions"]):
print("{}. {}: {:.4f}".format(i + 1, result["label"],
result["probability"]))
else:
print("Request failed")