From 97ab57fbfe55631556cc1556540a6e96ae442587 Mon Sep 17 00:00:00 2001 From: Slater-Victoroff Date: Wed, 14 May 2014 00:04:16 -0400 Subject: [PATCH] updated readme, changed routes, and included some additional infrastructure --- AUTHORS | 2 + CHANGES.txt | 1 + IndicoIo/__init__.py | 4 ++ .../{facial_features.py => features.py} | 7 +++- README | 16 +++++--- README.md | 16 +++++--- setup.py | 3 +- tests/test_run.py | 38 ++++++++++++++++++- 8 files changed, 73 insertions(+), 14 deletions(-) create mode 100644 AUTHORS create mode 100644 CHANGES.txt rename IndicoIo/images/{facial_features.py => features.py} (58%) diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000..4b733af --- /dev/null +++ b/AUTHORS @@ -0,0 +1,2 @@ +Slater Victoroff +Alec Radford diff --git a/CHANGES.txt b/CHANGES.txt new file mode 100644 index 0000000..1f50ed3 --- /dev/null +++ b/CHANGES.txt @@ -0,0 +1 @@ +v0.2.8, Tue May 13 -- Added Description, Authors file, changelog. Cleaned up import paths and modified corresponding examples and tests diff --git a/IndicoIo/__init__.py b/IndicoIo/__init__.py index 4e0105c..7c12b12 100644 --- a/IndicoIo/__init__.py +++ b/IndicoIo/__init__.py @@ -1 +1,5 @@ JSON_HEADERS = {'Content-type': 'application/json', 'Accept': 'text/plain'} + +from text.sentiment import political, spam, posneg +from images.fer import fer +from images.features import facial_features diff --git a/IndicoIo/images/facial_features.py b/IndicoIo/images/features.py similarity index 58% rename from IndicoIo/images/facial_features.py rename to IndicoIo/images/features.py index 1a85c34..0300678 100644 --- a/IndicoIo/images/facial_features.py +++ b/IndicoIo/images/features.py @@ -7,7 +7,10 @@ from IndicoIo import JSON_HEADERS base_url = lambda c: "http://indico.io/api/features/%s" % c -def facial(face): +def facial_features(face, full_return=False): data_dict = json.dumps({"datums": face}) response = requests.post(base_url("facial"), data=data_dict, headers=JSON_HEADERS) - return json.loads(response.content) + response_dict = json.loads(response.content) + if full_return: + return response_dict + return json.loads(response_dict['feature_vector']) diff --git a/README b/README index 2f35b26..45a3d9a 100644 --- a/README +++ b/README @@ -7,6 +7,8 @@ Check out the main site on: http://indico.io +Our APIs are totally free to use, and ready to be used in your application. No data or training required. + Current APIs ------------ @@ -23,9 +25,7 @@ Examples ``` >>> import numpy as np ->>> from IndicoIo.text.sentiment import political, spam, posneg ->>> from IndicoIo.images.fer import fer ->>> from IndicoIo.images.facial_features import facial +>>> from IndicoIo import political, spam, posneg, fer, facial_features >>> political("Guns don't kill people, people kill people") {u'Libertarian': 1.000094905588269, u'Liberal': 1.000194776694221, u'Green': 1.0000989185747784, u'Conservative': 1.000114308739228} @@ -41,7 +41,13 @@ Examples >>> fer(test_face) {u'Angry': 0.08843749137458341, u'Sad': 0.39091163159204684, u'Neutral': 0.1947947999669361, u'Surprise': 0.03443785859010413, u'Fear': 0.17574534848440568, u'Happy': 0.11567286999192382} ->>> facial(test_face) -{u'feature_vector': u'[0.0, -0.02568680526917187, 0.21645604230056517, -0.1519435786033145, -0.5648621854611555, 3.0607368045577226, 0.11434321880792693, -0.02163810928547493, -0.44224330594186484, 0.3024315632285246, -2.6068048934495276, 2.497798330306638, 3.040558335205844, 0.741045340525325, 0.37198135618478817, -0.33132377802172325, -0.9804190889833034, 0.5046575784709395, -0.5609132323152847, 1.679107064439151, 0.6825037853544341, -1.5977176226648016, 1.8959464303080562, -0.7812860715595836, -2.998394007543733, -0.22637273967347724, -0.9642457010679496, 1.4557274834236749, 2.412244419186633, 2.3151771738421965, 0.7881483386786367, 1.6622850935863422, 0.1304768990234367, 1.9344501393866649, 3.1271558035162914, -0.10250886439220543, 1.4921395116492966, 2.761645355670677, 1.6903473594991179, 1.009209807271491, 0.07273926986120445, -1.4941708135718021, -2.082786362439631, 1.0160924044870847, 2.5326580674673895, -0.8328208491083264, 2.0390177029762935, 3.0342637531932777]'} +>>> facial_features(test_face) +[0.0, -0.02568680526917187, 0.21645604230056517, -0.1519435786033145, -0.5648621854611555, 3.0607368045577226, 0.11434321880792693, -0.02163810928547493, -0.44224330594186484, 0.3024315632285246, -2.6068048934495276, 2.497798330306638, 3.040558335205844, 0.741045340525325, 0.37198135618478817, -0.33132377802172325, -0.9804190889833034, 0.5046575784709395, -0.5609132323152847, 1.679107064439151, 0.6825037853544341, -1.5977176226648016, 1.8959464303080562, -0.7812860715595836, -2.998394007543733, -0.22637273967347724, -0.9642457010679496, 1.4557274834236749, 2.412244419186633, 2.3151771738421965, 0.7881483386786367, 1.6622850935863422, 0.1304768990234367, 1.9344501393866649, 3.1271558035162914, -0.10250886439220543, 1.4921395116492966, 2.761645355670677, 1.6903473594991179, 1.009209807271491, 0.07273926986120445, -1.4941708135718021, -2.082786362439631, 1.0160924044870847, 2.5326580674673895, -0.8328208491083264, 2.0390177029762935, 3.0342637531932777] ``` + +Installation +------------ +``` +pip install indicoio +``` diff --git a/README.md b/README.md index 2f35b26..45a3d9a 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,8 @@ Check out the main site on: http://indico.io +Our APIs are totally free to use, and ready to be used in your application. No data or training required. + Current APIs ------------ @@ -23,9 +25,7 @@ Examples ``` >>> import numpy as np ->>> from IndicoIo.text.sentiment import political, spam, posneg ->>> from IndicoIo.images.fer import fer ->>> from IndicoIo.images.facial_features import facial +>>> from IndicoIo import political, spam, posneg, fer, facial_features >>> political("Guns don't kill people, people kill people") {u'Libertarian': 1.000094905588269, u'Liberal': 1.000194776694221, u'Green': 1.0000989185747784, u'Conservative': 1.000114308739228} @@ -41,7 +41,13 @@ Examples >>> fer(test_face) {u'Angry': 0.08843749137458341, u'Sad': 0.39091163159204684, u'Neutral': 0.1947947999669361, u'Surprise': 0.03443785859010413, u'Fear': 0.17574534848440568, u'Happy': 0.11567286999192382} ->>> facial(test_face) -{u'feature_vector': u'[0.0, -0.02568680526917187, 0.21645604230056517, -0.1519435786033145, -0.5648621854611555, 3.0607368045577226, 0.11434321880792693, -0.02163810928547493, -0.44224330594186484, 0.3024315632285246, -2.6068048934495276, 2.497798330306638, 3.040558335205844, 0.741045340525325, 0.37198135618478817, -0.33132377802172325, -0.9804190889833034, 0.5046575784709395, -0.5609132323152847, 1.679107064439151, 0.6825037853544341, -1.5977176226648016, 1.8959464303080562, -0.7812860715595836, -2.998394007543733, -0.22637273967347724, -0.9642457010679496, 1.4557274834236749, 2.412244419186633, 2.3151771738421965, 0.7881483386786367, 1.6622850935863422, 0.1304768990234367, 1.9344501393866649, 3.1271558035162914, -0.10250886439220543, 1.4921395116492966, 2.761645355670677, 1.6903473594991179, 1.009209807271491, 0.07273926986120445, -1.4941708135718021, -2.082786362439631, 1.0160924044870847, 2.5326580674673895, -0.8328208491083264, 2.0390177029762935, 3.0342637531932777]'} +>>> facial_features(test_face) +[0.0, -0.02568680526917187, 0.21645604230056517, -0.1519435786033145, -0.5648621854611555, 3.0607368045577226, 0.11434321880792693, -0.02163810928547493, -0.44224330594186484, 0.3024315632285246, -2.6068048934495276, 2.497798330306638, 3.040558335205844, 0.741045340525325, 0.37198135618478817, -0.33132377802172325, -0.9804190889833034, 0.5046575784709395, -0.5609132323152847, 1.679107064439151, 0.6825037853544341, -1.5977176226648016, 1.8959464303080562, -0.7812860715595836, -2.998394007543733, -0.22637273967347724, -0.9642457010679496, 1.4557274834236749, 2.412244419186633, 2.3151771738421965, 0.7881483386786367, 1.6622850935863422, 0.1304768990234367, 1.9344501393866649, 3.1271558035162914, -0.10250886439220543, 1.4921395116492966, 2.761645355670677, 1.6903473594991179, 1.009209807271491, 0.07273926986120445, -1.4941708135718021, -2.082786362439631, 1.0160924044870847, 2.5326580674673895, -0.8328208491083264, 2.0390177029762935, 3.0342637531932777] ``` + +Installation +------------ +``` +pip install indicoio +``` diff --git a/setup.py b/setup.py index bab3917..3ab3959 100644 --- a/setup.py +++ b/setup.py @@ -5,13 +5,14 @@ except ImportError: setup( name = "IndicoIo", - version = '0.2.7', + version = '0.2.8', packages = [ "IndicoIo", "IndicoIo.text", "IndicoIo.images", "tests", ], + description = "A Python Wrapper for IndicoIo. Use pre-built state of the art machine learning algorithms with a single line of code.", license = "MIT License (See LICENSE)", long_description = open("README").read(), url = "https://github.com/IndicoDataSolutions/IndicoIo-python", diff --git a/tests/test_run.py b/tests/test_run.py index 506faae..5d4714c 100644 --- a/tests/test_run.py +++ b/tests/test_run.py @@ -1,5 +1,9 @@ import unittest -from IndicoIo.text.sentiment import political, spam, posneg + +import numpy as np + +from IndicoIo import political, spam, posneg, fer, facial_features + class FullAPIRun(unittest.TestCase): @@ -27,5 +31,37 @@ class FullAPIRun(unittest.TestCase): self.assertTrue(isinstance(response, dict)) self.assertEqual(posneg_set, set(response.keys())) + def test_good_fer(self): + fer_set = set(['Angry', 'Sad', 'Neutral', 'Surprise', 'Fear', 'Happy']) + test_face = np.linspace(0,50,48*48).reshape(48,48).tolist() + response = fer(test_face) + + self.assertTrue(isinstance(response, dict)) + self.assertEqual(fer_set, set(response.keys())) + + def test_bad_fer(self): + fer_set = set(['Angry', 'Sad', 'Neutral', 'Surprise', 'Fear', 'Happy']) + test_face = np.linspace(0,50,56*56).reshape(56,56).tolist() + response = fer(test_face) + + self.assertTrue(isinstance(response, dict)) + self.assertEqual(fer_set, set(response.keys())) + + def test_good_facial_features(self): + test_face = np.linspace(0,50,48*48).reshape(48,48).tolist() + response = facial_features(test_face) + + self.assertTrue(isinstance(response, list)) + self.assertEqual(len(response), 48) + + def test_full_facial_features(self): + features_set = set(['feature_vector', 'warnings']) + test_face = np.linspace(0,50,56*56).reshape(56,56).tolist() + response = facial_features(test_face, True) + + self.assertEqual(set(response.keys()), features_set) + self.assertEqual(response['warnings'], 'Using a 48x48 array will produce the best results') + + if __name__ == "__main__": unittest.main()