如何使用boto3提交Mechanical Turk外部问题 [英] How to submit Mechanical Turk ExternalQuestions with boto3
问题描述
我正在尝试使用boto3以编程方式在机械特克上创建一个问题,但是我似乎做错了,因为create_hit
所需的ExternalQuestion
数据结构似乎丢失了.
I am trying to programmatically create a question on mechanical turk using boto3, but I seem to be doing something wrong, since the ExternalQuestion
data structure that is required for create_hit
seems to be missing.
我尝试像这样创建HIT:
I try to create the HIT like so:
import boto3
#...
client = boto3.client(
'mturk',
endpoint_url=endpoint_url,
region_name=region_name,
aws_access_key_id=aws_access_key_id,
aws_secret_access_key=aws_secret_access_key,
)
question = ExternalQuestion(external_url=question_target, frame_height=800)
response = client.create_hit(
MaxAssignments=10,
Title='Test',
Description='This is a test of ExternalQuestion',
Question=question,
AssignmentDurationInSeconds=60,
LifetimeInSeconds=24 * 60 * 60,
Reward=0.01)
哪个失败:
Traceback (most recent call last):
File "createTask.py", line 21, in <module>
question = ExternalQuestion(external_url=question_target, frame_height=800)
NameError: name 'ExternalQuestion' is not defined
任何有关如何进行的建议都将受到高度赞赏.
Any advice on how to proceed is highly appreciated.
推荐答案
这是我的生产代码中的直接片段.我打开一个XML文件,您可以从请求者站点获取该文件的模板,然后将其修改为包含您自己的javascript和html.我将在下面附上示例.
This is a direct snip from my production code. I open an XML file which you can get a template for from the requester site and then just ammend it to contain your own javascript and html. I will attach a sample below.
Python
import boto3
region_name = 'us-east-1'
aws_access_key_id = '*********************'
aws_secret_access_key = '*********************'
endpoint_url = 'https://mturk-requester-sandbox.us-east-1.amazonaws.com'
# Uncomment this line to use in production
#endpoint_url = 'https://mturk-requester.us-east-1.amazonaws.com'
client = boto3.client(
'mturk',
endpoint_url=endpoint_url,
region_name=region_name,
aws_access_key_id=aws_access_key_id,
aws_secret_access_key=aws_secret_access_key,
)
questionSampleFile = open("K:/" + str(somefile) + ".xml", "r")
questionSample = questionSampleFile.read()
localRequirements = [{
'QualificationTypeId': '00000000000000000071',
'Comparator': 'NotIn',
'LocaleValues': [{
'Country': 'WF'
}],
'RequiredToPreview': True
}]
xReward = '0.25'
# Create the HIT
response = client.create_hit(
MaxAssignments = 1,
#AutoApprovalDelayInSeconds = 259200,
#3 days for lifetime
LifetimeInSeconds = 172800,
#1 hour to finish the assignment
AssignmentDurationInSeconds = 5400,
Reward = xReward,
Title = 'Enter Missing Data',
Keywords = 'data entry, typing, inspection',
Description = 'Edit and Add Data from PDF',
Question = questionSample,
QualificationRequirements = localRequirements
)
XML
<HTMLQuestion xmlns="http://mechanicalturk.amazonaws.com/AWSMechanicalTurkDataSchemas/2011-11-11/HTMLQuestion.xsd">
<HTMLContent><![CDATA[
]]>
</HTMLContent>
<FrameHeight>900</FrameHeight>
</HTMLQuestion>
这篇关于如何使用boto3提交Mechanical Turk外部问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!