mirror of
https://github.com/wassname/IndicoIo-python.git
synced 2026-06-27 16:10:34 +08:00
Email + password auth from client
This commit is contained in:
@@ -5,7 +5,7 @@ import numpy as np
|
||||
|
||||
from indicoio.utils import image_preprocess, api_handler
|
||||
|
||||
def facial_features(api_root, image, batch=False):
|
||||
def facial_features(api_root, image, batch=False, auth=None):
|
||||
"""
|
||||
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.
|
||||
@@ -27,9 +27,9 @@ def facial_features(api_root, image, batch=False):
|
||||
:type image: list of lists
|
||||
:rtype: List containing feature responses
|
||||
"""
|
||||
return api_handler(image, api_root + "facialfeatures", batch=batch)
|
||||
return api_handler(image, api_root + "facialfeatures", batch=batch, auth=auth)
|
||||
|
||||
def image_features(api_root, image, batch=False):
|
||||
def image_features(api_root, image, batch=False, auth=None):
|
||||
"""
|
||||
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.
|
||||
@@ -60,4 +60,4 @@ def image_features(api_root, image, batch=False):
|
||||
:rtype: List containing features
|
||||
"""
|
||||
image = image_preprocess(image)
|
||||
return api_handler(image, api_root + "imagefeatures", batch=batch)
|
||||
return api_handler(image, api_root + "imagefeatures", batch=batch, auth=auth)
|
||||
|
||||
@@ -4,7 +4,7 @@ import requests
|
||||
import numpy as np
|
||||
from indicoio.utils import api_handler
|
||||
|
||||
def fer(api_root, image, batch=False):
|
||||
def fer(api_root, image, batch=False, auth=None):
|
||||
"""
|
||||
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
|
||||
@@ -28,4 +28,4 @@ def fer(api_root, image, batch=False):
|
||||
:rtype: Dictionary containing emotion probability pairs
|
||||
"""
|
||||
|
||||
return api_handler(image, api_root + "fer", batch=batch)
|
||||
return api_handler(image, api_root + "fer", batch=batch, auth=auth)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from indicoio.utils import api_handler
|
||||
|
||||
def language(api_root, text, batch=False):
|
||||
def language(api_root, text, batch=False, auth=None):
|
||||
"""
|
||||
Given input text, returns a probability distribution over 33 possible
|
||||
languages of what language the text was written in.
|
||||
@@ -23,4 +23,4 @@ def language(api_root, text, batch=False):
|
||||
:rtype: Dictionary of language probability pairs
|
||||
"""
|
||||
|
||||
return api_handler(text, api_root + "language", batch=batch)
|
||||
return api_handler(text, api_root + "language", batch=batch, auth=auth)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from indicoio import JSON_HEADERS
|
||||
from indicoio.utils import api_handler
|
||||
|
||||
def political(api_root, text, batch=False):
|
||||
def political(api_root, text, batch=False, auth=None):
|
||||
"""
|
||||
Given input text, returns a probability distribution over the political alignment of the speaker.
|
||||
|
||||
@@ -27,9 +27,9 @@ def political(api_root, text, batch=False):
|
||||
:rtype: Dictionary of party probability pairs
|
||||
"""
|
||||
|
||||
return api_handler(text, api_root + "political", batch=batch)
|
||||
return api_handler(text, api_root + "political", batch=batch, auth=auth)
|
||||
|
||||
def posneg(api_root, text, batch=False):
|
||||
def posneg(api_root, text, batch=False, auth=None):
|
||||
"""
|
||||
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.
|
||||
@@ -50,4 +50,4 @@ def posneg(api_root, text, batch=False):
|
||||
:rtype: Float
|
||||
"""
|
||||
|
||||
return api_handler(text, api_root + "sentiment", batch=batch)
|
||||
return api_handler(text, api_root + "sentiment", batch=batch, auth=auth)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from indicoio.utils import api_handler
|
||||
|
||||
def text_tags(api_root, text, batch=False):
|
||||
def text_tags(api_root, text, batch=False, auth=None):
|
||||
"""
|
||||
Given input text, returns a probability distribution over 100 document categories
|
||||
|
||||
@@ -22,4 +22,4 @@ def text_tags(api_root, text, batch=False):
|
||||
:rtype: Dictionary of class probability pairs
|
||||
"""
|
||||
|
||||
return api_handler(text, api_root + "texttags", batch=batch)
|
||||
return api_handler(text, api_root + "texttags", batch=batch, auth=None)
|
||||
|
||||
@@ -1,14 +1,31 @@
|
||||
import inspect, json, requests
|
||||
import inspect, json, getpass, os
|
||||
import requests
|
||||
import numpy as np
|
||||
from skimage.transform import resize
|
||||
|
||||
from indicoio import JSON_HEADERS
|
||||
|
||||
def api_handler(arg, url, batch=False):
|
||||
def auth_query():
|
||||
email = os.environ.get("INDICO_EMAIL")
|
||||
password = os.environ.get("INDICO_PASSWORD")
|
||||
|
||||
# store settings
|
||||
if not email:
|
||||
email = raw_input("Email: ")
|
||||
os.environ["INDICO_EMAIL"] = email
|
||||
|
||||
if not password:
|
||||
password = getpass.getpass("Password: ")
|
||||
os.environ["INDICO_PASSWORD"] = password
|
||||
|
||||
return (email, password)
|
||||
|
||||
def api_handler(arg, url, batch=False, auth=None):
|
||||
data_dict = json.dumps({'data': arg})
|
||||
if batch:
|
||||
url += "/batch"
|
||||
response = requests.post(url, data=data_dict, headers=JSON_HEADERS).json()
|
||||
auth = auth_query()
|
||||
response = requests.post(url, data=data_dict, headers=JSON_HEADERS, auth=auth).json()
|
||||
results = response.get('results', False)
|
||||
if not results:
|
||||
error = response.get('error')
|
||||
|
||||
Reference in New Issue
Block a user