Last active
October 19, 2018 23:28
-
-
Save himanshurawlani/a8d9f064709f4014df7ad47b5d0a1b42 to your computer and use it in GitHub Desktop.
Script to make a request to Flask server (mimics frontend request)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# importing the requests library | |
import argparse | |
import base64 | |
import requests | |
# defining the api-endpoint | |
API_ENDPOINT = "http://localhost:5000/imageclassifier/predict/" | |
# taking input image via command line | |
ap = argparse.ArgumentParser() | |
ap.add_argument("-i", "--image", required=True, | |
help="path of the image") | |
args = vars(ap.parse_args()) | |
image_path = args['image'] | |
b64_image = "" | |
# Encoding the JPG,PNG,etc. image to base64 format | |
with open(image_path, "rb") as imageFile: | |
b64_image = base64.b64encode(imageFile.read()) | |
# data to be sent to api | |
data = {'b64': b64_image} | |
# sending post request and saving response as response object | |
r = requests.post(url=API_ENDPOINT, data=data) | |
# extracting the response | |
print("{}".format(r.text)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment