-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
81 lines (67 loc) · 2.31 KB
/
test.py
File metadata and controls
81 lines (67 loc) · 2.31 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import main.firebase
import requests
import base64
import json
import time
firebase = main.firebase.FireBase('../strangerdetection-firebase-adminsdk-ndswy-371433d43f.json',
'strangerdetection.appspot.com')
def test_server():
url = firebase.get_image_access_url("tien.png")
content = requests.get(url).content
localhost = "http://127.0.0.1:5000/api/v1/encodings"
base64_string = str(base64.b64encode(content))[2:-1]
data = {
'user_email': 'tientt@gmail.com',
'image': base64_string
}
print(json.dumps(data))
x = requests.post(localhost, json=json.dumps(data))
print(x.text)
def test_firebase():
image_name = "71650dc8-3674-4702-a948-308ae0369a6a.png"
print(firebase.get_image_access_url(image_name))
def test_create_new_encoding():
localhost = "http://127.0.0.1:5000/api/v1/encodings"
with open('../1440_Vladimir_Putin_Wallpaper.jpg', 'rb') as image:
base64_string = str(base64.b64encode(image.read()))[2:-1]
data = {
'user_email': 'tientt@gmail.com',
'image': base64_string
}
start = time.time()
x = requests.post(localhost, json=json.dumps(data))
end = time.time()
print("Time: " + str(end - start))
response_data = json.loads(x.text)
print(response_data)
image_name = response_data['image_name']
url = firebase.get_image_access_url(image_name)
print(url)
def test_delete_encoding():
localhost = "http://127.0.0.1:5000/api/v1/encodings"
data = {
'image_name': '71d7c0e2-417d-4d27-90f3-51acc14126a3.png'
}
start = time.time()
x = requests.delete(localhost, json=json.dumps(data))
end = time.time()
print("Time: " + str(end - start))
response_data = json.loads(x.text)
print(response_data)
def test_detect():
localhost = "http://127.0.0.1:5000/api/v1/processImage"
with open('../tien.png', 'rb') as image:
base64_string = str(base64.b64encode(image.read()))[2:-1]
data = {
'image': base64_string
}
start = time.time()
x = requests.post(localhost, json=json.dumps(data))
end = time.time()
print("Time: " + str(end - start))
response_data = json.loads(x.text)
print(response_data)
if __name__ == '__main__':
#test_create_new_encoding()
# test_delete_encoding()
test_detect()