Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate 1.2.0 #20

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
220 changes: 199 additions & 21 deletions README.md

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions compreface/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@
from .detect_face_from_image import DetectFaceFromImageClient
from .verify_face_from_image import VerifyFaceFromImageClient
from .subject_client import SubjectClient
from .recognize_face_from_embeddings import RecognizeFaceFromEmbeddingClient
from .verification_face_from_embeddings import VerificationFaceFromEmbeddingClient
from .verify_face_from_embeddings import VerifyFaceFromEmbeddingClient
44 changes: 30 additions & 14 deletions compreface/client/add_example_of_subject.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,36 @@
import requests

from compreface.common.multipart_constructor import multipart_constructor
from compreface.common.typed_dict import DetProbOptionsDict, check_fields_by_name
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
self.url: str = domain + ":" + port + self.client_url

"""
GET request for get all subjects.

:return: json with subjects from server.
"""

def get(self) -> dict:
url: str = self.url
result = requests.get(url, headers={'x-api-key': self.api_key})
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()

"""
Expand All @@ -51,17 +59,25 @@ def get(self) -> dict:
: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
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])
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})
result = requests.post(
url,
data=m,
headers={"Content-Type": m.content_type, "x-api-key": self.api_key},
)
return result.json()

def put(self):
Expand All @@ -75,7 +91,7 @@ def put(self):
: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})
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()
24 changes: 17 additions & 7 deletions compreface/client/delete_example_by_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,30 @@
class DeleteExampleByIdClient(ClientRequest):

"""
Delete example by id from image_id.
Delete example by id from image_id.
"""

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
self.url: str = domain + ":" + port + self.client_url

def get(self):
pass

def post(self):
pass
"""
POST request to delete several subject examples.

:param image_id: UUID of the removing face.

:return: json from server.
"""

def post(self, image_ids: list = []):
url: str = self.url + "/delete"
result = requests.post(url, json=image_ids, headers={"x-api-key": self.api_key})
return result.json()

def put(self):
pass
Expand All @@ -49,7 +59,7 @@ def put(self):
:return: json from server.
"""

def delete(self, image_id: str = ''):
url: str = self.url + '/' + image_id
result = requests.delete(url, headers={'x-api-key': self.api_key})
def delete(self, image_id: str = ""):
url: str = self.url + "/" + image_id
result = requests.delete(url, headers={"x-api-key": self.api_key})
return result.json()
17 changes: 10 additions & 7 deletions compreface/client/detect_face_from_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@

class DetectFaceFromImageClient(ClientRequest):
"""
Detection faces in image. It uses image path for encode and send to CompreFace server.
Detection faces in image. It uses image path for encode and send to CompreFace server.
"""

def __init__(self, api_key: str, domain: str, port: str):
super().__init__()
self.client_url: str = DETECTION_API
self.api_key: str = api_key
self.url: str = domain + ':' + port + self.client_url
self.url: str = domain + ":" + port + self.client_url

def get(self):
pass
Expand All @@ -44,22 +44,25 @@ def get(self):
:return: json from server.
"""

def post(self, image: str = '' or bytes, options: ExpandedOptionsDict = {}):
url: str = self.url + '?'
def post(self, image: str = "" or bytes, options: ExpandedOptionsDict = {}):
url: str = self.url + "?"

# 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])
url += "&" + key + "=" + str(options[key])

# Encoding image from path and encode in multipart for sending to the server.
m = multipart_constructor(image)

# Sending encode image for detection faces.
result = requests.post(url, data=m, headers={'Content-Type': m.content_type,
'x-api-key': self.api_key})
result = requests.post(
url,
data=m,
headers={"Content-Type": m.content_type, "x-api-key": self.api_key},
)
return result.json()

def put(self):
Expand Down
70 changes: 70 additions & 0 deletions compreface/client/recognize_face_from_embeddings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
"""
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.typed_dict import (
PredictionCountOptionsDict,
check_fields_by_name,
)
from compreface.config.api_list import RECOGNIZE_EMBEDDINGS_API
from ..common import ClientRequest


class RecognizeFaceFromEmbeddingClient(ClientRequest):
"""
The service is used to determine similarities between input embeddings and embeddings within the Face Collection.
"""

