-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathtest_api.py
More file actions
29 lines (24 loc) · 766 Bytes
/
test_api.py
File metadata and controls
29 lines (24 loc) · 766 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
import base64
import requests
import os
import json
import time
url = "http://127.0.0.1:5000/infer"
image_folder_path = "images"
image_files = os.listdir(image_folder_path)
if __name__ == "__main__":
st = time.time()
i_ = 0
for img in image_files:
i_ += 1
with open(os.path.join(image_folder_path, img), "rb") as image_file:
encoded_string = base64.b64encode(image_file.read())
data = {}
data['image_name'] = img
data['image'] = encoded_string
response = requests.post(url, data)
print("response")
response_dict = json.loads(response.text)
for i in response_dict:
print("key: ", i, "val: ", response_dict[i])
print(i_, time.time() - st)