Skip to content

Commit

Permalink
minor cleanup and docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
qmac committed Mar 28, 2018
1 parent b4f2ee5 commit c71f736
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 9 deletions.
14 changes: 11 additions & 3 deletions pliers/converters/api/google.py
Expand Up @@ -22,6 +22,13 @@ class GoogleSpeechAPIConverter(GoogleAPITransformer, AudioToTextConverter):
speech_contexts (list): A list of a list of favored phrases or words
to assist the API. The inner list is a sequence of word tokens,
each outer element is a potential context.
discovery_file (str): path to discovery file containing Google
application credentials.
api_version (str): API version to use.
max_results (int): Max number of results per page.
num_retries (int): Number of times to retry query on failure.
rate_limit (int): The minimum number of seconds required between
transform calls on this Transformer.
'''

api_name = 'speech'
Expand All @@ -47,21 +54,22 @@ def _query_api(self, request):
return request_obj.execute(num_retries=self.num_retries)

def _build_request(self, stim):
audio_desc = {}
tmp = tempfile.mktemp() + '.flac'
stim.clip.write_audiofile(tmp, fps=stim.sampling_rate, codec='flac',
ffmpeg_params=['-ac', '1'])

with open(tmp, 'rb') as f:
data = f.read()
os.remove(tmp)
audio_desc['content'] = base64.b64encode(data).decode()

if self.speech_contexts:
speech_contexts = [{'phrases': c} for c in self.speech_contexts]
else:
speech_contexts = []
request = {
'audio': audio_desc,
'audio': {
'content': base64.b64encode(data).decode()
},
'config': {
'encoding': 'FLAC',
'sampleRateHertz': stim.sampling_rate,
Expand Down
2 changes: 2 additions & 0 deletions pliers/converters/api/ibm.py
Expand Up @@ -30,6 +30,8 @@ class IBMSpeechAPIConverter(APITransformer, AudioToTextConverter):
be separated by (i.e. the unit each TextStim in the ComplexTextStim
elements should be). Currently, only 'words' or 'phrases' are
supported.
rate_limit (int): The minimum number of seconds required between
transform calls on this Transformer.
'''

_env_keys = ('IBM_USERNAME', 'IBM_PASSWORD')
Expand Down
16 changes: 15 additions & 1 deletion pliers/converters/api/microsoft.py
Expand Up @@ -8,7 +8,21 @@
class MicrosoftAPITextConverter(MicrosoftVisionAPITransformer,
ImageToTextConverter):

''' Detects text within images using the Microsoft Vision API. '''
''' Detects text within images using the Microsoft Vision API.
Args:
language (str): Target language to detect in the image.
subscription_key (str): A valid subscription key for Microsoft Cognitive
Services. Only needs to be passed the first time the extractor is
initialized.
location (str): Region the subscription key has been registered in.
It will be the first part of the endpoint URL suggested by
Microsoft when you first created the key.
Examples include: westus, westcentralus, eastus
api_version (str): API version to use.
rate_limit (int): The minimum number of seconds required between
transform calls on this Transformer.
'''

api_method = 'ocr'
_log_attributes = ('subscription_key', 'api_version', 'language')
Expand Down
2 changes: 2 additions & 0 deletions pliers/converters/api/wit.py
Expand Up @@ -20,6 +20,8 @@ class SpeechRecognitionAPIConverter(APITransformer, AudioToTextConverter):
Args:
api_key (str): API key. Must be passed explicitly or stored in
the environment variable specified in the _env_keys field.
rate_limit (int): The minimum number of seconds required between
transform calls on this Transformer.
'''

_log_attributes = ('api_key', 'recognize_method')
Expand Down
3 changes: 2 additions & 1 deletion pliers/extractors/api/clarifai.py
Expand Up @@ -12,7 +12,6 @@
from pliers.transformers import BatchTransformerMixin
from pliers.transformers.api import APITransformer
from pliers.utils import listify, attempt_to_import, verify_dependencies
from six.moves.urllib.parse import urlparse
import pandas as pd

clarifai_client = attempt_to_import('clarifai.rest.client', 'clarifai_client',
Expand All @@ -39,6 +38,8 @@ class ClarifaiAPIExtractor(APITransformer, BatchTransformerMixin,
number of label predictions returned.
select_concepts (list): List of concepts (strings) to query from the
API. For example, ['food', 'animal'].
rate_limit (int): The minimum number of seconds required between
transform calls on this Transformer.
'''

