-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathadd_example_of_subject.py
More file actions
97 lines (78 loc) · 3.09 KB
/
add_example_of_subject.py
File metadata and controls
97 lines (78 loc) · 3.09 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
"""
Copyright(c) 2021 the original author or authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https: // www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied. See the License for the specific language governing
permissions and limitations under the License.
"""
import requests
from compreface.common.multipart_constructor import multipart_constructor
from compreface.common.typed_dict import (
DetProbOptionsDict,
SavedObjectOptions,
check_fields_by_name,
)
from compreface.config.api_list import RECOGNIZE_CRUD_API
from ..common import ClientRequest
class AddExampleOfSubjectClient(ClientRequest):
def __init__(self, api_key: str, domain: str, port: str):
super().__init__()
self.client_url: str = RECOGNIZE_CRUD_API
self.api_key: str = api_key
self.url: str = domain + ":" + port + self.client_url
"""
GET request for get all subjects.
:return: json with subjects from server.
"""
def get(self, options: SavedObjectOptions = {}) -> dict:
url: str = self.url + "?"
for key in options.keys():
# Checks fields with necessary rules.
# key - key field by options.
check_fields_by_name(key, options[key])
url += "&" + key + "=" + str(options[key])
result = requests.get(url, headers={"x-api-key": self.api_key})
return result.json()
"""
POST request for add subject from his face in image.
:param image_path: path to image in file system.
:param subject: fullname
:param options: dictionary with options for server.
:return: json with this subject from server.
"""
def post(
self,
image: str = "" or bytes,
subject: str = "",
options: DetProbOptionsDict = {},
) -> dict:
url: str = self.url + "?subject=" + subject
# Validation loop and adding fields to the url.
for key in options.keys():
# Checks fields with necessary rules.
# key - key field by options.
check_fields_by_name(key, options[key])
url += "&" + key + "=" + str(options[key])
m = multipart_constructor(image)
result = requests.post(
url,
data=m,
headers={"Content-Type": m.content_type, "x-api-key": self.api_key},
)
return result.json()
def put(self):
pass
"""
Delete request to CompreFace server.
:param subject: fullname
:return: json from server.
"""
def delete(self, subject: str = ""):
url: str = self.url + "?subject=" + subject
result = requests.delete(url, headers={"x-api-key": self.api_key})
return result.json()