mirror of
https://github.com/wassname/IndicoIo-python.git
synced 2026-06-27 16:10:34 +08:00
ADD: url params for apis for multi api req
This commit is contained in:
@@ -25,7 +25,7 @@ def facial_features(image, cloud=None, batch=False, api_key=None, **kwargs):
|
||||
:rtype: List containing feature responses
|
||||
"""
|
||||
image = image_preprocess(image, batch=batch)
|
||||
return api_handler(image, cloud=cloud, api="facialfeatures", batch=batch, api_key=api_key, **kwargs)
|
||||
return api_handler(image, cloud=cloud, api="facialfeatures", url_params={"batch":batch, "api_key":api_key}, **kwargs)
|
||||
|
||||
def image_features(image, cloud=None, batch=False, api_key=None, **kwargs):
|
||||
"""
|
||||
@@ -58,4 +58,4 @@ def image_features(image, cloud=None, batch=False, api_key=None, **kwargs):
|
||||
:rtype: List containing features
|
||||
"""
|
||||
image = image_preprocess(image, batch=batch, size=(64,64))
|
||||
return api_handler(image, cloud=cloud, api="imagefeatures", batch=batch, api_key=api_key, **kwargs)
|
||||
return api_handler(image, cloud=cloud, api="imagefeatures", url_params={"batch":batch, "api_key":api_key}, **kwargs)
|
||||
|
||||
@@ -27,4 +27,4 @@ def fer(image, cloud=None, batch=False, api_key=None, **kwargs):
|
||||
:rtype: Dictionary containing emotion probability pairs
|
||||
"""
|
||||
image = image_preprocess(image, batch=batch)
|
||||
return api_handler(image, cloud=cloud, api="fer", batch=batch, api_key=api_key, **kwargs)
|
||||
return api_handler(image, cloud=cloud, api="fer", url_params={"batch":batch, "api_key":api_key}, **kwargs)
|
||||
|
||||
@@ -24,4 +24,4 @@ def language(text, cloud=None, batch=False, api_key=None, **kwargs):
|
||||
:rtype: Dictionary of language probability pairs
|
||||
"""
|
||||
|
||||
return api_handler(text, cloud=cloud, api="language", batch=batch, api_key=api_key, **kwargs)
|
||||
return api_handler(text, cloud=cloud, api="language", url_params={"batch":batch, "api_key":api_key}, **kwargs)
|
||||
|
||||
@@ -26,7 +26,7 @@ def political(text, cloud=None, batch=False, api_key=None, **kwargs):
|
||||
:rtype: Dictionary of party probability pairs
|
||||
"""
|
||||
|
||||
return api_handler(text, cloud=cloud, api="political", batch=batch, api_key=api_key, **kwargs)
|
||||
return api_handler(text, cloud=cloud, api="political", url_params={"batch":batch, "api_key":api_key}, **kwargs)
|
||||
|
||||
def posneg(text, cloud=None, batch=False, api_key=None, **kwargs):
|
||||
"""
|
||||
@@ -49,4 +49,4 @@ def posneg(text, cloud=None, batch=False, api_key=None, **kwargs):
|
||||
:rtype: Float
|
||||
"""
|
||||
|
||||
return api_handler(text, cloud=cloud, api="sentiment", batch=batch, api_key=api_key, **kwargs)
|
||||
return api_handler(text, cloud=cloud, api="sentiment", url_params={"batch":batch, "api_key":api_key}, **kwargs)
|
||||
|
||||
@@ -23,4 +23,4 @@ def text_tags(text, cloud=None, batch=False, api_key=None, **kwargs):
|
||||
:rtype: Dictionary of class probability pairs
|
||||
"""
|
||||
|
||||
return api_handler(text, cloud=cloud, api="texttags", batch=batch, api_key=api_key, **kwargs)
|
||||
return api_handler(text, cloud=cloud, api="texttags", url_params={"batch":batch, "api_key":api_key}, **kwargs)
|
||||
|
||||
@@ -8,7 +8,7 @@ from indicoio import config
|
||||
B64_PATTERN = re.compile("^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{4}|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)")
|
||||
|
||||
|
||||
def api_handler(arg, cloud, api, batch=False, api_key=None, **kwargs):
|
||||
def api_handler(arg, cloud, api, url_params = {"batch":False, "api_key":None}, **kwargs):
|
||||
data = {'data': arg}
|
||||
data.update(**kwargs)
|
||||
json_data = json.dumps(data)
|
||||
@@ -21,12 +21,11 @@ def api_handler(arg, cloud, api, batch=False, api_key=None, **kwargs):
|
||||
# default to indico public cloud
|
||||
host = config.PUBLIC_API_HOST
|
||||
|
||||
if not api_key:
|
||||
api_key = config.api_key
|
||||
|
||||
url = config.url_protocol + "//%s/%s" % (host, api)
|
||||
url = url + "/batch" if batch else url
|
||||
url += "?key=%s" % api_key
|
||||
url = url + "/batch" if url_params.get("batch", False) else url
|
||||
url += "?key=%s" % (url_params.get("api_key", None) or config.api_key)
|
||||
if "apis" in url_params:
|
||||
url += "&apis=%s" % ",".join(url_params["apis"])
|
||||
|
||||
response = requests.post(url, data=json_data, headers=JSON_HEADERS)
|
||||
if response.status_code == 503 and cloud != None:
|
||||
|
||||
@@ -27,7 +27,7 @@ def multi(data, type, apis, available, batch=False, **kwargs):
|
||||
)
|
||||
# Convert client api names to server names before sending request
|
||||
apis = map(CLIENT_SERVER_MAP.get, apis)
|
||||
result = api_handler(data, apis=apis, batch=batch, **kwargs)
|
||||
result = api_handler(data, url_params = {"apis":apis, "batch":batch}, **kwargs)
|
||||
return handle_response(result)
|
||||
|
||||
def handle_response(result):
|
||||
|
||||
Reference in New Issue
Block a user