_log_attributes = ('api_key', 'model', 'model_name', 'min_value',
Expand Down
2 changes: 2 additions & 0 deletions pliers/extractors/api/indico.py
Expand Up @@ -22,6 +22,8 @@ class IndicoAPIExtractor(APITransformer, BatchTransformerMixin, Extractor):
api_key (str): A valid API key for the Indico API. Only needs to be
passed the first time the extractor is initialized.
models (list): The names of the Indico models to use.
rate_limit (int): The minimum number of seconds required between
transform calls on this Transformer.
'''

_log_attributes = ('api_key', 'models', 'model_names')
Expand Down
28 changes: 24 additions & 4 deletions pliers/extractors/api/microsoft.py
Expand Up @@ -15,15 +15,25 @@ class MicrosoftAPIFaceExtractor(MicrosoftAPITransformer, ImageExtractor):
image using the Microsoft Azure Cognitive Services API.
Args:
face_id (bool): return faceIds of the detected faces or not. The
face_id (bool): Return faceIds of the detected faces or not. The
default value is False.
landmarks (str): return face landmarks of the detected faces or
landmarks (str): Return face landmarks of the detected faces or
not. The default value is False.
attributes (list): one or more specified face attributes as strings.
attributes (list): One or more specified face attributes as strings.
Supported face attributes include accessories, age, blur, emotion,
exposure, facialHair, gender, glasses, hair, headPose, makeup,
noise, occlusion, and smile. Note that each attribute has
additional computational and time cost.
subscription_key (str): A valid subscription key for Microsoft Cognitive
Services. Only needs to be passed the first time the extractor is
initialized.
location (str): Region the subscription key has been registered in.
It will be the first part of the endpoint URL suggested by
Microsoft when you first created the key.
Examples include: westus, westcentralus, eastus
api_version (str): API version to use.
rate_limit (int): The minimum number of seconds required between
transform calls on this Transformer.
'''

api_name = 'face'
Expand Down Expand Up @@ -116,11 +126,21 @@ class MicrosoftVisionAPIExtractor(MicrosoftVisionAPITransformer,
''' Base MicrosoftVisionAPIExtractor class.
Args:
features (list): one or more specified vision features as strings.
features (list): One or more specified vision features as strings.
Supported vision features include Tags, Categories, ImageType,
Color, and Adult. Note that each attribute has additional
computational and time cost. By default extracts all visual
features from an image.
subscription_key (str): A valid subscription key for Microsoft Cognitive
Services. Only needs to be passed the first time the extractor is
initialized.
location (str): Region the subscription key has been registered in.
It will be the first part of the endpoint URL suggested by
Microsoft when you first created the key.
Examples include: westus, westcentralus, eastus
api_version (str): API version to use.
rate_limit (int): The minimum number of seconds required between
transform calls on this Transformer.
'''

api_method = 'analyze'
Expand Down
2 changes: 2 additions & 0 deletions pliers/transformers/api/google.py
Expand Up @@ -22,6 +22,8 @@ class GoogleAPITransformer(APITransformer):
api_version (str): API version to use.
max_results (int): Max number of results per page.
num_retries (int): Number of times to retry query on failure.
rate_limit (int): The minimum number of seconds required between
transform calls on this Transformer.
'''

_env_keys = 'GOOGLE_APPLICATION_CREDENTIALS'
Expand Down
2 changes: 2 additions & 0 deletions pliers/transformers/api/microsoft.py
Expand Up @@ -19,6 +19,8 @@ class MicrosoftAPITransformer(APITransformer):
Microsoft when you first created the key.
Examples include: westus, westcentralus, eastus
api_version (str): API version to use.
rate_limit (int): The minimum number of seconds required between
transform calls on this Transformer.
'''

_log_attributes = ('subscription_key', 'location', 'api_version')
Expand Down

0 comments on commit c71f736

Please sign in to comment.