mirror of
https://github.com/wassname/IndicoIo-python.git
synced 2026-08-11 11:12:45 +08:00
FIX: check if data is a list to determine if batch or single request
This commit is contained in:
committed by
Madison May
parent
9bea224d94
commit
1d42d6defe
+21
-3
@@ -1,4 +1,5 @@
|
||||
from functools import partial
|
||||
from functools import wraps, partial
|
||||
import warnings
|
||||
|
||||
Version, version, __version__, VERSION = ('0.8.1',) * 4
|
||||
|
||||
@@ -23,9 +24,26 @@ from indicoio.utils.multi import predict_image, predict_text
|
||||
|
||||
from indicoio.config import API_NAMES
|
||||
|
||||
def deprecation_decorator(f, api):
|
||||
@wraps(f)
|
||||
def wrapper(*args, **kwargs):
|
||||
warnings.warn(
|
||||
"'batch_" + api + "' will be deprecated in the next major update. Please call '" + api + "' instead with the same arguments.",
|
||||
DeprecationWarning
|
||||
)
|
||||
return f(*args, **kwargs)
|
||||
return wrapper
|
||||
|
||||
def detect_batch_decorator(f):
|
||||
@wraps(f)
|
||||
def wrapper(*args, **kwargs):
|
||||
if isinstance(args[0], list):
|
||||
kwargs['batch'] = True
|
||||
return f(*args, **kwargs)
|
||||
return wrapper
|
||||
|
||||
apis = dict((api, globals().get(api)) for api in API_NAMES)
|
||||
|
||||
for api in apis:
|
||||
globals()[api] = partial(apis[api])
|
||||
globals()['batch_' + api] = partial(apis[api], batch=True)
|
||||
globals()[api] = partial(detect_batch_decorator(apis[api]))
|
||||
globals()['batch_' + api] = partial(deprecation_decorator(apis[api], api), batch=True)
|
||||
|
||||
Reference in New Issue
Block a user