mirror of
https://github.com/wassname/IndicoIo-python.git
synced 2026-08-12 11:40:34 +08:00
FIX: Added version changes and IndicoError
This commit is contained in:
@@ -23,3 +23,4 @@ v0.5.1, Friday Feb 27 -- More README updates, fixed rst formatting issue, added
|
|||||||
v0.5.2, Tue March 7 -- Required API keys, configuration settings
|
v0.5.2, Tue March 7 -- Required API keys, configuration settings
|
||||||
v0.5.3, Wed Apr 15 -- Added scipy to requirements, edited Readme to not break pypi page
|
v0.5.3, Wed Apr 15 -- Added scipy to requirements, edited Readme to not break pypi page
|
||||||
v0.6.0, Thu May 29 -- Remove numpy / scipy dependency in favor of Pillow
|
v0.6.0, Thu May 29 -- Remove numpy / scipy dependency in favor of Pillow
|
||||||
|
v0.7.0, Tue Jun 9 -- Added support for calling multiple APIs in a single function and accepting filenames as image API inputs
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
|
Version, version, __version__, VERSION = ('0.7.0',) * 4
|
||||||
|
|
||||||
JSON_HEADERS = {
|
JSON_HEADERS = {
|
||||||
'Content-type': 'application/json',
|
'Content-type': 'application/json',
|
||||||
'Accept': 'application/json',
|
'Accept': 'application/json',
|
||||||
'client-lib': 'python',
|
'client-lib': 'python',
|
||||||
'version-number': '0.7.0'
|
'version-number': VERSION
|
||||||
}
|
}
|
||||||
|
|
||||||
Version, version, __version__, VERSION = ('0.7.0',) * 4
|
|
||||||
|
|
||||||
from indicoio.text.sentiment import political, posneg
|
from indicoio.text.sentiment import political, posneg
|
||||||
from indicoio.text.sentiment import posneg as sentiment
|
from indicoio.text.sentiment import posneg as sentiment
|
||||||
from indicoio.text.lang import language
|
from indicoio.text.lang import language
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ def multi(data, type, apis, available, batch=False, **kwargs):
|
|||||||
|
|
||||||
def handle_response(result):
|
def handle_response(result):
|
||||||
# Parse out the results to a dicionary of api: result
|
# Parse out the results to a dicionary of api: result
|
||||||
return dict((SERVER_CLIENT_MAP[api], parsed_response(res))
|
return dict((SERVER_CLIENT_MAP[api], parsed_response(api, res))
|
||||||
for api, res in result.iteritems())
|
for api, res in result.iteritems())
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
"""
|
"""
|
||||||
Setup for indico apis
|
Setup for indico apis
|
||||||
"""
|
"""
|
||||||
|
from indicoio import VERSION
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from setuptools import setup
|
from setuptools import setup
|
||||||
except ImportError:
|
except ImportError:
|
||||||
@@ -8,7 +10,7 @@ except ImportError:
|
|||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="IndicoIo",
|
name="IndicoIo",
|
||||||
version='0.7.0',
|
version=VERSION,
|
||||||
packages=[
|
packages=[
|
||||||
"indicoio",
|
"indicoio",
|
||||||
"indicoio.text",
|
"indicoio.text",
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ from indicoio import political, sentiment, fer, facial_features, language, image
|
|||||||
from indicoio import batch_political, batch_sentiment, batch_fer, batch_facial_features
|
from indicoio import batch_political, batch_sentiment, batch_fer, batch_facial_features
|
||||||
from indicoio import batch_language, batch_image_features, batch_text_tags
|
from indicoio import batch_language, batch_image_features, batch_text_tags
|
||||||
from indicoio import predict_image, predict_text, batch_predict_image, batch_predict_text
|
from indicoio import predict_image, predict_text, batch_predict_image, batch_predict_text
|
||||||
|
from indicoio.utils.errors import IndicoError
|
||||||
|
|
||||||
DIR = os.path.dirname(os.path.realpath(__file__))
|
DIR = os.path.dirname(os.path.realpath(__file__))
|
||||||
|
|
||||||
@@ -49,7 +50,7 @@ class BatchAPIRun(unittest.TestCase):
|
|||||||
|
|
||||||
def test_batch_fer_bad_b64(self):
|
def test_batch_fer_bad_b64(self):
|
||||||
test_data = ["$bad#FI jeaf9(#0"]
|
test_data = ["$bad#FI jeaf9(#0"]
|
||||||
self.assertRaises(ValueError, batch_fer, test_data, api_key=self.api_key)
|
self.assertRaises(IndicoError, batch_fer, test_data, api_key=self.api_key)
|
||||||
|
|
||||||
def test_batch_fer_good_b64(self):
|
def test_batch_fer_good_b64(self):
|
||||||
test_data = ["iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAg5JREFUeNrEV4uNgzAMpegGyAgZgQ3KBscIjMAGx03QEdqbgG5AOwG3AWwAnSCXqLZkuUkwhfYsvaLm5xc7sZ1dIhdtUVjsLZRFTvp+LSaLq8UZ/s+KMSbZCcY5RV9E4QQKHG7QtgeCGv4PFt8WpzkCcztu3TiL0eJgkQmsVFn0MK+LzYkRKEGpG1GDyZdKRdaolhAoJewXnJsO1jtKCFDlChZAFxyJj2PnBRU20KZg7oMlOAENijpi8hwmGkKkZW2GzONtVLA/DxHAhTO2I7MCVBSQ6nGDlEBJDhyVYiUBHXBxzQm0wE4FzPYsGs856dA9SAAP2oENzFYqR6iAFQpHIAUzO/nxnOgthF/lM3w/3U8KYXTwxG/1IgIulF+wPQUXDMl75UoJZIHstRWpaGb8IGYqwBoKlG/lgpzoUEBoj50p8QtVrmHgaaXyC/H3BFC+e9kGFlCB0CtBF7FifQ8D9zjQQHj0pdOM3F1pUBoFKdxtqkMClScHJCSDlSxhHSNRT5K+FaZnHglrz+AGoxZLKNLYH6s3CkkuyJlp58wviZ4PuSCWDXl5hmjZtxcSCGbDUD3gK7EMOZBLCETrgVBF5K0lI5bIZ0wfrYh8NWHIAiNTPHpuTOKpCes1VTFaiNaFdGwPfdmaqlj6LmjJbgoSSfUW74K3voz+/W0oIeB7HWu2s+dfx3N+eLX8CTAAwUmKjK/dHS4AAAAASUVORK5CYII="]
|
test_data = ["iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAg5JREFUeNrEV4uNgzAMpegGyAgZgQ3KBscIjMAGx03QEdqbgG5AOwG3AWwAnSCXqLZkuUkwhfYsvaLm5xc7sZ1dIhdtUVjsLZRFTvp+LSaLq8UZ/s+KMSbZCcY5RV9E4QQKHG7QtgeCGv4PFt8WpzkCcztu3TiL0eJgkQmsVFn0MK+LzYkRKEGpG1GDyZdKRdaolhAoJewXnJsO1jtKCFDlChZAFxyJj2PnBRU20KZg7oMlOAENijpi8hwmGkKkZW2GzONtVLA/DxHAhTO2I7MCVBSQ6nGDlEBJDhyVYiUBHXBxzQm0wE4FzPYsGs856dA9SAAP2oENzFYqR6iAFQpHIAUzO/nxnOgthF/lM3w/3U8KYXTwxG/1IgIulF+wPQUXDMl75UoJZIHstRWpaGb8IGYqwBoKlG/lgpzoUEBoj50p8QtVrmHgaaXyC/H3BFC+e9kGFlCB0CtBF7FifQ8D9zjQQHj0pdOM3F1pUBoFKdxtqkMClScHJCSDlSxhHSNRT5K+FaZnHglrz+AGoxZLKNLYH6s3CkkuyJlp58wviZ4PuSCWDXl5hmjZtxcSCGbDUD3gK7EMOZBLCETrgVBF5K0lI5bIZ0wfrYh8NWHIAiNTPHpuTOKpCes1VTFaiNaFdGwPfdmaqlj6LmjJbgoSSfUW74K3voz+/W0oIeB7HWu2s+dfx3N+eLX8CTAAwUmKjK/dHS4AAAAASUVORK5CYII="]
|
||||||
@@ -71,7 +72,7 @@ class BatchAPIRun(unittest.TestCase):
|
|||||||
|
|
||||||
def test_batch_fer_nonexistant_filepath(self):
|
def test_batch_fer_nonexistant_filepath(self):
|
||||||
test_data = ["data/unhappy.png"]
|
test_data = ["data/unhappy.png"]
|
||||||
self.assertRaises(ValueError, batch_fer, test_data, api_key=self.api_key)
|
self.assertRaises(IndicoError, batch_fer, test_data, api_key=self.api_key)
|
||||||
|
|
||||||
|
|
||||||
def test_batch_facial_features(self):
|
def test_batch_facial_features(self):
|
||||||
@@ -151,18 +152,18 @@ class BatchAPIRun(unittest.TestCase):
|
|||||||
self.assertTrue(set(response.keys()) == set(config.TEXT_APIS))
|
self.assertTrue(set(response.keys()) == set(config.TEXT_APIS))
|
||||||
|
|
||||||
def test_multi_api_bad_api(self):
|
def test_multi_api_bad_api(self):
|
||||||
self.assertRaises(ValueError,
|
self.assertRaises(IndicoError,
|
||||||
batch_predict_text,
|
batch_predict_text,
|
||||||
"this shouldn't work",
|
"this shouldn't work",
|
||||||
apis=["sentiment", "somethingbad"])
|
apis=["sentiment", "somethingbad"])
|
||||||
|
|
||||||
def test_multi_bad_mixed_api(self):
|
def test_multi_bad_mixed_api(self):
|
||||||
self.assertRaises(ValueError,
|
self.assertRaises(IndicoError,
|
||||||
predict_text,
|
predict_text,
|
||||||
"this shouldn't work",
|
"this shouldn't work",
|
||||||
apis=["fer", "sentiment", "facial_features"])
|
apis=["fer", "sentiment", "facial_features"])
|
||||||
def test_batch_multi_bad_mixed_api(self):
|
def test_batch_multi_bad_mixed_api(self):
|
||||||
self.assertRaises(ValueError,
|
self.assertRaises(IndicoError,
|
||||||
batch_predict_text,
|
batch_predict_text,
|
||||||
["this shouldn't work"],
|
["this shouldn't work"],
|
||||||
apis=["fer", "sentiment", "facial_features"])
|
apis=["fer", "sentiment", "facial_features"])
|
||||||
@@ -363,7 +364,7 @@ class FullAPIRun(unittest.TestCase):
|
|||||||
|
|
||||||
def test_set_api_key(self):
|
def test_set_api_key(self):
|
||||||
test_data = 'clearly an english sentence'
|
test_data = 'clearly an english sentence'
|
||||||
self.assertRaises(ValueError,
|
self.assertRaises(IndicoError,
|
||||||
language,
|
language,
|
||||||
test_data,
|
test_data,
|
||||||
api_key ='invalid_api_key')
|
api_key ='invalid_api_key')
|
||||||
@@ -372,7 +373,7 @@ class FullAPIRun(unittest.TestCase):
|
|||||||
config.api_key = 'invalid_api_key'
|
config.api_key = 'invalid_api_key'
|
||||||
|
|
||||||
self.assertEqual(config.api_key, 'invalid_api_key')
|
self.assertEqual(config.api_key, 'invalid_api_key')
|
||||||
self.assertRaises(ValueError,
|
self.assertRaises(IndicoError,
|
||||||
language,
|
language,
|
||||||
test_data)
|
test_data)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user