mirror of
https://github.com/wassname/IndicoIo-python.git
synced 2026-08-19 11:50:16 +08:00
Cleaner api handler interface + extended tests
This commit is contained in:
+13
-15
@@ -4,26 +4,22 @@ import numpy as np
|
||||
from skimage.transform import resize
|
||||
|
||||
from indicoio import JSON_HEADERS
|
||||
from indicoio import config
|
||||
|
||||
def auth_query():
|
||||
email = os.environ.get("INDICO_EMAIL")
|
||||
password = os.environ.get("INDICO_PASSWORD")
|
||||
|
||||
# store settings
|
||||
if not email:
|
||||
email = raw_input("Email: ")
|
||||
os.environ["INDICO_EMAIL"] = email
|
||||
|
||||
if not password:
|
||||
password = getpass.getpass("Password: ")
|
||||
os.environ["INDICO_PASSWORD"] = password
|
||||
|
||||
return (email, password)
|
||||
|
||||
def api_handler(arg, url, batch=False, auth=None, **kwargs):
|
||||
def api_handler(arg, cloud, api, batch=False, auth=None, **kwargs):
|
||||
data = {'data': arg}
|
||||
data.update(**kwargs)
|
||||
json_data = json.dumps(data)
|
||||
|
||||
if cloud:
|
||||
host = "%s.indico.domains"
|
||||
else:
|
||||
# default to indico public cloud
|
||||
host = config.public_api_host
|
||||
|
||||
url = "http://%s/%s" % (host, api)
|
||||
|
||||
if batch:
|
||||
url += "/batch"
|
||||
|
||||
@@ -34,6 +30,7 @@ def api_handler(arg, url, batch=False, auth=None, **kwargs):
|
||||
raise ValueError(error)
|
||||
return results
|
||||
|
||||
|
||||
class TypeCheck(object):
|
||||
"""
|
||||
Decorator that performs a typecheck on the input to a function
|
||||
@@ -118,6 +115,7 @@ def normalize(array, distribution=1, norm_range=(0, 1), **kwargs):
|
||||
return dict(zip(keys, norm_array))
|
||||
return norm_array
|
||||
|
||||
|
||||
def image_preprocess(image, batch=False):
|
||||
"""
|
||||
Takes an image and prepares it for sending to the api including
|
||||
|
||||
Reference in New Issue
Block a user