Skip to content

Instantly share code, notes, and snippets.

@AmazonMTurk
Last active October 24, 2017 22:17
Show Gist options
  • Save AmazonMTurk/44e9bf2cb7f7f8bc5f4b25d973ab6437 to your computer and use it in GitHub Desktop.
Save AmazonMTurk/44e9bf2cb7f7f8bc5f4b25d973ab6437 to your computer and use it in GitHub Desktop.
Getting Started with Emotion Detection
from mturk_crowd_beta_client import MTurkCrowdClient
from boto3.session import Session
import uuid
# This examples assume you have a local AWS profile called
# 'mturk-crowd-caller', but you can authenticate however you like,
# including by directly passing in your access key and secret key.
session = Session(profile_name='mturk-crowd-caller')
# Create the client
crowd_client = MTurkCrowdClient(session)
# For this example, we'll give our task a random, unique name. For prod
# tasks, you'll probably want to pick a name based on your input source.
task_name = 'my-test-task-' + uuid.uuid4().hex
# Next, we specify the name of the function to call
# In this example, we're first calling the emotion-detection-test function.
# The test function doesn't cost any money and is useful for validating that your account is setup correctly and for testing your integration.
# To call the prod emotion-detection function, uncomment the next line and comment out the emotion-detection-test line
# function_name = 'emotion-detection'
function_name = 'emotion-detection-test'
# The text we want labeled
text = 'First time ever winning all three fantasy leagues AND @Seahawks win!'
# Create the task
put_result = crowd_client.put_task(function_name,
task_name,
{'text': text})
print('PUT response: {}'.format(
{'status_code': put_result.status_code, 'task': put_result.json()}))
# Get the task we just created. Note that for a prod (i.e., non-test) task,
# we'd have to poll periodically until the task completed.
# Since we are running a test, this will return mock results.
get_result = crowd_client.get_task(function_name, task_name)
print('GET response: {}'.format(
{'api-name': function_name, 'note': 'SAMPLE RESULTS ONLY', 'status_code': get_result.status_code, 'task': get_result.json()}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment