1
+ """
2
+ Copyright(c) 2021 the original author or authors
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ https: // www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
13
+ or implied. See the License for the specific language governing
14
+ permissions and limitations under the License.
15
+ """
16
+
17
+ from compreface .common .multipart_constructor import multipart_constructor_with_two_images
1
18
import requests
2
19
from compreface .config .api_list import VERIFICATION_API
3
20
import os
@@ -34,13 +51,11 @@ def get(self):
34
51
"""
35
52
36
53
def post (self ,
37
- source_image_path : str = '' ,
38
- target_image_path : str = '' ,
54
+ source_image : str = '' or bytes ,
55
+ target_image : str = '' or bytes ,
39
56
options : AllOptionsDict = {}) -> dict :
40
57
41
58
url : str = self .url + '/verify?'
42
- source_name_img : str = os .path .basename (source_image_path )
43
- target_name_img : str = os .path .basename (target_image_path )
44
59
# Validation loop and adding fields to the url.
45
60
for key in options .keys ():
46
61
# Checks fields with necessary rules.
@@ -49,12 +64,7 @@ def post(self,
49
64
url += '&' + key + "=" + str (options [key ])
50
65
51
66
# Encoding image from path and encode in multipart for sending to the server.
52
- m = MultipartEncoder (
53
- fields = {'source_image' : (source_name_img , open (
54
- source_image_path , 'rb' )), 'target_image' : (target_name_img , open (
55
- target_image_path , 'rb' ))}
56
-
57
- )
67
+ m = multipart_constructor_with_two_images (source_image , target_image )
58
68
59
69
# Sending encode image for verify face.
60
70
result = requests .post (url , data = m , headers = {'Content-Type' : m .content_type ,
0 commit comments