mirror of
https://github.com/wassname/IndicoIo-python.git
synced 2026-08-11 11:12:45 +08:00
Api standardization, feature importance folder
This commit is contained in:
+24
@@ -0,0 +1,24 @@
|
|||||||
|
language: python
|
||||||
|
python:
|
||||||
|
- 2.7
|
||||||
|
|
||||||
|
# Setup anaconda
|
||||||
|
before_install:
|
||||||
|
- wget http://repo.continuum.io/miniconda/Miniconda-latest-Linux-x86_64.sh -O miniconda.sh
|
||||||
|
- chmod +x miniconda.sh
|
||||||
|
- ./miniconda.sh -b
|
||||||
|
- export PATH=/home/travis/miniconda/bin:$PATH
|
||||||
|
- conda update --yes conda
|
||||||
|
# The next couple lines fix a crash with multiprocessing on Travis and are not specific to using Miniconda
|
||||||
|
- sudo rm -rf /dev/shm
|
||||||
|
- sudo ln -s /run/shm /dev/shm
|
||||||
|
|
||||||
|
# Install packages
|
||||||
|
install:
|
||||||
|
- conda install --yes python=$TRAVIS_PYTHON_VERSION atlas numpy scipy matplotlib nose dateutil pandas statsmodels requests requests six scikit-image
|
||||||
|
- python setup.py install
|
||||||
|
|
||||||
|
# Run test
|
||||||
|
script:
|
||||||
|
- nosetests -w ./tests/remote
|
||||||
|
|
||||||
@@ -1,16 +1,16 @@
|
|||||||
from functools import partial
|
from functools import partial
|
||||||
from utils import config
|
import indicoio.config as config
|
||||||
|
|
||||||
JSON_HEADERS = {'Content-type': 'application/json', 'Accept': 'text/plain'}
|
JSON_HEADERS = {'Content-type': 'application/json', 'Accept': 'text/plain'}
|
||||||
|
|
||||||
Version, version, __version__, VERSION = ('0.4.5',) * 4
|
Version, version, __version__, VERSION = ('0.4.5',) * 4
|
||||||
|
|
||||||
from text.sentiment import political, posneg
|
from indicoio.text.sentiment import political, posneg
|
||||||
from text.sentiment import posneg as sentiment
|
from indicoio.text.sentiment import posneg as sentiment
|
||||||
from text.lang import language
|
from indicoio.text.lang import language
|
||||||
from images.fer import fer
|
from indicoio.images.fer import fer
|
||||||
from images.features import facial_features
|
from indicoio.images.features import facial_features
|
||||||
from images.features import image_features
|
from indicoio.images.features import image_features
|
||||||
|
|
||||||
political = partial(political, config.api_root)
|
political = partial(political, config.api_root)
|
||||||
posneg = partial(posneg, config.api_root)
|
posneg = partial(posneg, config.api_root)
|
||||||
|
|||||||
@@ -3,8 +3,7 @@ import json
|
|||||||
import requests
|
import requests
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
from indicoio import JSON_HEADERS
|
from indicoio.utils import image_preprocess, api_handler
|
||||||
from indicoio.utils import image_preprocess
|
|
||||||
|
|
||||||
def facial_features(api_root, image):
|
def facial_features(api_root, image):
|
||||||
"""
|
"""
|
||||||
@@ -28,14 +27,7 @@ def facial_features(api_root, image):
|
|||||||
:type image: list of lists
|
:type image: list of lists
|
||||||
:rtype: List containing feature responses
|
:rtype: List containing feature responses
|
||||||
"""
|
"""
|
||||||
|
return api_handler(image, api_root + "facialfeatures")
|
||||||
data_dict = json.dumps({"face": image})
|
|
||||||
response = requests.post(api_root + "facialfeatures", data=data_dict, headers=JSON_HEADERS)
|
|
||||||
response_dict = response.json()
|
|
||||||
if 'response' not in response_dict:
|
|
||||||
raise ValueError(response_dict.values()[0])
|
|
||||||
else:
|
|
||||||
return response_dict['response']
|
|
||||||
|
|
||||||
def image_features(api_root, image):
|
def image_features(api_root, image):
|
||||||
"""
|
"""
|
||||||
@@ -68,10 +60,4 @@ def image_features(api_root, image):
|
|||||||
:rtype: List containing features
|
:rtype: List containing features
|
||||||
"""
|
"""
|
||||||
image = image_preprocess(image)
|
image = image_preprocess(image)
|
||||||
data_dict = json.dumps({"image": image})
|
return api_handler(image, api_root + "imagefeatures")
|
||||||
response = requests.post(api_root + "imagefeatures", data=data_dict, headers=JSON_HEADERS)
|
|
||||||
response_dict = response.json()
|
|
||||||
if 'Features' not in response_dict:
|
|
||||||
raise ValueError(response_dict.values()[0])
|
|
||||||
else:
|
|
||||||
return response_dict['Features']
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import json
|
|||||||
|
|
||||||
import requests
|
import requests
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from indicoio import JSON_HEADERS
|
from indicoio.utils import api_handler
|
||||||
|
|
||||||
def fer(api_root, image):
|
def fer(api_root, image):
|
||||||
"""
|
"""
|
||||||
@@ -28,10 +28,4 @@ def fer(api_root, image):
|
|||||||
:rtype: Dictionary containing emotion probability pairs
|
:rtype: Dictionary containing emotion probability pairs
|
||||||
"""
|
"""
|
||||||
|
|
||||||
data_dict = json.dumps({"face": image})
|
return api_handler(image, api_root + "fer")
|
||||||
response = requests.post(api_root + "fer", data=data_dict, headers=JSON_HEADERS)
|
|
||||||
response_dict = response.json()
|
|
||||||
if len(response_dict) < 2:
|
|
||||||
raise ValueError(response_dict.values()[0])
|
|
||||||
else:
|
|
||||||
return response_dict
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
from functools import partial
|
from functools import partial
|
||||||
from indicoio.utils import config
|
import indicoio.config as config
|
||||||
|
|
||||||
JSON_HEADERS = {'Content-type': 'application/json', 'Accept': 'text/plain'}
|
JSON_HEADERS = {'Content-type': 'application/json', 'Accept': 'text/plain'}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import requests
|
import requests
|
||||||
import json
|
import json
|
||||||
|
|
||||||
from indicoio import JSON_HEADERS
|
from indicoio.utils import api_handler
|
||||||
|
|
||||||
def language(api_root, text):
|
def language(api_root, text):
|
||||||
"""
|
"""
|
||||||
@@ -26,10 +26,4 @@ def language(api_root, text):
|
|||||||
:rtype: Dictionary of language probability pairs
|
:rtype: Dictionary of language probability pairs
|
||||||
"""
|
"""
|
||||||
|
|
||||||
data_dict = json.dumps({'text': text})
|
return api_handler(text, api_root + "language")
|
||||||
response = requests.post(api_root + "language", data=data_dict, headers=JSON_HEADERS)
|
|
||||||
response_dict = response.json()
|
|
||||||
if len(response_dict) < 2:
|
|
||||||
raise ValueError(response_dict.values()[0])
|
|
||||||
else:
|
|
||||||
return response_dict
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import requests
|
|||||||
import json
|
import json
|
||||||
|
|
||||||
from indicoio import JSON_HEADERS
|
from indicoio import JSON_HEADERS
|
||||||
from indicoio.utils import normalize
|
from indicoio.utils import api_handler
|
||||||
|
|
||||||
def political(api_root, text):
|
def political(api_root, text):
|
||||||
"""
|
"""
|
||||||
@@ -30,13 +30,7 @@ def political(api_root, text):
|
|||||||
:rtype: Dictionary of party probability pairs
|
:rtype: Dictionary of party probability pairs
|
||||||
"""
|
"""
|
||||||
|
|
||||||
data_dict = json.dumps({'text': text})
|
return api_handler(text, api_root + "political")
|
||||||
response = requests.post(api_root + "political", data=data_dict, headers=JSON_HEADERS)
|
|
||||||
response_dict = response.json()
|
|
||||||
if len(response_dict) < 2:
|
|
||||||
raise ValueError(response_dict.values()[0])
|
|
||||||
else:
|
|
||||||
return response_dict
|
|
||||||
|
|
||||||
def posneg(api_root, text):
|
def posneg(api_root, text):
|
||||||
"""
|
"""
|
||||||
@@ -59,10 +53,4 @@ def posneg(api_root, text):
|
|||||||
:rtype: Float
|
:rtype: Float
|
||||||
"""
|
"""
|
||||||
|
|
||||||
data_dict = json.dumps({'text': text})
|
return api_handler(text, api_root + "sentiment")
|
||||||
response = requests.post(api_root + "sentiment", data=data_dict, headers=JSON_HEADERS)
|
|
||||||
response_dict = response.json()
|
|
||||||
if 'Sentiment' not in response_dict:
|
|
||||||
raise ValueError(response_dict.values()[0])
|
|
||||||
else:
|
|
||||||
return response_dict['Sentiment']
|
|
||||||
|
|||||||
@@ -1,7 +1,18 @@
|
|||||||
import inspect
|
import inspect, json, requests
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from skimage.transform import resize
|
from skimage.transform import resize
|
||||||
|
|
||||||
|
from indicoio import JSON_HEADERS
|
||||||
|
|
||||||
|
def api_handler(arg, url):
|
||||||
|
data_dict = json.dumps({'data': arg})
|
||||||
|
response = requests.post(url, data=data_dict, headers=JSON_HEADERS).json()
|
||||||
|
results = response.get('results', False)
|
||||||
|
if not results:
|
||||||
|
error = response.get('error')
|
||||||
|
raise ValueError(error)
|
||||||
|
return results
|
||||||
|
|
||||||
class TypeCheck(object):
|
class TypeCheck(object):
|
||||||
"""
|
"""
|
||||||
Decorator that performs a typecheck on the input to a function
|
Decorator that performs a typecheck on the input to a function
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
numpy>=1.8.0
|
||||||
|
six>=1.3.0
|
||||||
|
scikit-image>=0.10.1
|
||||||
|
requests>=2.2.1
|
||||||
@@ -8,7 +8,7 @@ except ImportError:
|
|||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="IndicoIo",
|
name="IndicoIo",
|
||||||
version='0.4.5',
|
version='0.4.6',
|
||||||
packages=[
|
packages=[
|
||||||
"indicoio",
|
"indicoio",
|
||||||
"indicoio.text",
|
"indicoio.text",
|
||||||
|
|||||||
Reference in New Issue
Block a user