Skip to content

Commit babd754

Browse files
committed
init sdk
1 parent 8fc8df2 commit babd754

File tree

66 files changed

+821
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+821
-0
lines changed

.gitignore

Whitespace-only changes.

.idea/.gitignore

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/compreface-python-sdk.iml

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/inspectionProfiles/Project_Default.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/inspectionProfiles/profiles_settings.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

LICENSE.txt

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
MIT License
2+
Copyright (c) 2021 Exadel
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
The above copyright notice and this permission notice shall be included in all
10+
copies or substantial portions of the Software.
11+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17+
SOFTWARE.

compreface/__init__.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# -*- coding: utf-8 -*-
2+
3+
from .core import CompreFace
213 Bytes
Binary file not shown.

compreface/client/__init__.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# -*- coding: utf-8 -*-
2+
3+
from .verify_face_from_image import VerifyFaceFromImageClient
4+
from .add_example_of_subject import AddExampleOfSubjectClient
5+
from .delete_example_by_id import DeleteExampleByIdClient
6+
from .recognize_face_from_image import RecognizeFaceFromImageClient
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# -*- coding: utf-8 -*-
2+
3+
import os
4+
import requests
5+
from requests_toolbelt.multipart.encoder import MultipartEncoder
6+
7+
from ..common import ClientRequest
8+
9+
10+
class AddExampleOfSubjectClient(ClientRequest):
11+
12+
def __init__(self, api_key: str, domain: str, port: str):
13+
super().__init__()
14+
self.client_url: str = '/api/v1/faces'
15+
self.api_key: str = api_key
16+
self.url: str = domain + ':' + port + self.client_url
17+
18+
def get(self) -> dict:
19+
url: str = self.url
20+
result = requests.get(url, headers={'x-api-key': self.api_key})
21+
return result.json()
22+
23+
def post(self, image_path: str = '', subject: str = '') -> dict:
24+
url: str = self.url + '?subject=' + subject
25+
name_img: str = os.path.basename(image_path)
26+
m = MultipartEncoder(
27+
fields={'file': (name_img, open(image_path, 'rb'))}
28+
)
29+
result = requests.post(url, data=m, headers={'Content-Type': m.content_type,
30+
'x-api-key': self.api_key})
31+
return result.json()
32+
33+
def put(self):
34+
pass
35+
36+
def delete(self, subject: str = ''):
37+
url: str = self.url + '?subject=' + subject
38+
result = requests.delete(url, headers={'x-api-key': self.api_key})
39+
return result.json()
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# -*- coding: utf-8 -*-
2+
3+
import requests
4+
5+
from ..common import ClientRequest
6+
7+
8+
class DeleteExampleByIdClient(ClientRequest):
9+
10+
def __init__(self, api_key: str, domain: str, port: str):
11+
super().__init__()
12+
self.client_url: str = '/api/v1/faces/'
13+
self.api_key: str = api_key
14+
self.url: str = domain + ':' + port + self.client_url
15+
16+
def get(self):
17+
pass
18+
19+
def post(self):
20+
pass
21+
22+
def put(self):
23+
pass
24+
25+
def delete(self, image_id: str = ''):
26+
url: str = self.url + image_id
27+
result = requests.delete(url, headers={'x-api-key': self.api_key})
28+
return result.json()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# -*- coding: utf-8 -*-
2+
3+
import os
4+
import requests
5+
from requests_toolbelt.multipart.encoder import MultipartEncoder
6+
7+
from ..common import ClientRequest
8+
9+
10+
class RecognizeFaceFromImageClient(ClientRequest):
11+
12+
def __init__(self, api_key: str, domain: str, port: str):
13+
super().__init__()
14+
self.client_url: str = '/api/v1/faces/recognize'
15+
self.api_key: str = api_key
16+
self.url: str = domain + ':' + port + self.client_url
17+
18+
def get(self):
19+
pass
20+
21+
def post(self, image_path: str = '',
22+
limit: float = 0,
23+
det_prob_threshold: float = 0,
24+
prediction_count: int = 0):
25+
url: str = self.url + '?limit=' + str(limit) + '&prediction_count=' + str(prediction_count) \
26+
+ '&det_prob_threshold=' + \
27+
str(det_prob_threshold)
28+
name_img: str = os.path.basename(image_path)
29+
m = MultipartEncoder(
30+
fields={'file': (name_img, open(image_path, 'rb'))}
31+
)
32+
result = requests.post(url, data=m, headers={'Content-Type': m.content_type,
33+
'x-api-key': self.api_key})
34+
return result.json()
35+
36+
def put(self):
37+
pass
38+
39+
def delete(self):
40+
pass

