mirror of
https://github.com/wassname/IndicoIo-python.git
synced 2026-06-27 16:10:34 +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 utils import config
|
||||
import indicoio.config as config
|
||||
|
||||
JSON_HEADERS = {'Content-type': 'application/json', 'Accept': 'text/plain'}
|
||||
|
||||
Version, version, __version__, VERSION = ('0.4.5',) * 4
|
||||
|
||||
from text.sentiment import political, posneg
|
||||
from text.sentiment import posneg as sentiment
|
||||
from text.lang import language
|
||||
from images.fer import fer
|
||||
from images.features import facial_features
|
||||
from images.features import image_features
|
||||
from indicoio.text.sentiment import political, posneg
|
||||
from indicoio.text.sentiment import posneg as sentiment
|
||||
from indicoio.text.lang import language
|
||||
from indicoio.images.fer import fer
|
||||
from indicoio.images.features import facial_features
|
||||
from indicoio.images.features import image_features
|
||||
|
||||
political = partial(political, config.api_root)
|
||||
posneg = partial(posneg, config.api_root)
|
||||
|
||||
@@ -3,8 +3,7 @@ import json
|
||||
import requests
|
||||
import numpy as np
|
||||
|
||||
from indicoio import JSON_HEADERS
|
||||
from indicoio.utils import image_preprocess
|
||||
from indicoio.utils import image_preprocess, api_handler
|
||||
|
||||
def facial_features(api_root, image):
|
||||
"""
|
||||
@@ -28,14 +27,7 @@ def facial_features(api_root, image):
|
||||
:type image: list of lists
|
||||
:rtype: List containing feature responses
|
||||
"""
|
||||
|
||||
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']
|
||||
return api_handler(image, api_root + "facialfeatures")
|
||||
|
||||
def image_features(api_root, image):
|
||||
"""
|
||||
@@ -68,10 +60,4 @@ def image_features(api_root, image):
|
||||
:rtype: List containing features
|
||||
"""
|
||||
image = image_preprocess(image)
|
||||
data_dict = json.dumps({"image": image})
|
||||
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']
|
||||
return api_handler(image, api_root + "imagefeatures")
|
||||
|
||||
@@ -2,7 +2,7 @@ import json
|
||||
|
||||
import requests
|
||||
import numpy as np
|
||||
from indicoio import JSON_HEADERS
|
||||
from indicoio.utils import api_handler
|
||||
|
||||
def fer(api_root, image):
|
||||
"""
|
||||
@@ -28,10 +28,4 @@ def fer(api_root, image):
|
||||
:rtype: Dictionary containing emotion probability pairs
|
||||
"""
|
||||
|
||||
data_dict = json.dumps({"face": image})
|
||||
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
|
||||
return api_handler(image, api_root + "fer")
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from functools import partial
|
||||
from indicoio.utils import config
|
||||
import indicoio.config as config
|
||||
|
||||
JSON_HEADERS = {'Content-type': 'application/json', 'Accept': 'text/plain'}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import requests
|
||||
import json
|
||||
|
||||
from indicoio import JSON_HEADERS
|
||||
from indicoio.utils import api_handler
|
||||
|
||||
def language(api_root, text):
|
||||
"""
|
||||
@@ -26,10 +26,4 @@ def language(api_root, text):
|
||||
:rtype: Dictionary of language probability pairs
|
||||
"""
|
||||
|
||||
data_dict = json.dumps({'text': text})
|
||||
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
|
||||
return api_handler(text, api_root + "language")
|
||||
|
||||
@@ -2,7 +2,7 @@ import requests
|
||||
import json
|
||||
|
||||
from indicoio import JSON_HEADERS
|
||||
from indicoio.utils import normalize
|
||||
from indicoio.utils import api_handler
|
||||
|
||||
def political(api_root, text):
|
||||
"""
|
||||
@@ -30,13 +30,7 @@ def political(api_root, text):
|
||||
:rtype: Dictionary of party probability pairs
|
||||
"""
|
||||
|
||||
data_dict = json.dumps({'text': text})
|
||||
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
|
||||
return api_handler(text, api_root + "political")
|
||||
|
||||
def posneg(api_root, text):
|
||||
"""
|
||||
@@ -59,10 +53,4 @@ def posneg(api_root, text):
|
||||
:rtype: Float
|
||||
"""
|
||||
|
||||
data_dict = json.dumps({'text': text})
|
||||
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']
|
||||
return api_handler(text, api_root + "sentiment")
|
||||
|
||||
@@ -1,7 +1,18 @@
|
||||
import inspect
|
||||
import inspect, json, requests
|
||||
import numpy as np
|
||||
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):
|
||||
"""
|
||||
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(
|
||||
name="IndicoIo",
|
||||
version='0.4.5',
|
||||
version='0.4.6',
|
||||
packages=[
|
||||
"indicoio",
|
||||
"indicoio.text",
|
||||
|
||||
Reference in New Issue
Block a user