-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.py
More file actions
63 lines (61 loc) · 2.46 KB
/
Copy pathtest.py
File metadata and controls
63 lines (61 loc) · 2.46 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import requests
import base64
import json
import os
if __name__ == '__main__':
# ####################################################################################################################
# # Test indexing of one image #
# ####################################################################################################################
# with open("images/2.jpg", "rb") as f:
# image = f.read()
# # buffered = io.BytesIO()
# # image.save(buffered, format="JPEG")
# im = base64.b64encode(image)
# base64string = im.decode('utf-8')
# data = {
# "base64img": base64string,
# "name": "2.jpg"
# }
# data = json.dumps(data, indent=2)
# r = requests.post("http://84.201.156.50/encode/image", data=data)
# assert r.status_code == 200
#
# ####################################################################################################################
# # Test indexing of many images #
# ####################################################################################################################
# image_base64_list = []
# image_names = []
# for img_name in os.listdir("images"):
# with open(f"images/{img_name}", "rb") as f:
# image = f.read()
# im = base64.b64encode(image)
# base64string = im.decode('utf-8')
# image_names.append(img_name)
# image_base64_list.append(base64string)
# data = {
# "img_list": image_base64_list,
# "img_names": image_names
# }
# data = json.dumps(data, indent=2)
# r = requests.post("http://84.201.156.50/encode/images", data=data)
# assert r.status_code == 200
#
# data = {
# "text": "a cat in a yellow hat"
# }
# r = requests.post("http://localhost:8000/text/search", data=json.dumps(data))
# assert r.status_code == 200
with open("images/163.jpg", "rb") as f:
image = f.read()
# buffered = io.BytesIO()
# image.save(buffered, format="JPEG")
im = base64.b64encode(image)
base64string = im.decode('utf-8')
data = {
"base64img": base64string,
"name": "2.jpg"
}
data = json.dumps(data, indent=2)
r = requests.post("http://localhost:8000/image/search", data=data)
print(r.json())
assert r.status_code == 200