compreface/client/test-client.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import requests
2+
import os
3+
from requests_toolbelt.multipart.encoder import MultipartEncoder
4+
5+
url_view = "http://localhost:8000/api/v1/faces"
6+
api_key = "7dacfc8e-1bb1-4fcf-a9b1-76e4d9d89855"
7+
headers = {"Content-Type": "application/x-www-form-urlencoded", "x-api-key": api_key}
8+
headers_api_key = {"x-api-key": api_key}
9+
path = 'image_path'
10+
11+
12+
def add(path_img, subject):
13+
url = 'http://localhost:8000/api/v1/faces?subject=' + subject
14+
name_img = os.path.basename(path_img)
15+
m = MultipartEncoder(
16+
fields={'file': (name_img, open(path_img, 'rb'))}
17+
)
18+
19+
r = requests.post(url, data=m, headers={'Content-Type': m.content_type,
20+
'x-api-key': api_key})
21+
22+
print(r.status_code)
23+
print(r.text)
24+
print(r.json())
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# -*- coding: utf-8 -*-
2+
3+
import os
4+
import requests
5+
from requests_toolbelt.multipart.encoder import MultipartEncoder
6+
7+
from ..common import ClientRequest
8+
9+
10+
class VerifyFaceFromImageClient(ClientRequest):
11+
12+
def __init__(self, api_key: str, domain: str, port: str):
13+
super().__init__()
14+
self.client_url: str = '/api/v1/faces/'
15+
self.api_key: str = api_key
16+
self.url: str = domain + ':' + port + self.client_url
17+
18+
def get(self):
19+
pass
20+
21+
def post(self,
22+
image_path: str = '',
23+
image_id: str = '',
24+
limit: float = 0,
25+
det_prob_threshold: float = 0,):
26+
url: str = self.url + image_id + '/verify' +'?limit=' + str(limit) + \
27+
'&det_prob_threshold=' + \
28+
str(det_prob_threshold)
29+
name_img: str = os.path.basename(image_path)
30+
m = MultipartEncoder(
31+
fields={'file': (name_img, open(image_path, 'rb'))}
32+
)
33+
result = requests.post(url, data=m, headers={'Content-Type': m.content_type,
34+
'x-api-key': self.api_key})
35+
return result.json()
36+
37+
def put(self):
38+
pass
39+
40+
def delete(self):
41+
pass

compreface/common/__init__.py

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# -*- coding: utf-8 -*-
2+
3+
from .client import ClientRequest
4+
from .service import Service
Binary file not shown.
Binary file not shown.
Binary file not shown.

compreface/common/client.py

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# -*- coding: utf-8 -*-
2+
3+
from abc import ABC, abstractmethod
4+
5+
6+
class ClientRequest(ABC):
7+
"""The best class of all requests"""
8+
9+
@abstractmethod
10+
def __init__(self):
11+
pass
12+
13+
@abstractmethod
14+
def get(self):
15+
pass
16+
17+
@abstractmethod
18+
def post(self):
19+
pass
20+
21+
@abstractmethod
22+
def put(self):
23+
pass
24+
25+
@abstractmethod
26+
def delete(self):
27+
pass

compreface/common/service.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# -*- coding: utf-8 -*-
2+
3+
from abc import ABC, abstractmethod
4+
5+
6+
class Service(ABC):
7+
"""The best class of all services"""
8+
9+
@abstractmethod
10+
def __init__(self, api_key: str):
11+
self._api_key = api_key
12+
13+
@property
14+
def api_key(self):
15+
return self._api_key
16+
17+
@abstractmethod
18+
def get_available_functions(self):
19+
pass

compreface/core/__init__.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# -*- coding: utf-8 -*-
2+
3+
from .model import CompreFace
219 Bytes
Binary file not shown.
2.15 KB
Binary file not shown.

compreface/core/model.py

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# -*- coding: utf-8 -*-
2+
3+
from typing import Optional
4+
from ..service import (
5+
RecognitionService,
6+
VerificationService,
7+
DetectionService
8+
)
9+
10+
11+
class CompreFace(object):
12+
"""
13+
Main class
14+
"""
15+
16+
def __init__(self, domain: str, port: str):
17+
self._domain: str = domain
18+
self._port: str = port
19+
self.recognition: Optional[RecognitionService] = None
20+
self.verification: Optional[VerificationService] = None
21+
self.detection: Optional[DetectionService] = None
22+
23+
@property
24+
def domain(self):
25+
return self._domain
26+
27+
@domain.setter
28+
def domain(self, domain: str):
29+
self._domain = domain
30+
31+
@property
32+
def port(self):
33+
return self._port
34+
35+
@port.setter
36+
def port(self, port: str):
37+
self._port = port
38+
39+
def init_face_recognition(self, api_key: str) -> RecognitionService:
40+
"""
41+
Init Face Recognition Service
42+
:param api_key:
43+
:return:
44+
"""
45+
self.recognition = RecognitionService(api_key=api_key,
46+
domain=self.domain,
47+
port=self.port)
48+
return self.recognition
49+
50+
def init_face_verification(self, api_key: str) -> VerificationService:
51+
"""
52+
Init Face Verification Service
53+
:param api_key:
54+
:return:
55+
"""
56+
self.verification = VerificationService(api_key=api_key,
57+
domain=self.domain,
58+
port=self.port)
59+
return self.verification
60+
61+
def init_face_detection(self, api_key: str) -> DetectionService:
62+
"""
63+
Init Face Detection Service
64+
:param api_key:
65+
:return:
66+
"""
67+
self.detection = DetectionService(api_key=api_key)
68+
return self.detection

compreface/exceptions/__init__.py

Whitespace-only changes.

compreface/service/__init__.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# -*- coding: utf-8 -*-
2+
3+
from .detection_service import DetectionService
4+
from .verification_service import VerificationService
5+
from .recognition_service import RecognitionService
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)