Skip to content

Commit

Permalink
Merge pull request facebookresearch#42 from facebookresearch/mturk-new
Browse files Browse the repository at this point in the history
small refactoring and add helpful instruction
  • Loading branch information
yf225 authored May 4, 2017
2 parents 8b1c004 + 2c52fa0 commit b92347f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
4 changes: 3 additions & 1 deletion parlai/mturk/core/handler_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import data_model

# Dynamically generated code begin
# Expects mturk_submit_url, rds_host, rds_db_name, rds_username, rds_password, task_description, requester_key_gt, num_hits, is_sandbox
# Expects mturk_submit_url, frame_height, rds_host, rds_db_name, rds_username, rds_password, task_description, requester_key_gt, num_hits, is_sandbox
# {{block_task_config}}
# Dynamically generated code end

Expand Down Expand Up @@ -66,6 +66,7 @@ def chat_index(event, context):
template_context['task_description'] = task_description
template_context['mturk_submit_url'] = mturk_submit_url
template_context['is_cover_page'] = False
template_context['frame_height'] = frame_height

return _render_template(template_context, 'mturk_index.html')

Expand Down Expand Up @@ -188,6 +189,7 @@ def approval_index(event, context):
template_context['is_cover_page'] = False
template_context['is_approval_page'] = True
template_context['num_hits'] = int(num_hits)
template_context['frame_height'] = frame_height

return _render_template(template_context, 'mturk_index.html')

Expand Down
2 changes: 1 addition & 1 deletion parlai/mturk/core/mturk_index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<body>
<div class="container-fluid">
<div class="row">
<div id="left-pane" class="col-xs-4" style="height: 650px; background-color: #dff0d8; padding: 30px; overflow:scroll;">
<div id="left-pane" class="col-xs-4" style="height: {{frame_height}}px; background-color: #dff0d8; padding: 30px; overflow:scroll;">
<h1>Live Chat</h1>
<hr style="border-top: 1px solid #555" />
<span id="task-description" style="font-size: 16px">
Expand Down
12 changes: 5 additions & 7 deletions parlai/mturk/core/setup_aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
files_to_copy = [parent_dir+'/'+'data_model.py', parent_dir+'/'+'mturk_index.html']
lambda_server_directory_name = 'lambda_server'
lambda_server_zip_file_name = 'lambda_server.zip'
mturk_hit_frame_height = 650

def add_api_gateway_method(api_gateway_client, lambda_function_arn, rest_api_id, endpoint_resource, http_method_type, response_data_type):
api_gateway_client.put_method(
Expand Down Expand Up @@ -116,7 +117,7 @@ def setup_aws_credentials():
try:
session = boto3.Session(profile_name=aws_profile_name)
except ProfileNotFound as e:
print("AWS credentials not found. Please create an IAM user with programmatic access and AdministratorAccess policy at https://console.aws.amazon.com/iam/, and then enter the user's security credentials below:")
print('''AWS credentials not found. Please create an IAM user with programmatic access and AdministratorAccess policy at https://console.aws.amazon.com/iam/ (On the "Set permissions" page, choose "Attach existing policies directly" and then select "AdministratorAccess" policy). \nAfter creating the IAM user, please enter the user's Access Key ID and Secret Access Key below:''')
aws_access_key_id = input('Access Key ID: ')
aws_secret_access_key = input('Secret Access Key: ')
if not os.path.exists(os.path.expanduser('~/.aws/')):
Expand Down Expand Up @@ -243,6 +244,7 @@ def setup_relay_server_api(mturk_submit_url, rds_host, task_config, is_sandbox,
handler_file_string = handler_template_file.read()
handler_file_string = handler_file_string.replace(
'# {{block_task_config}}',
"frame_height = " + str(mturk_hit_frame_height) + "\n" + \
"mturk_submit_url = \'" + mturk_submit_url + "\'\n" + \
"rds_host = \'" + rds_host + "\'\n" + \
"rds_db_name = \'" + rds_db_name + "\'\n" + \
Expand Down Expand Up @@ -506,16 +508,12 @@ def create_hit_type(hit_title, hit_description, hit_keywords, hit_reward, is_san
def create_hit_with_hit_type(page_url, hit_type_id, is_sandbox):
page_url = page_url.replace('&', '&amp;')

frame_height = 650

question_data_struture = '''<ExternalQuestion xmlns="http://mechanicalturk.amazonaws.com/AWSMechanicalTurkDataSchemas/2006-07-14/ExternalQuestion.xsd">
<ExternalURL>{{external_url}}</ExternalURL>
<FrameHeight>{{frame_height}}</FrameHeight>
<ExternalURL>'''+page_url+'''</ExternalURL>
<FrameHeight>'''+str(mturk_hit_frame_height)+'''</FrameHeight>
</ExternalQuestion>
'''

question_data_struture = question_data_struture.replace('{{external_url}}', page_url).replace('{{frame_height}}', str(frame_height))

client = boto3.client(
service_name = 'mturk',
region_name = 'us-east-1',
Expand Down

0 comments on commit b92347f

Please sign in to comment.