2020"""
2121
2222import requests , json , os
23+ from io import BytesIO
2324
2425VERSION = None
2526path_version = os .path .join (os .path .dirname (__file__ ), '../version.py' )
@@ -41,7 +42,6 @@ def __init__(self, api_user, api_secret, *args):
4142
4243 if len (args ) > 1 :
4344 for arg in args :
44- print (arg )
4545 self .modelsType += arg + ','
4646 self .modelsType = self .modelsType [:- 1 ]
4747 else :
@@ -51,21 +51,25 @@ def image(self, image):
5151 numberOfModels = self .modelsType .count ("," )
5252
5353 if numberOfModels > 0 :
54- if image .lower ().startswith (('http://' , 'https://' )):
55- url = self .endpoint + '1.0/check.json'
54+ url = self .endpoint + '1.0/check.json'
55+
56+ if isinstance (image , bytes ):
57+ r = requests .post (url , files = {'media' : BytesIO (image )}, data = {'models' : self .modelsType ,'api_user' : self .api_user , 'api_secret' : self .api_secret }, headers = headers )
58+ elif image .lower ().startswith (('http://' , 'https://' )):
5659 r = requests .get (url , params = {'models' : self .modelsType , 'url' : image , 'api_user' : self .api_user , 'api_secret' : self .api_secret }, headers = headers )
5760 else :
58- url = self .endpoint + '1.0/check.json'
5961 r = requests .post (url , files = {'media' : open (image , 'rb' )}, data = {'models' : self .modelsType ,'api_user' : self .api_user , 'api_secret' : self .api_secret }, headers = headers )
6062
6163 output = json .loads (r .text )
6264 return output
6365 else :
64- if image .lower ().startswith (('http://' , 'https://' )):
65- url = self .endpoint + '1.0' + '/' + self .modelsType + '.json'
66+ url = self .endpoint + '1.0' + '/' + self .modelsType + '.json'
67+
68+ if isinstance (image , bytes ):
69+ r = requests .post (url , files = {'media' : BytesIO (image )}, data = {'api_user' : self .api_user ,'api_secret' : self .api_secret }, headers = headers )
70+ elif image .lower ().startswith (('http://' , 'https://' )):
6671 r = requests .get (url , params = {'url' : image , 'api_user' : self .api_user , 'api_secret' : self .api_secret }, headers = headers )
6772 else :
68- url = self .endpoint + '1.0' + '/' + self .modelsType + '.json'
6973 r = requests .post (url , files = {'media' : open (image , 'rb' )}, data = {'api_user' : self .api_user ,'api_secret' : self .api_secret }, headers = headers )
7074
7175 output = json .loads (r .text )
0 commit comments