mirror of
https://github.com/wassname/IndicoIo-python.git
synced 2026-07-23 12:40:06 +08:00
Ensuring calls default to the values found by the Settings object in indicoio.config
This commit is contained in:
+10
-2
@@ -12,8 +12,16 @@ from indicoio.images.fer import fer
|
||||
from indicoio.images.features import facial_features
|
||||
from indicoio.images.features import image_features
|
||||
|
||||
apis = ['political', 'posneg', 'sentiment', 'language', 'fer',
|
||||
'facial_features', 'image_features', 'text_tags']
|
||||
apis = [
|
||||
'political',
|
||||
'posneg',
|
||||
'sentiment',
|
||||
'language',
|
||||
'fer',
|
||||
'facial_features',
|
||||
'image_features',
|
||||
'text_tags'
|
||||
]
|
||||
apis = dict((api, globals().get(api)) for api in apis)
|
||||
|
||||
for api in apis:
|
||||
|
||||
+4
-4
@@ -44,11 +44,11 @@ class Settings(ConfigParser.ConfigParser):
|
||||
os.getenv("INDICO_PASSWORD") or self.auth_settings.get('password')
|
||||
)
|
||||
|
||||
settings = Settings(files=[
|
||||
SETTINGS = Settings(files=[
|
||||
os.path.expanduser("~/.indicorc"),
|
||||
os.path.join(os.getcwd(), '.indicorc')
|
||||
])
|
||||
|
||||
auth = settings.auth()
|
||||
cloud = settings.cloud()
|
||||
public_api_host = 'apiv1.indico.io'
|
||||
AUTH = SETTINGS.auth()
|
||||
CLOUD = SETTINGS.cloud()
|
||||
PUBLIC_API_HOST = 'apiv1.indico.io'
|
||||
|
||||
@@ -6,7 +6,7 @@ import numpy as np
|
||||
from indicoio.utils import image_preprocess, api_handler
|
||||
import indicoio.config as config
|
||||
|
||||
def facial_features(image, cloud=config.cloud, batch=False, auth=None, **kwargs):
|
||||
def facial_features(image, cloud=config.CLOUD, batch=False, auth=None, **kwargs):
|
||||
"""
|
||||
Given an grayscale input image of a face, returns a 48 dimensional feature vector explaining that face.
|
||||
Useful as a form of feature engineering for face oriented tasks.
|
||||
@@ -30,7 +30,7 @@ def facial_features(image, cloud=config.cloud, batch=False, auth=None, **kwargs)
|
||||
"""
|
||||
return api_handler(image, cloud=cloud, api="facialfeatures", batch=batch, auth=auth, **kwargs)
|
||||
|
||||
def image_features(image, cloud=config.cloud, batch=False, auth=None, **kwargs):
|
||||
def image_features(image, cloud=config.CLOUD, batch=False, auth=None, **kwargs):
|
||||
"""
|
||||
Given an input image, returns a 2048 dimensional sparse feature vector explaining that image.
|
||||
Useful as a form of feature engineering for image oriented tasks.
|
||||
|
||||
@@ -6,7 +6,7 @@ import numpy as np
|
||||
from indicoio.utils import api_handler
|
||||
import indicoio.config as config
|
||||
|
||||
def fer(image, cloud=config.cloud, batch=False, auth=None, **kwargs):
|
||||
def fer(image, cloud=config.CLOUD, batch=False, auth=None, **kwargs):
|
||||
"""
|
||||
Given a grayscale input image of a face, returns a probability distribution over emotional state.
|
||||
Input should be in a list of list format, resizing will be attempted internally but for best
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from indicoio.utils import api_handler
|
||||
import indicoio.config as config
|
||||
|
||||
def language(text, cloud=config.cloud, batch=False, auth=None, **kwargs):
|
||||
def language(text, cloud=config.CLOUD, batch=False, auth=None, **kwargs):
|
||||
"""
|
||||
Given input text, returns a probability distribution over 33 possible
|
||||
languages of what language the text was written in.
|
||||
|
||||
@@ -2,7 +2,7 @@ from indicoio import JSON_HEADERS
|
||||
from indicoio.utils import api_handler
|
||||
import indicoio.config as config
|
||||
|
||||
def political(text, cloud=config.cloud, batch=False, auth=None, **kwargs):
|
||||
def political(text, cloud=config.CLOUD, batch=False, auth=None, **kwargs):
|
||||
"""
|
||||
Given input text, returns a probability distribution over the political alignment of the speaker.
|
||||
|
||||
@@ -30,7 +30,7 @@ def political(text, cloud=config.cloud, batch=False, auth=None, **kwargs):
|
||||
|
||||
return api_handler(text, cloud=cloud, api="political", batch=batch, auth=auth, **kwargs)
|
||||
|
||||
def posneg(text, cloud=config.cloud, batch=False, auth=None, **kwargs):
|
||||
def posneg(text, cloud=config.CLOUD, batch=False, auth=None, **kwargs):
|
||||
"""
|
||||
Given input text, returns a scalar estimate of the sentiment of that text.
|
||||
Values are roughly in the range 0 to 1 with 0.5 indicating neutral sentiment.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from indicoio.utils import api_handler
|
||||
import indicoio.config as config
|
||||
|
||||
def text_tags(text, cloud=config.cloud, batch=False, auth=None, **kwargs):
|
||||
def text_tags(text, cloud=config.CLOUD, batch=False, auth=None, **kwargs):
|
||||
"""
|
||||
Given input text, returns a probability distribution over 100 document categories
|
||||
|
||||
|
||||
@@ -13,16 +13,18 @@ def api_handler(arg, cloud, api, batch=False, auth=None, **kwargs):
|
||||
json_data = json.dumps(data)
|
||||
|
||||
if cloud:
|
||||
host = "%s.indico.domains"
|
||||
host = "%s.indico.domains" % cloud
|
||||
else:
|
||||
# default to indico public cloud
|
||||
host = config.public_api_host
|
||||
host = config.PUBLIC_API_HOST
|
||||
|
||||
url = "http://%s/%s" % (host, api)
|
||||
|
||||
if batch:
|
||||
url += "/batch"
|
||||
|
||||
if not auth:
|
||||
auth = config.AUTH
|
||||
|
||||
response = requests.post(url, data=json_data, headers=JSON_HEADERS, auth=auth).json()
|
||||
results = response.get('results', False)
|
||||
if results is False:
|
||||
|
||||
Reference in New Issue
Block a user