mirror of
https://github.com/wassname/IndicoIo-python.git
synced 2026-07-30 11:50:43 +08:00
Passing in a root_url variable and pulling config from environment variables
This commit is contained in:
committed by
Madison May
parent
a1621e8531
commit
6b9251f4f5
@@ -1,5 +1,4 @@
|
|||||||
from functools import partial
|
from functools import partial
|
||||||
import indicoio.config as config
|
|
||||||
|
|
||||||
JSON_HEADERS = {'Content-type': 'application/json', 'Accept': 'text/plain'}
|
JSON_HEADERS = {'Content-type': 'application/json', 'Accept': 'text/plain'}
|
||||||
|
|
||||||
@@ -16,11 +15,7 @@ from indicoio.images.features import image_features
|
|||||||
apis = ['political', 'posneg', 'sentiment', 'language', 'fer',
|
apis = ['political', 'posneg', 'sentiment', 'language', 'fer',
|
||||||
'facial_features', 'image_features', 'text_tags']
|
'facial_features', 'image_features', 'text_tags']
|
||||||
apis = dict((api, globals().get(api)) for api in apis)
|
apis = dict((api, globals().get(api)) for api in apis)
|
||||||
class Namespace(object): pass
|
|
||||||
local = Namespace()
|
|
||||||
|
|
||||||
for api in apis:
|
for api in apis:
|
||||||
globals()[api] = partial(apis[api], config.api_root)
|
globals()[api] = partial(apis[api])
|
||||||
globals()['batch_' + api] = partial(apis[api], config.api_root, batch=True)
|
globals()['batch_' + api] = partial(apis[api], batch=True)
|
||||||
setattr(local, api, partial(apis[api], config.local_api_root))
|
|
||||||
setattr(local, 'batch_' + api, partial(apis[api], config.local_api_root, batch=True))
|
|
||||||
|
|||||||
+3
-2
@@ -1,2 +1,3 @@
|
|||||||
local_api_root = "http://localhost:9438/"
|
import os
|
||||||
api_root = "http://apiv1.indico.io/"
|
|
||||||
|
api_root = os.getenv("INDICO_PRIVATE_CLOUD_URL") or "http://apiv1.indico.io/"
|
||||||
|
|||||||
@@ -4,8 +4,9 @@ import requests
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
from indicoio.utils import image_preprocess, api_handler
|
from indicoio.utils import image_preprocess, api_handler
|
||||||
|
import indicoio.config as config
|
||||||
|
|
||||||
def facial_features(api_root, image, batch=False, auth=None, **kwargs):
|
def facial_features(image, url_root=config.api_root, batch=False, auth=None, **kwargs):
|
||||||
"""
|
"""
|
||||||
Given an grayscale input image of a face, returns a 48 dimensional feature vector explaining that face.
|
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.
|
Useful as a form of feature engineering for face oriented tasks.
|
||||||
@@ -27,9 +28,9 @@ def facial_features(api_root, image, batch=False, auth=None, **kwargs):
|
|||||||
: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", batch=batch, auth=auth, **kwargs)
|
return api_handler(image, url_root + "facialfeatures", batch=batch, auth=auth, **kwargs)
|
||||||
|
|
||||||
def image_features(api_root, image, batch=False, auth=None, **kwargs):
|
def image_features(image, url_root=config.api_root, batch=False, auth=None, **kwargs):
|
||||||
"""
|
"""
|
||||||
Given an input image, returns a 2048 dimensional sparse feature vector explaining that image.
|
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.
|
Useful as a form of feature engineering for image oriented tasks.
|
||||||
@@ -60,4 +61,4 @@ def image_features(api_root, image, batch=False, auth=None, **kwargs):
|
|||||||
:rtype: List containing features
|
:rtype: List containing features
|
||||||
"""
|
"""
|
||||||
image = image_preprocess(image, batch=batch)
|
image = image_preprocess(image, batch=batch)
|
||||||
return api_handler(image, api_root + "imagefeatures", batch=batch, auth=auth, **kwargs)
|
return api_handler(image, url_root + "imagefeatures", batch=batch, auth=auth, **kwargs)
|
||||||
|
|||||||
@@ -2,9 +2,11 @@ import json
|
|||||||
|
|
||||||
import requests
|
import requests
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from indicoio.utils import api_handler
|
|
||||||
|
|
||||||
def fer(api_root, image, batch=False, auth=None, **kwargs):
|
from indicoio.utils import api_handler
|
||||||
|
import indicoio.config as config
|
||||||
|
|
||||||
|
def fer(image, url_root=config.api_root, batch=False, auth=None, **kwargs):
|
||||||
"""
|
"""
|
||||||
Given a grayscale input image of a face, returns a probability distribution over emotional state.
|
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
|
Input should be in a list of list format, resizing will be attempted internally but for best
|
||||||
@@ -28,4 +30,4 @@ def fer(api_root, image, batch=False, auth=None, **kwargs):
|
|||||||
:rtype: Dictionary containing emotion probability pairs
|
:rtype: Dictionary containing emotion probability pairs
|
||||||
"""
|
"""
|
||||||
|
|
||||||
return api_handler(image, api_root + "fer", batch=batch, auth=auth, **kwargs)
|
return api_handler(image, url_root + "fer", batch=batch, auth=auth, **kwargs)
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
from indicoio.utils import api_handler
|
from indicoio.utils import api_handler
|
||||||
|
import indicoio.config as config
|
||||||
|
|
||||||
def language(api_root, text, batch=False, auth=None, **kwargs):
|
def language(text, url_root=config.api_root, batch=False, auth=None, **kwargs):
|
||||||
"""
|
"""
|
||||||
Given input text, returns a probability distribution over 33 possible
|
Given input text, returns a probability distribution over 33 possible
|
||||||
languages of what language the text was written in.
|
languages of what language the text was written in.
|
||||||
@@ -23,4 +24,4 @@ def language(api_root, text, batch=False, auth=None, **kwargs):
|
|||||||
:rtype: Dictionary of language probability pairs
|
:rtype: Dictionary of language probability pairs
|
||||||
"""
|
"""
|
||||||
|
|
||||||
return api_handler(text, api_root + "language", batch=batch, auth=auth, **kwargs)
|
return api_handler(text, url_root + "language", batch=batch, auth=auth, **kwargs)
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
from indicoio import JSON_HEADERS
|
from indicoio import JSON_HEADERS
|
||||||
from indicoio.utils import api_handler
|
from indicoio.utils import api_handler
|
||||||
|
import indicoio.config as config
|
||||||
|
|
||||||
def political(api_root, text, batch=False, auth=None, **kwargs):
|
def political(text, url_root=config.api_root, batch=False, auth=None, **kwargs):
|
||||||
"""
|
"""
|
||||||
Given input text, returns a probability distribution over the political alignment of the speaker.
|
Given input text, returns a probability distribution over the political alignment of the speaker.
|
||||||
|
|
||||||
@@ -27,9 +28,9 @@ def political(api_root, text, batch=False, auth=None, **kwargs):
|
|||||||
:rtype: Dictionary of party probability pairs
|
:rtype: Dictionary of party probability pairs
|
||||||
"""
|
"""
|
||||||
|
|
||||||
return api_handler(text, api_root + "political", batch=batch, auth=auth, **kwargs)
|
return api_handler(text, url_root + "political", batch=batch, auth=auth, **kwargs)
|
||||||
|
|
||||||
def posneg(api_root, text, batch=False, auth=None, **kwargs):
|
def posneg(text, url_root=config.api_root, batch=False, auth=None, **kwargs):
|
||||||
"""
|
"""
|
||||||
Given input text, returns a scalar estimate of the sentiment of that text.
|
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.
|
Values are roughly in the range 0 to 1 with 0.5 indicating neutral sentiment.
|
||||||
@@ -50,4 +51,4 @@ def posneg(api_root, text, batch=False, auth=None, **kwargs):
|
|||||||
:rtype: Float
|
:rtype: Float
|
||||||
"""
|
"""
|
||||||
|
|
||||||
return api_handler(text, api_root + "sentiment", batch=batch, auth=auth, **kwargs)
|
return api_handler(text, url_root + "sentiment", batch=batch, auth=auth, **kwargs)
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
from indicoio.utils import api_handler
|
from indicoio.utils import api_handler
|
||||||
|
import indicoio.config as config
|
||||||
|
|
||||||
def text_tags(api_root, text, batch=False, auth=None, **kwargs):
|
def text_tags(text, url_root=config.api_root, batch=False, auth=None, **kwargs):
|
||||||
"""
|
"""
|
||||||
Given input text, returns a probability distribution over 100 document categories
|
Given input text, returns a probability distribution over 100 document categories
|
||||||
|
|
||||||
@@ -22,4 +23,4 @@ def text_tags(api_root, text, batch=False, auth=None, **kwargs):
|
|||||||
:rtype: Dictionary of class probability pairs
|
:rtype: Dictionary of class probability pairs
|
||||||
"""
|
"""
|
||||||
|
|
||||||
return api_handler(text, api_root + "texttags", batch=batch, auth=auth, **kwargs)
|
return api_handler(text, url_root + "texttags", batch=batch, auth=auth, **kwargs)
|
||||||
|
|||||||
Reference in New Issue
Block a user