forked from RaebingZhong/flask_deployment
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.py
36 lines (26 loc) · 869 Bytes
/
client.py
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
# -*- coding:utf-8 -*-
# @time :2019.09.24
# @IDE : pycharm
# @author :lxztju
# @github : https://github.com/lxztju
import requests
import argparse
# Initialize the keras REST API endpoint URL.
REST_API_URL = 'http://127.0.0.1:5000/predict'
def predict_result(image_path):
# Initialize image path
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 successful.
if r['success']:
print(r['predictions'])
# Otherwise, the request failed.
else:
print('Request failed')
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Classification demo')
parser.add_argument('--file', type=str, help='test image file')
args = parser.parse_args()
predict_result(args.file)