-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnvision.py
More file actions
executable file
·76 lines (63 loc) · 2.24 KB
/
nvision.py
File metadata and controls
executable file
·76 lines (63 loc) · 2.24 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
import os
import copy
import json
import requests
default_url = os.getenv('URL', 'https://nvision.nipa.cloud/api/v1/')
default_headers = {
'Content-Type': 'application/json; charset=utf-8',
}
def scrub_dict(d):
new_dict = {}
for k, v in d.items():
if isinstance(v, dict):
v = scrub_dict(v)
if v not in (u'', None, {}):
new_dict[k] = v
return new_dict
class API(object):
def __init__(self, api_key, service_name):
self.service_name = service_name
self.endpoint = default_url + service_name
self.headers = copy.copy(default_headers)
self.headers['Authorization'] = 'ApiKey {}'.format(api_key)
def predict(self,
image,
confidence_threshold=0.1,
output_cropped_image=False,
output_visualized_image=False):
"""
docstring: Make a RESTful request for model inference
:param image: base64 encoded string
:param confidence_threshold: float
- value options: [0,1]
- default: 0.1
:param output_cropped_image: Boolean
- value options: True or False,
- default: False
:param output_visualized_image: Boolean
- value options: True or False,
- default: False
"""
data = {
"raw_data": image,
"configurations": [{
"parameter": "ConfidenceThreshold",
"value": str(confidence_threshold)
}, {
"parameter": "OutputCroppedImage",
"value": str(output_cropped_image).lower()
}, {
"parameter": "OutputVisualizedImage",
"value": str(output_visualized_image).lower()
}]
}
response = requests.post(url=self.endpoint,
headers=self.headers,
data=json.dumps(data))
return response
class ObjectDetection(API):
def __init__(self, api_key):
super().__init__(api_key, service_name='object-detection')
class FaceDetection:
def __init__(self, api_key):
super().__init__(api_key, service_name='face-detection')