mirror of
https://github.com/wassname/IndicoIo-python.git
synced 2026-08-12 11:40:34 +08:00
ADD: default apis for text/image with tests
This commit is contained in:
@@ -46,7 +46,7 @@ def handle_response(result):
|
|||||||
raise Exception("Sorry, %s API returned an unexpected response:\n%s" % (api, result[api]))
|
raise Exception("Sorry, %s API returned an unexpected response:\n%s" % (api, result[api]))
|
||||||
|
|
||||||
|
|
||||||
def predict_text(input_text, apis, cloud=None, batch=False, api_key=None, **kwargs):
|
def predict_text(input_text, apis=TEXT_APIS, cloud=None, batch=False, api_key=None, **kwargs):
|
||||||
"""
|
"""
|
||||||
Given input text, returns the results of specified text apis. Possible apis
|
Given input text, returns the results of specified text apis. Possible apis
|
||||||
include: [ 'text_tags', 'political', 'sentiment', 'language' ]
|
include: [ 'text_tags', 'political', 'sentiment', 'language' ]
|
||||||
@@ -80,7 +80,7 @@ def predict_text(input_text, apis, cloud=None, batch=False, api_key=None, **kwar
|
|||||||
**kwargs)
|
**kwargs)
|
||||||
|
|
||||||
|
|
||||||
def predict_image(image, apis, cloud=None, batch=False, api_key=None, **kwargs):
|
def predict_image(image, apis=IMAGE_APIS, cloud=None, batch=False, api_key=None, **kwargs):
|
||||||
"""
|
"""
|
||||||
Given input image, returns the results of specified image apis. Possible apis
|
Given input image, returns the results of specified image apis. Possible apis
|
||||||
include: ['fer', 'facial_features', 'image_features']
|
include: ['fer', 'facial_features', 'image_features']
|
||||||
|
|||||||
@@ -136,6 +136,13 @@ class BatchAPIRun(unittest.TestCase):
|
|||||||
self.assertTrue(isinstance(response, list))
|
self.assertTrue(isinstance(response, list))
|
||||||
self.assertTrue(set(response[0].keys()) == set(config.TEXT_APIS))
|
self.assertTrue(set(response[0].keys()) == set(config.TEXT_APIS))
|
||||||
|
|
||||||
|
def test_default_multi_api_text(self):
|
||||||
|
test_data = ['clearly an english sentence']
|
||||||
|
response = batch_predict_text(test_data, api_key=self.api_key)
|
||||||
|
|
||||||
|
self.assertTrue(isinstance(response, list))
|
||||||
|
self.assertTrue(set(response[0].keys()) == set(config.TEXT_APIS))
|
||||||
|
|
||||||
def test_multi_api_bad_api(self):
|
def test_multi_api_bad_api(self):
|
||||||
self.assertRaises(ValueError,
|
self.assertRaises(ValueError,
|
||||||
batch_predict_text,
|
batch_predict_text,
|
||||||
|
|||||||
Reference in New Issue
Block a user