def __init__(self, api_key: str, domain: str, port: str):
super().__init__()
self.client_url: str = RECOGNIZE_EMBEDDINGS_API
self.api_key: str = api_key
self.url: str = domain + ":" + port + self.client_url

def get(self):
pass

"""
POST request for recognize faces in embeddings.

:param embeddings: An input embeddings. The length depends on the model.
:param options: dictionary with options for server.

:return: json from server.
"""

def post(self, embeddings: list = [[]], options: PredictionCountOptionsDict = {}):
url: str = self.url + "/recognize?"

# 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])
# Sending an input source embedding for recognize faces.
result = requests.post(
url,
json={"embeddings": embeddings},
headers={"x-api-key": self.api_key, "Content-Type": "application/json"},
)
result.raise_for_status()
return result.json()

def put(self):
pass

def delete(self):
pass
17 changes: 10 additions & 7 deletions compreface/client/recognize_face_from_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@
import requests

from compreface.common.multipart_constructor import multipart_constructor
from compreface.common.typed_dict import AllOptionsDict, check_fields_by_name
from compreface.common.typed_dict import RecognizeOptionsDict, check_fields_by_name
from compreface.config.api_list import RECOGNIZE_API
from ..common import ClientRequest


class RecognizeFaceFromImageClient(ClientRequest):
"""
Recognize faces in image. It uses image path for encode and send to CompreFace server.
Recognize faces in image. It uses image path for encode and send to CompreFace server.
"""

def __init__(self, api_key: str, domain: str, port: str):
super().__init__()
self.client_url: str = RECOGNIZE_API
self.api_key: str = api_key
self.url: str = domain + ':' + port + self.client_url
self.url: str = domain + ":" + port + self.client_url

def get(self):
pass
Expand All @@ -44,22 +44,25 @@ def get(self):
:return: json from server.
"""

def post(self, image: str = '' or bytes, options: AllOptionsDict = {}):
def post(self, image: str = "" or bytes, options: RecognizeOptionsDict = {}):
url: str = self.url + "?"

# 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])
url += "&" + key + "=" + str(options[key])

# Encoding image from path and encode in multipart for sending to the server.
m = multipart_constructor(image)

# Sending encode image for recognize faces.
result = requests.post(url, data=m, headers={'Content-Type': m.content_type,
'x-api-key': self.api_key})
result = requests.post(
url,
data=m,
headers={"Content-Type": m.content_type, "x-api-key": self.api_key},
)
return result.json()

def put(self):
Expand Down
15 changes: 7 additions & 8 deletions compreface/client/subject_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@


class SubjectClient(ClientRequest):

def __init__(self, api_key: str, domain: str, port: str):
super().__init__()
self.client_url: str = SUBJECTS_CRUD_API
self.api_key: str = api_key
self.url: str = domain + ':' + port + self.client_url
self.headers = {'Content-Type': 'application/json', 'x-api-key': api_key}
self.url: str = domain + ":" + port + self.client_url
self.headers = {"Content-Type": "application/json", "x-api-key": api_key}

"""
GET request for get all subjects.
Expand All @@ -49,7 +48,7 @@ def get(self) -> dict:
:return: json with this subject from server.
"""

def post(self, subject: dict = '') -> dict:
def post(self, subject: dict = "") -> dict:
url: str = self.url
result = requests.post(url, data=json.dumps(subject), headers=self.headers)
return result.json()
Expand All @@ -62,8 +61,8 @@ def post(self, subject: dict = '') -> dict:
:return: json from server.
"""

def put(self, request: dict = '') -> dict:
url: str = self.url + '/' + request.get('api_endpoint')
def put(self, request: dict = "") -> dict:
url: str = self.url + "/" + request.get("api_endpoint")
result = requests.put(url, data=json.dumps(request), headers=self.headers)
return result.json()

Expand All @@ -75,7 +74,7 @@ def put(self, request: dict = '') -> dict:
:return: json from server.
"""

def delete(self, subject: str = '') -> dict:
url: str = self.url + '/' + subject if subject else self.url
def delete(self, subject: str = "") -> dict:
url: str = self.url + "/" + subject if subject else self.url
result = requests.delete(url, headers=self.headers)
return result.json()
Loading