def createQuestion(identifier, displayName, questionText, answers): """ Create a question """ questionContent = QuestionContent() #questionTitle = FormattedContent('<font face="Helvetica" size="2"><b> Sentence #' + str(displayName + 1) + '</b></font>') #questionContent.append(questionTitle) instruction = 'Which of the following sentiments <i>best</i> matches the sentiment expressed in the above sentence?' #questionBody = FormattedContent('<font face="Helvetica" size="2">' + questionText + '</font>') #questionContent.append(questionBody) questionInstruction = FormattedContent('<font face="Helvetica" size="2">' + instruction + '</font>') questionContent.append(questionInstruction) #answerTuple = tuple([('<a href="https://wikipedia.org/en/' + y.replace(" ","_") + '" target="_blank">' + y + "</a>") for y in list(answers)]) #links = FormattedContent('<b>Links</b> | ' + answerTuple[0] + ' | ' + answerTuple[1]) #questionContent.append(links) displayName = "Question #" + str(displayName + 1) question = MTurkQuestion(identifier=identifier, content=questionContent, display_name=displayName, answer_spec=AnswerSpecification( buildAnswers(answers)), is_required=True) return question
def __generate_qualification_test(self, question_data, num_correct, title): ''' Returns a QuestionForm and AnswerKey for a qualification test from a list of sentence dictionaries ''' # Get question and answer data questions = map( lambda (i, x): self.__generate_qualification_question(x, i), enumerate(question_data)) answers = map(lambda (i, x): x["answer_key_" + str(i)], enumerate(questions)) answer_key = self.__generate_answer_key(answers, num_correct, len(question_data)) # Create form setup qual_overview = Overview() qual_overview.append_field("Title", title) # Instructions qual_overview.append( FormattedContent("<h1>You must correctly code " + str(num_correct) + " out of the " + str(len(question_data)) + " test sentences below.</h1>")) qual_overview.append( FormattedContent( "<h2>Coding instructions are listed below. Please read through these carefully before continuing on to the coding task.</h2>" )) inst_url = "https://s3.amazonaws.com/aws.drewconway.com/mt/experiments/cmp/html/instructions.html" qual_overview.append( FormattedContent( '<iframe src="' + inst_url + '" frameborder="0" width="1280" height="300" scrolling="auto">This text is necessary to ensure proper XML validation</iframe>' )) # Create question form and append contents qual_form = QuestionForm() qual_form.append(qual_overview) for q in questions: i = q["question_num"] qual_form.append(q["policy_area_" + str(i)]) qual_form.append(q["econ_scale_" + str(i)]) qual_form.append(q["soc_scale_" + str(i)]) return (qual_form, answer_key)
def __generate_qualification_question(self, sentence_data, question_num): ''' Returns a sentence coding qualification test, with answer key ''' url_left = sentence_data['question_' + str(question_num + 1)]['URL_left'] url_right = sentence_data['question_' + str(question_num + 1)]['URL_right'] # retrieve picture to examine its resolution file_left = cStringIO.StringIO(urllib.urlopen(url_left).read()) img_left = Image.open(file_left) left_height = img_left.height if left_height > 400: left_height = 400 file_right = cStringIO.StringIO(urllib.urlopen(url_right).read()) img_right = Image.open(file_right) right_height = img_right.height if right_height > 400: right_height = 400 options = [('Left', '0'), ('Right', '1')] question_content = QuestionContent() question_content.append_field( 'Title', 'Indicate which one of the following images is better in terms of composition.' ) question_content.append( FormattedContent( 'Left: <img src="' + url_left + '" height="' + str(left_height) + '" alt="Left picture"></img>Right: <img src="' + url_right + '" height="' + str(right_height) + '" alt="Right picutre"></img>')) answer_selection = SelectionAnswer(min=1, max=1, style='radiobutton', selections=options, type='text', other=False) question = Question(identifier='photo_pair_' + str(question_num), content=question_content, answer_spec=AnswerSpecification(answer_selection), is_required=True) # Glue everything together in a dictionary, keyed by the question_num return { "question_num": question_num, "question_" + str(question_num): question, "answer_key_" + str(question_num): self.__generate_answer_form(sentence_data, question_num) }
def createHits(question, answers, params): if SANDBOX: mturk_url = 'mechanicalturk.sandbox.amazonaws.com' preview_url = 'https://workersandbox.mturk.com/mturk/preview?groupId=' else: mturk_url = 'mechanicalturk.amazonaws.com' preview_url = 'https://mturk.com/mturk/preview?groupId=' #Create Hit Form Structure overview = Overview() overview.append_field('Title', 'We want to know the crowds opinion!') overview.append( FormattedContent( '<a href="http://programthecrowd.com/">Visit us here</a>')) questionContent = QuestionContent() questionContent.append_field('Title', question) answerChoices = SelectionAnswer(min=1, max=1, style='checkbox', selections=answers, type='text', other=False) q = Question(identifier='Help', content=questionContent, answer_spec=AnswerSpecification(answerChoices), is_required=True) questionForm = QuestionForm() questionForm.append(overview) questionForm.append(q) hitIdList = [] global conn # key = params['aws_access_key'] # secret = params['aws_secret_key'] conn = MTurkConnection( aws_access_key_id='AKIAJBTEJI2RGTJH7OBA', aws_secret_access_key='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', host=mturk_url) #For Loop to create and post hits for i in range(0, NUMBER_OF_HITS): create_hit_rs = conn.create_hit(questions=questionForm, lifetime=LIFETIME, max_assignments=NUMBER_OF_ASSIGNMENTS, title=TITLE, keywords=KEYWORDS, reward=REWARD, duration=DURATION, approval_delay=APPROVAL_DELAY, annotation=DESCRIPTION) #print(preview_url + create_hit_rs[0].HITTypeId) #print("HIT ID: " + create_hit_rs[0].HITId) hitIdList.append(create_hit_rs[0].HITId) return hitIdList
def __generate_qualification_test(self, question_data, num_correct, title): ''' Returns a QuestionForm and AnswerKey for a qualification test from a list of sentence dictionaries. question_data : json object containing all the questions. ''' # Get question and answer data questions = map( lambda (i, x): self.__generate_qualification_question(x, i), enumerate(question_data)) answers = map(lambda (i, x): x["answer_key_" + str(i)], enumerate(questions)) answer_key = self.__generate_answer_key(answers, num_correct, len(question_data)) # Create form setup qual_overview = Overview() qual_overview.append_field("Title", title) # Instructions qual_overview.append( FormattedContent( "<h1>Please answer all the questions below.</h1>")) qual_overview.append( FormattedContent( "<h2>For each question, please choose either the left or right image \ which you think is more beautiful in terms of its composition. Hints: Please make your decision based on\ several 'rules of thumb' in photography, such as rule of thirds, visual balance and golden ratio. \ You may also make your decision by judging which image contains less unimportant or distracting contents.</h2>" )) # Create question form and append contents qual_form = QuestionForm() qual_form.append(qual_overview) for q in questions: i = q["question_num"] qual_form.append(q["question_" + str(i)]) return (qual_form, answer_key)
def make_many_to_many_form(questions): if not questions: raise ValueError('Questions cannot be empty!') question_form = QuestionForm() for q in questions: qid = q['id'] q_text = SimpleField('Text', q['content']) contents = [q_text] if q.has_key('url'): contents.append(FormattedContent(make_image_content(q['url']))) q_content = QuestionContent(contents) selections = [(i, i) for i in q['options']] answer_spec = AnswerSpecification(SelectionAnswer(min=1, max=len(q['options']), style='checkbox', selections=selections)) question = Question(qid, q_content, answer_spec, True) question_form.append(question) return question_form
def make_question_form_HIT(self, audio_clip_urls, hit_title, question_title, description, keywords, duration=DEFAULT_DURATION, reward=DEFAULT_REWARD): overview = Overview() overview.append_field("Title", hit_title) #overview.append(FormattedContent('<a target = "_blank" href="url">hyperlink</a>')) question_form = QuestionForm() question_form.append(overview) for ac in audio_clip_urls: audio_html = self.transcription_question.replace( self.audio_url_tag, ac) qc = QuestionContent() qc.append_field("Title", question_title) qc.append(FormattedContent(audio_html)) fta = FreeTextAnswer() q = Question(identifier="transcription", content=qc, answer_spec=AnswerSpecification(fta)) question_form.append(q) try: response = self.conn.create_hit(questions=question_form, max_assignments=1, title=hit_title, description=description, keywords=keywords, duration=duration, reward=reward) except MTurkRequestError as e: if e.reason != "OK": raise return question_form, response
def createQuestionForm(overviewTitle, overviewDescription, numberOfTweets, listOfTweets, listOfTweetIDs): """ Create an overview for an MTurk HIT """ #The Question Form should contain 1 overview and 3 odd questions questionForm = QuestionForm() #Define the Overview overview = Overview() Title = FormattedContent(overviewTitle) overview.append(Title) overviewDescription1 = FormattedContent(overviewDescription[0]) overviewDescription2 = FormattedContent(overviewDescription[1]) overviewDescription3 = FormattedContent(overviewDescription[2]) overview.append(overviewDescription1) overview.append(overviewDescription2) overview.append(overviewDescription3) #Append the Overview to the Question Form questionForm.append(overview) #Create the Questions, and Add them for i in xrange(numberOfTweets): overview = Overview() questionTitle = FormattedContent( '<font face="Helvetica" size="2"><b> Tweet #' + str(i + 1) + '</b></font>') overview.append(questionTitle) questionBody = FormattedContent('<font face="Helvetica" size="2">' + listOfTweets[i] + '</font>') overview.append(questionBody) #answerTuple = tuple([('<a href="https://wikipedia.org/en/' + y.replace(" ","_") + '" target="_blank">' + y + "</a>") for y in list(listOfAnswers[i])]) #links = FormattedContent('<b>Links</b> | ' + answerTuple[0] + ' | ' + answerTuple[1]) #overview.append(links) questionForm.append(overview) question = createQuestion(listOfTweetIDs[i], i, listOfTweets[i], ["Positive", "Negative"]) questionForm.append(question) return questionForm
host=HOST) title = 'Profile of record Athlete Information' description = ('Provide Information about the Athlete') keywords = 'website, rating, opinions' height =[('4\'11','4\'11'),('5\'1','5\'1'),('5\'2','5\'2'),('5\'3','5\'3'),('5\'4','5\'4'),('5\'5','5\'5'),('5\'6','5\'6'),('5\'7','5\'7')] #--------------- BUILD OVERVIEW ------------------- overview = Overview() overview.append_field('Title', 'What is the Height if this Athlete?') overview.append(FormattedContent('<a> target="_blank"' ' href="https://en.wikipedia.org/wiki/Brett_Favre"' ' Athlete Information URL</a>')) # ##--------------- BUILD QUESTION ------------------- # qc = QuestionContent() qc.append_field('Title','What is the Height of Brett Favre') fta = SelectionAnswer(min=1, max=1,style='dropdown', selections=height, type='text', other=False) q = Question(identifier='design', content=qc, answer_spec=AnswerSpecification(fta),
def generate_hits(subset, begin_index, args, data_ids, images_metainfo): from boto.mturk.connection import MTurkConnection from boto.mturk.question import QuestionContent, Question, QuestionForm, Overview, AnswerSpecification, SelectionAnswer, FormattedContent, FreeTextAnswer from boto.mturk.qualification import PercentAssignmentsApprovedRequirement, Qualifications ACCESS_ID = amazon_config.ACCESS_ID SECRET_KEY = amazon_config.SECRET_KEY HOST = 'mechanicalturk.amazonaws.com' mtc = MTurkConnection(aws_access_key_id=ACCESS_ID, aws_secret_access_key=SECRET_KEY, host=HOST) title = 'Give your opinion of interestingness level about images' description = ( 'Watch images and give us your opinion of interestingness level about the images' ) keywords = 'image, interestingness, interesting, rating, opinions' ratings = [('Very boring', '-2'), ('Boring', '-1'), ('Neutral', '0'), ('Interesting', '1'), ('Very interesting, I would like to share it with my friends.', '2')] #--------------- BUILD OVERVIEW ------------------- overview = Overview() overview.append_field( 'Title', 'Give your opinion about interestingness level on those images') #--------------- BUILD QUESTIONs ------------------- questions = [] utils.write_file(subset, args.o + '.index_' + str(begin_index) + '.txt') index = 0 for image_url in subset: image_id = data_ids[index] image = images_metainfo[image_id] interestingness = 0 if ('repin_count' in image): interestingness = int(image['repin_count']) + int( image['like_count']) #else: # interestingness = int(image['interestingness']) index = index + 1 qc = QuestionContent() context = '' if (interestingness > 0): context = ' (shared by ' + str(interestingness) + ' people)' qc.append_field('Title', 'How interesting the image' + context + ' to you?') qc.append( FormattedContent('<img src="' + image_url + '" alt="image" />')) fta = SelectionAnswer(min=1, max=1, style='dropdown', selections=ratings, type='text', other=False) q = Question(identifier='interestingness', content=qc, answer_spec=AnswerSpecification(fta), is_required=True) questions.append(q) #--------------- BUILD THE QUESTION FORM ------------------- question_form = QuestionForm() question_form.append(overview) for question in questions: question_form.append(question) # BUILD QUALIFICATION qualifications = Qualifications() req = PercentAssignmentsApprovedRequirement(comparator="GreaterThan", integer_value="95") qualifications.add(req) #--------------- CREATE THE HIT ------------------- mtc.create_hit(questions=question_form, qualifications=qualifications, max_assignments=10, title=title, description=description, keywords=keywords, duration=60 * 30, reward=0.2)
title = 'Match these Pictures to Macy\'s Products' description = 'Look at this photo and match it to Macy\'s products' keywords = 'clothing, rating, opinions, easy, quick, macys' ratings = [('Very Bad', '1'), ('Bad', '2'), ('OK', '3'), ('Good', '4'), ('Very Good', '5')] #make overview overview = Overview() overview.append_field('Title', 'Rank how these two images match.') overview.append( FormattedContent('<table border="1"><tr><td width="50%"><img src="' + PIN_IMAGE_URL + '" alt="Pintrest Image" /></td>' '<td width="50%"><img src="' + MACYS_IMAGE_URL + '" alt="Macys Image" /></td></tr><tr>' '<td width="50%">' + PIN_IMAGE_TITLE + '</td><td width="50%">' + MACYS_IMAGE_TITLE + '</td></tr></table>')) #make q1 qc1 = QuestionContent() qc1.append_field('Title', 'Rank the match between these two') fta1 = SelectionAnswer(min=1, max=1, style='dropdown', selections=ratings, type='text', other=False)
description = ('Visit a website and give us your opinion about' ' the design and also some personal comments') keywords = 'website, rating, opinions' #ratings =[('Very Bad','-2'), # ('Bad','-1'), # ('Not bad','0'), # ('Good','1'), # ('Very Good','1')] # #--------------- BUILD OVERVIEW ------------------- overview = Overview() overview.append_field('Title', 'Give your opinion on this website') overview.append(FormattedContent('<a target="_blank"' ' href="https://shop.sqor.com/">' ' Sqor Sports Shop</a>')) # ##--------------- BUILD QUESTION 1 ------------------- # #qc1 = QuestionContent() #qc1.append_field('Title','How looks the design ?') # #fta1 = SelectionAnswer(min=1, max=1,style='dropdown', # selections=ratings, # type='text', # other=False) # #q1 = Question(identifier='design', # content=qc1, # answer_spec=AnswerSpecification(fta1),
def __generate_qualification_question(self, sentence_data, question_num): ''' Returns a sentence coding qualification test, with answer key ''' # # Coding scale data econ_scale = [('', 'NA'), ('Very left', '-2'), ('Somewhat left', '-1'), ('Neither left nor right', '0'), ('Somewhat right', '1'), ('Very right', '2')] soc_scale = [('', 'NA'), ('Very liberal', '2'), ('Somewhat liberal', '-1'), ('Neither liberal nor conservative', '0'), ('Somewhat conservative', '1'), ('Very conservative', '2')] policy_area = [('Select policy area', '0'), ('Not Economic or Social', '1'), ('Economic', '2'), ('Social', '3')] # Generate the question text externally. tuid = sentence_data["text_unit_id"] q_url = "http://s3.amazonaws.com/aws.drewconway.com/mt/experiments/cmp/html/formatted_sentence.html?text_unit_id=" q_url_formatted = q_url + str(tuid) + "&question_num=" + str( question_num) # Create policy area question and answer fields content_sentence = QuestionContent() content_sentence.append_field("Title", "#" + str(question_num + 1)) content_sentence.append( FormattedContent( '<iframe src="' + q_url_formatted + '" frameborder="0" width="1280" height="180" scrolling="auto">This text is necessary to ensure proper XML validation</iframe>' )) ans_policy_area = SelectionAnswer(min=1, max=1, style="dropdown", selections=policy_area) qst_policy_area = Question( identifier="policy_area_" + str(question_num), content=content_sentence, answer_spec=AnswerSpecification(ans_policy_area), is_required=True) # Create 'Economic' policy scale question and answer fields content_econ_policy = QuestionContent() content_econ_policy.append_field( "Text", "If you selected 'Not Economic or Social' the task is complete. Either move to the next sentence, or submit your answers." ) content_econ_policy.append_field( "Text", "If you selected 'Economic', now select economic policy scale below. Otherwise, do not make a selection." ) ans_econ_scale = SelectionAnswer(min=1, max=1, style="dropdown", selections=econ_scale) qst_econ_policy = Question( identifier="econ_scale_" + str(question_num), content=content_econ_policy, answer_spec=AnswerSpecification(ans_econ_scale), is_required=True) # Create 'Social' policy scale question and answer fields content_soc_policy = QuestionContent() content_soc_policy.append_field( "Text", "If you selected 'Social', now select the social policy scale below. Otherwise, do not make a selection." ) ans_soc_scale = SelectionAnswer(min=1, max=1, style="dropdown", selections=soc_scale) qst_soc_policy = Question( identifier="soc_scale_" + str(question_num), content=content_soc_policy, answer_spec=AnswerSpecification(ans_soc_scale), is_required=True) # Glue everything together in a dictionary, keyed by the question_num return { "question_num": question_num, "policy_area_" + str(question_num): qst_policy_area, "econ_scale_" + str(question_num): qst_econ_policy, "soc_scale_" + str(question_num): qst_soc_policy, "answer_key_" + str(question_num): self.__generate_answer_form(sentence_data, question_num) }
def question_form_formatted_content(self): qc = QuestionContent() formatted_xhtml = """\ <table border="1"> <tr> <td></td> <td align="center">1</td> <td align="center">2</td> <td align="center">3</td> </tr> <tr> <td align="right">A</td> <td align="center"><b>X</b></td> <td align="center"> </td> <td align="center"><b>O</b></td> </tr> <tr> <td align="right">B</td> <td align="center"> </td> <td align="center"><b>O</b></td> <td align="center"> </td> </tr> <tr> <td align="right">C</td> <td align="center"> </td> <td align="center"> </td> <td align="center"><b>X</b></td> </tr> <tr> <td align="center" colspan="4">It is <b>X</b>'s turn.</td> </tr> </table> """ qc.append(FormattedContent(formatted_xhtml)) q = Question( identifier="Formatted content test!", content=qc, answer_spec=AnswerSpecification( SelectionAnswer( min=1, max=5, style='checkbox', selections=[ (Binary( 'image', 'jpg', 'http://images.google.com/images?q=tbn:ANd9GcSh1HXq3WyOvvG7-AgvNugKC2LzImMUvUDNTuDAPwVKuw8NZzvLN62pGYhX:farm1.static.flickr.com/21/24204504_e143536a2e.jpg', 'steak1').get_as_xml(), 'img1'), (Binary( 'image', 'jpg', 'http://images.google.com/images?q=tbn:ANd9GcTkMoChevUBvQfmfksKDBM5oj4V2ruj6riqv7kC-_6qf9MR0igeBlJLkSI:www.miranchomeatmarket.com/images/T-%2520bone%2520steak.jpg', 'steak2').get_as_xml(), 'img2'), (Binary( 'image', 'jpg', 'http://images.google.com/images?q=tbn:ANd9GcSttsqT7kj9siDKZg1p4fU6W9IFlMZHCFSxFd49ECJR1Bu_1QlHQwmH1DU:img4.myrecipes.com/i/recipes/ck/06/08/grilled-steak-ck-1215910-l.jpg', 'steak3').get_as_xml(), 'img3'), (Binary( 'image', 'jpg', 'http://images.google.com/images?q=tbn:ANd9GcRfdQ-vuNt-W4W7JZRkAmbZpE6LLA0puCQs5erSzrGtsOY8H8t-vgEzqA:www.greendiamondgrille.com/images/new/NewYorkStripSteak.jpg', 'steak4').get_as_xml(), 'img4'), (Binary( 'image', 'jpg', 'http://images.google.com/images?q=tbn:ANd9GcTsJzCp6En1R9yvFQw7bGsSxiiQCqlMrFg7XCbcJ13G39Aa3e6ZilWW34oI:www.bunrab.com/dailyfeed/dailyfeed_images_jan-07/df07_01-08_steak.jpg', 'steak5').get_as_xml(), 'img5'), (Binary( 'image', 'jpg', 'http://images.google.com/images?q=tbn:ANd9GcTkMoChevUBvQfmfksKDBM5oj4V2ruj6riqv7kC-_6qf9MR0igeBlJLkSI:www.miranchomeatmarket.com/images/T-%2520bone%2520steak.jpg', 'steak2').get_as_xml(), 'img6'), (Binary( 'image', 'jpg', 'http://images.google.com/images?q=tbn:ANd9GcSttsqT7kj9siDKZg1p4fU6W9IFlMZHCFSxFd49ECJR1Bu_1QlHQwmH1DU:img4.myrecipes.com/i/recipes/ck/06/08/grilled-steak-ck-1215910-l.jpg', 'steak3').get_as_xml(), 'img7'), (Binary( 'image', 'jpg', 'http://images.google.com/images?q=tbn:ANd9GcRfdQ-vuNt-W4W7JZRkAmbZpE6LLA0puCQs5erSzrGtsOY8H8t-vgEzqA:www.greendiamondgrille.com/images/new/NewYorkStripSteak.jpg', 'steak4').get_as_xml(), 'img8'), (Binary( 'image', 'jpg', 'http://images.google.com/images?q=tbn:ANd9GcTsJzCp6En1R9yvFQw7bGsSxiiQCqlMrFg7XCbcJ13G39Aa3e6ZilWW34oI:www.bunrab.com/dailyfeed/dailyfeed_images_jan-07/df07_01-08_steak.jpg', 'steak5').get_as_xml(), 'img9') ], type='binary')), is_required=True, display_name="This is display name") qf = QuestionForm() qf.append(q) if self.hit_type_id: try: create_hit_rs = self.connect.create_hit( hit_type=self.hit_type_id, question=qf, lifetime=datetime.timedelta(days=14), max_assignments=1, annotation="This is a annotation") except MTurkRequestError as e: print "create hit type error:\n status: %s reason: %s\n body: %s" % ( e.status, e.reason, e.body) else: print "success!! key: %s" % create_hit_rs
def add_image(url, overview, width=20, height=20): """Add an image to :param overview:. """ overview.append_field('Text', title) overview.append(FormattedContent( '<img src="{0}" alt="Pic" height="500" width="500"></img>'.format(url))) return overview
def demo_create_favorite_color_hit(): """A HIT to determine the Worker's favorite color""" TITLE = 'Tell me your favorite color' DESCRIPTION = ('This is a HIT that is created by a computer program ' 'to demonstrate how Mechanical Turk works. This should ' 'be a free HIT for the worker.') KEYWORDS = 'data collection, favorite, color' DURATION = 15 * 60 # 15 minutes (Time to work on HIT) MAX_ASSIGNMENTS = 1 # Number of assignments per HIT REWARD_PER_ASSIGNMENT = 0.00 # $0.00 USD (1 cent) #--------------- BUILD HIT container ------------------- overview = Overview() overview.append_field('Title', TITLE) overview.append( FormattedContent( "<p>This is an experiment to learn Mechanical Turk</p>")) #--------------- BUILD QUESTION 1 ------------------- question_content = QuestionContent() question_content.append( FormattedContent( "<b>What is your favorite color?</b> There isn't a financial " "reward for answering, but you will get an easy approval for your " "statistics.")) free_text_answer = FreeTextAnswer(num_lines=1) q1 = Question(identifier='favorite_color', content=question_content, answer_spec=AnswerSpecification(free_text_answer), is_required=True) #--------------- BUILD QUESTION 3 ------------------- question_content = QuestionContent() question_content.append( FormattedContent("""<p>Give me a fun comment:</p>""")) q2 = Question(identifier="comments", content=question_content, answer_spec=AnswerSpecification(FreeTextAnswer())) #--------------- BUILD THE QUESTION FORM ------------------- question_form = QuestionForm() question_form.append(overview) question_form.append(q1) question_form.append(q2) #--------------- CREATE THE HIT ------------------- mtc = get_connection() hit = mtc.create_hit(questions=question_form, max_assignments=MAX_ASSIGNMENTS, title=TITLE, description=DESCRIPTION, keywords=KEYWORDS, duration=DURATION, reward=REWARD_PER_ASSIGNMENT) #---------- SHOW A LINK TO THE HIT GROUP ----------- base = get_worker_url() print "\nVisit this website to see the HIT that was created:" print "%s/mturk/preview?groupId=%s" % (base, hit[0].HITTypeId) return hit[0]
aws_secret_access_key=AWS_SECRET_ACCESS_KEY, host=HOST) if debug: print mtc.get_account_balance() title = 'Match these Pictures to Macy\'s Products' description = 'Look at this photo and match it to Macy\'s products' keywords = 'clothing, rating, opinions, easy, quick, macys' #make overview overview = Overview() overview.append_field('Title', 'Find three Macys.com Product Web IDs That Match') overview.append( FormattedContent('<img src="' + PIN_IMAGE_URL + '" alt="Pintrest Image" />' '<br />' + PIN_IMAGE_TITLE)) #make webid1 qc1 = QuestionContent() qc1.append_field('Title', 'First WebID Code') fta1 = FreeTextAnswer(num_lines=1) q1 = Question(identifier="FirstWebCode", content=qc1, answer_spec=AnswerSpecification(fta1)) #make webid2 qc2 = QuestionContent()
def create_crop_hit(mturk, URLs, num_assignment, qualification=Qualifications()): # Constant data for HIT generation hit_title = "Photo Quality Assessment" hit_description = "This task involves viewing pairs of pictures and judging which picture among the image pair is more beautiful." lifetime = 259200 keywords = ["photo", "quality", "ranking"] duration = 30 * 60 reward = 0.05 #approval_delay = 86400 # Question form for the HIT question_form = QuestionForm() overview = Overview() overview.append_field('Title', 'Photo Quality Assessment') overview.append( FormattedContent( 'For each question, please choose either the left or right image which you think is more beautiful in terms of its <u>composition</u>.' )) overview.append( FormattedContent( '<b>Hints: Please make your decision based on several "rules of thumb" in photography, such as rule of thirds, visual balance and golden ratio.</b>' )) #overview.append(FormattedContent('<b>You may also make your decision by judging which image contains less unimportant or distracting contents</b>.')) overview.append( FormattedContent( 'For those hard cases, please just select your preferred image based on your sense of aesthetics.' )) question_form.append(overview) ratings = [('Left', '0'), ('Right', '1')] for i in xrange(len(URLs)): qc = QuestionContent() qc.append_field('Title', 'Question') qc.append_field( 'Text', 'Please indicate which one of the following images is more beautiful.' ) qc.append( FormattedContent('<img src="' + URLs[i] + '" alt="Image not shown correctly!"></img>')) #URLs[i] fta = SelectionAnswer(min=1, max=1, style='radiobutton', selections=ratings, type='text', other=False) q = Question(identifier='photo_pair_' + str(i), content=qc, answer_spec=AnswerSpecification(fta), is_required=True) question_form.append(q) hit_res = mturk.create_hit( title=hit_title, description=hit_description, reward=Price(amount=reward), duration=duration, keywords=keywords, #approval_delay=approval_delay, question=question_form, #lifetime=lifetime, max_assignments=num_assignment, qualifications=qualification) # return HIT ID return hit_res[0].HITId
def submit_extract_keywords_hit(note): """Create a Mechanical Turk HIT that asks a worker to choose keywords and definitions from the given note.""" MTURK_HOST = run_mturk('submit_extract_keywords_hit') if not MTURK_HOST: return connection = MTurkConnection(settings.AWS_ACCESS_KEY_ID, settings.AWS_SECRET_ACCESS_KEY, host=MTURK_HOST) if note.course.school: title = KEYWORDS_HIT_TITLE_TEMPLATE.format( course=note.course.name, school=note.course.school.name) else: title = KEYWORDS_HIT_TITLE_TEMPLATE.format( course=note.course.name, school=note.course.department.school.name) overview = Overview() overview.append( FormattedContent( KEYWORDS_HIT_OVERVIEW_TEMPLATE.format( domain=Site.objects.get_current(), link=note.get_absolute_url()))) keyword_fta = FreeTextAnswer() keyword_fta.num_lines = 1 definition_fta = FreeTextAnswer() definition_fta.num_lines = 3 question_form = QuestionForm() question_form.append(overview) for i in range( min(len(KEYWORDS_HIT_KEYWORD_FIELDS), len(KEYWORDS_HIT_DEFINITION_FIELDS))): keyword_content = QuestionContent() keyword_content.append_field('Title', KEYWORDS_HIT_KEYWORD_FIELDS[i][1]) keyword_question = Question( identifier=KEYWORDS_HIT_KEYWORD_FIELDS[i][0], content=keyword_content, answer_spec=AnswerSpecification(keyword_fta), is_required=True if i <= 10 else False) question_form.append(keyword_question) definition_content = QuestionContent() definition_content.append_field('Title', KEYWORDS_HIT_DEFINITION_FIELDS[i][1]) definition_question = Question( identifier=KEYWORDS_HIT_DEFINITION_FIELDS[i][0], content=definition_content, answer_spec=AnswerSpecification(definition_fta), is_required=False) question_form.append(definition_question) hit = connection.create_hit(questions=question_form, max_assignments=1, title=title, description=KEYWORDS_HIT_DESCRIPTION, keywords=KEYWORDS_HIT_KEYWORDS, duration=KEYWORDS_HIT_DURATION, reward=KEYWORDS_HIT_REWARD, qualifications=KEYWORDS_HIT_QUALIFICATION, annotation=str(note.id))[0] KeywordExtractionHIT.objects.create(HITId=hit.HITId, note=note, processed=False)
def check_notes_mailbox(): MTURK_HOST = run_mturk('get_extract_keywords_results') if not MTURK_HOST: return try: MAILBOX_USER = os.environ['NOTES_MAILBOX_USERNAME'] MAILBOX_PASSWORD = os.environ['NOTES_MAILBOX_PASSWORD'] FILEPICKER_API_KEY = os.environ['FILEPICKER_API_KEY'] except: logger.warn( 'Could not find notes mailbox secrets, not running check_notes_mailbox' ) return connection = MTurkConnection(settings.AWS_ACCESS_KEY_ID, settings.AWS_SECRET_ACCESS_KEY, host=MTURK_HOST) mailbox = poplib.POP3_SSL('pop.gmail.com', 995) mailbox.user(MAILBOX_USER) mailbox.pass_(MAILBOX_PASSWORD) numMessages = len(mailbox.list()[1]) for i in range(numMessages): # construct message object from raw message raw_message_string = '\n'.join(mailbox.retr(i + 1)[1]) message = email.message_from_string(raw_message_string) if not message.is_multipart(): logger.warn('Got an email with no attachments') continue attachments = [] message_body = '' message_parts = message.get_payload() for part in message_parts: # Look for the message's plain text body if part.get_content_type( ) == 'text/plain' and part['Content-Disposition'] is None: message_body = part.get_payload() # Look for attachments elif part['Content-Disposition'] and 'attachment;' in part[ 'Content-Disposition']: attachment_mimetype = part.get_content_type() attachment_filename = re.search( CONTENT_DISPOSITION_REGEX, part['Content-Disposition']).group('filename') if part['Content-Transfer-Encoding'] == 'base64': attachment_data = base64.decodestring(part.get_payload()) else: attachment_data = part.get_payload() # Upload attachment to filepicker resp = requests.post('https://www.filepicker.io/api/store/S3?key={key}&policy={policy}&' \ 'signature={signature}&mimetype={mimetype}&filename={filename}' .format(key=FILEPICKER_API_KEY, policy=FP_POLICY_READ_WRITE, signature=FP_SIGNATURE_READ_WRITE, mimetype=attachment_mimetype, filename=attachment_filename), data=attachment_data) if resp.status_code == 200: url = json.loads(resp.text)['url'] url = url + '?policy={policy}&signature={signature}'\ .format(policy=FP_POLICY_READ, signature=FP_SIGNATURE_READ) attachments.append((url, attachment_filename)) else: logger.warn('Could not upload an attachment to filepicker') message_subject = message['Subject'] overview = Overview() overview.append( FormattedContent( EMAIL_HIT_OVERVIEW_TEMPLATE.format(subject=message_subject, body=message_body, attachments=''))) single_line_answer = FreeTextAnswer() single_line_answer.num_lines = 1 question_form = QuestionForm() question_form.append(overview) course_spam_content = QuestionContent() course_spam_content.append_field( 'Title', 'Does the email contain course notes (check attachments below)?') answer = SelectionAnswer(style='dropdown', selections=[('No', 'no'), ('Yes', 'yes')]) course_spam = Question(identifier=COURSE_SPAM_QID, content=course_spam_content, answer_spec=AnswerSpecification(answer), is_required=True) question_form.append(course_spam) course_name_content = QuestionContent() course_name_content.append_field('Title', 'Course Name') course_name = Question( identifier=COURSE_NAME_QID, content=course_name_content, answer_spec=AnswerSpecification(single_line_answer), is_required=True) question_form.append(course_name) instructor_names_content = QuestionContent() instructor_names_content.append_field('Title', 'Instructor Name(s)') instructor_names = Question( identifier=INSTRUCTOR_NAMES_QID, content=instructor_names_content, answer_spec=AnswerSpecification(single_line_answer), is_required=False) question_form.append(instructor_names) school_name_content = QuestionContent() school_name_content.append_field('Title', 'School Name') school_name = Question( identifier=SCHOOL_NAME_QID, content=school_name_content, answer_spec=AnswerSpecification(single_line_answer), is_required=True) question_form.append(school_name) department_name_content = QuestionContent() department_name_content.append_field('Title', 'Department Name') department_name = Question( identifier=DEPARTMENT_NAME_QID, content=department_name_content, answer_spec=AnswerSpecification(single_line_answer), is_required=False) question_form.append(department_name) for i in range(len(attachments)): overview = Overview() overview.append( FormattedContent( EMAIL_HIT_ATTACHMENT_OVERVIEW_TEMPLATE.format( link=attachments[i][0], name=attachments[i][1]))) question_form.append(overview) note_title_content = QuestionContent() note_title_content.append_field('Title', 'Note Title') note_title = Question( identifier=NOTE_TITLE_QID_TEMPLATE + str(i), content=note_title_content, answer_spec=AnswerSpecification(single_line_answer), is_required=True) question_form.append(note_title) note_category_content = QuestionContent() note_category_content.append_field('Title', 'Note Category') answer = SelectionAnswer(style='dropdown', selections=NOTE_CATEGORIES_FOR_MTURK) note_category = Question(identifier=NOTE_CATEGORY_QID_TEMPLATE + str(i), content=note_category_content, answer_spec=AnswerSpecification(answer), is_required=True) question_form.append(note_category) hit = connection.create_hit(questions=question_form, max_assignments=1, title=EMAIL_HIT_TITLE, description=EMAIL_HIT_DESCRIPTION, keywords=EMAIL_HIT_KEYWORDS, duration=EMAIL_HIT_DURATION, reward=EMAIL_HIT_REWARD, qualifications=EMAIL_HIT_QUALIFICATION)[0]
HOST = 'mechanicalturk.sandbox.amazonaws.com' mtc = MTurkConnection(aws_access_key_id=ACCESS_ID, aws_secret_access_key=SECRET_KEY, host=HOST) title = 'Transcription of promotions from image into text' description = ('Find the promotion information from the image provided.') keywords = 'image, text, promotion' #--------------- BUILD OVERVIEW ------------------- overview = Overview() overview.append_field('Title', title) overview.append( FormattedContent('<a target="_blank"' ' href="http://google.com">' ' Hello</a>')) #--------------- BUILD QUESTION 1 ------------------- qc1 = QuestionContent() qc1.append_field('Title', 'How looks the design ?') fta1 = SelectionAnswer(min=1, max=1, style='dropdown', selections=ratings, type='text', other=False) q1 = Question(identifier='design',
def PublishTasks(hitNum, maxAssignments): # sandbox in which to simulate: mechanicalturk.sandbox.amazonaws.com # real environment: mechanicalturk.amazonaws.com mtc = MTurkConnection(host='mechanicalturk.amazonaws.com') # print mtc.APIVersion # print mtc.get_account_balance() # print mtc.get_reviewable_hits() # print mtc.get_all_hits() #--------------- BUILD OVERVIEW ------------------- # jbragg: Modified maximum reward description. #title = '(Maximum reward possible: $70) Identify the relation between two entities in English sentences' title = 'Identify the relation between two entities in English sentences' #description = 'You will be given English sentences in which your task is to identify the relation between two designated entities. Your reward will depend on how many questions you have answered. The maximum reward you can earn is $70.' description = 'You will be given English sentences in which your task is to identify the relation between two designated entities. Your reward will depend on how many questions you have answered. The maximum reward you can earn is approximately $5.' keywords = 'English sentences, relation identification' ratings = [('Very Bad', '-2'), ('Bad', '-1'), ('Not bad', '0'), ('Good', '1'), ('Very Good', '1')] #--------------- BUILD OVERVIEW ------------------- overview = Overview() overview_title = 'Exercise link (please copy the link and paste it in your browser if it cannot be opened directly.)' link = '<a target="_blank"' ' href="http://128.208.3.167:3000/mturk">' ' http://128.208.3.167:3000/mturk</a>' # jbragg: Commented out long-term bonus. instructions = '<p>Instructions:</p><ul><li>You will be presented with sentences that have a person and a location highlighted.</li><li>Your task is to determine which of the 5 designated relations are expressed between the person and location.</li><li>You'll get paid $0.50 after each successful set of 20 questions<!-- -- plus a bonus of $2.00 after every 10 batches (equal to 200 questions)-->.</li><li>We know the correct answers to some of these sentence questions, and you can stay if you get these questions right.</li><li>You can start by going to the external link above now. After you finish all the questions, you will be provided with a confirm code, used for authentication and determining the appropriate amount of money as the payment.</li><li>In very rare cases where the website crashes, you could click backward and then forward on your browser to reload the question. It won\'t affect the payment because all the questions you have answered are recorded, on which the amount of payment is based. So please don\'t worry about that.</li></ul>' overview_content = link + instructions overview.append_field('Title', overview_title) overview.append(FormattedContent(overview_content)) #--------------- BUILD QUESTION 1 ------------------- qc1 = QuestionContent() qc1.append_field('Title', 'How looks the design ?') fta1 = SelectionAnswer(min=1, max=1, style='dropdown', selections=ratings, type='text', other=False) q1 = Question(identifier='design', content=qc1, answer_spec=AnswerSpecification(fta1), is_required=True) #--------------- BUILD QUESTION 2 ------------------- qc2 = QuestionContent() qc2.append_field( 'Title', 'Confirm code \n1. The code will be provided to you as you finish from the exercise link. \n2. The code will be verified before paying. \n3. By the end of every 20 questions (as a batch), You can choose to finish and get a confirm code, or continue.' ) fta2 = FreeTextAnswer() q2 = Question(identifier="Confirm_code", content=qc2, answer_spec=AnswerSpecification(fta2)) #--------------- BUILD THE QUESTION FORM ------------------- question_form = QuestionForm() question_form.append(overview) # question_form.append(q1) question_form.append(q2) #--------------- CREATE HITs ------------------- HIT_num = hitNum for i in range(HIT_num): # max_assignments: how many replicas this HIT has mtc.create_hit(questions=question_form, max_assignments=maxAssignments, title=title, description=description, keywords=keywords, duration=60 * 60 * 10, reward=0.50)
def new_rate_hit(PIN_IMAGE_URL, PIN_IMAGE_TITLE, MACYS_IMAGE_URL, MACYS_IMAGE_TITLE): mtc = MTurkConnection(aws_access_key_id=AWS_ACCESS_KEY_ID, aws_secret_access_key=AWS_SECRET_ACCESS_KEY, host=HOST) if debug: print mtc.get_account_balance() title = 'Match these Pictures to Macy\'s Products' description = 'Look at this photo and match it to Macy\'s products' keywords = 'clothing, rating, opinions, easy, quick, macys' ratings = [('Very Bad', '1'), ('Bad', '2'), ('OK', '3'), ('Good', '4'), ('Very Good', '5')] #make overview overview = Overview() overview.append_field('Title', 'Rank how these two images match.') overview.append( FormattedContent('<table border="1">><tr><td width="50%"><img src="' + PIN_IMAGE_URL + '" alt="Pintrest Image" /></td>' '<td width="50%"><img src="' + MACYS_IMAGE_URL + '" alt="Macys Image" /></td></tr><tr>' '<td width="50%">' + PIN_IMAGE_TITLE + '</td><td width="50%">' + MACYS_IMAGE_TITLE + '</td></tr></table>')) #make q1 qc1 = QuestionContent() qc1.append_field('Title', 'Rank the match between these two') fta1 = SelectionAnswer(min=1, max=1, style='dropdown', selections=ratings, type='text', other=False) q1 = Question(identifier='rating', content=qc1, answer_spec=AnswerSpecification(fta1), is_required=True) #make q2 qc2 = QuestionContent() qc2.append_field('Title', 'Comments about the HIT (Optional)') fta2 = FreeTextAnswer() q2 = Question(identifier="comments", content=qc2, answer_spec=AnswerSpecification(fta2)) #make question form question_form = QuestionForm() question_form.append(overview) question_form.append(q1) question_form.append(q2) #--------------- CREATE THE HIT ------------------- mtc.create_hit(questions=question_form, max_assignments=1, title=title, description=description, keywords=keywords, duration=60 * 5, reward=0.05)
def make_hit(image_url): title = 'Label image with its location' description = 'Answer questions about an image to label its location.' keywords = 'image categorization, locations, scene recognition' in_out = [('indoors', '0'), ('outdoors', '1')] nat_manmade = [('man-made', '0'), ('natural', '1')] functions = [('transportation/urban', '0'), ('restaurant', '1'), ('recreation', '2'), ('domestic', '3'), ('work/education', '4'), ('other/unclear', '5')] landscapes = [('body of water/beach', '0'), ('field', '1'), ('mountain', '2'), ('forest/jungle', '3'), ('other/unclear', '4')] #--------------- BUILD OVERVIEW ------------------- overview = Overview() overview.append_field('Title', title) with open(INSTRUCTIONS_HTML) as html: instructions = html.read() overview.append(FormattedContent(instructions)) image = Binary('image', None, image_url, 'image') overview.append(image) #--------------- BUILD QUESTION 1 ------------------- qc1 = QuestionContent() qc1.append_field( 'Text', 'Is the location shown in the image indoors or outdoors?') fta1 = SelectionAnswer(min=1, max=1, style='checkbox', selections=in_out, type='text', other=False) q1 = Question(identifier='Question 1', content=qc1, answer_spec=AnswerSpecification(fta1), is_required=True) #--------------- BUILD QUESTION 2 ------------------- qc2 = QuestionContent() qc2.append_field( 'Text', 'Is the location shown in the image man-made or ' + 'natural? Examples of man-made locations include ' + 'buildings and parks while examples of natural ' + 'locations include mountains and rivers.') fta2 = SelectionAnswer(min=1, max=1, style='checkbox', selections=nat_manmade, type='text', other=False) q2 = Question(identifier='Question 2', content=qc2, answer_spec=AnswerSpecification(fta2), is_required=True) #--------------- BUILD QUESTION 3 ------------------- qc3 = QuestionContent() qc3.append_field( 'Text', 'If the location in the image is man-made, what is the ' + 'general function or type of the location? If the ' + 'location is natural (not man-made), don\'t select ' + 'anything here.') fta3 = SelectionAnswer(min=0, max=1, style='checkbox', selections=functions, type='text', other=False) q3 = Question(identifier='Question 3', content=qc3, answer_spec=AnswerSpecification(fta3), is_required=False) #--------------- BUILD QUESTION 4 ------------------- qc4 = QuestionContent() qc4.append_field( 'Text', 'If the location in the picture is natural, what ' + 'kind of natural location is it? If the location ' + 'man-made (not natural), don\'t select anything here.') fta4 = SelectionAnswer(min=0, max=1, style='checkbox', selections=landscapes, type='text', other=False) q4 = Question(identifier='Question 4', content=qc4, answer_spec=AnswerSpecification(fta4), is_required=False) #--------------- BUILD THE QUESTION FORM ------------------- question_form = QuestionForm() question_form.append(overview) question_form.append(q1) question_form.append(q2) question_form.append(q3) question_form.append(q4) #-------------- QUALIFICATIONS ------------------- percent = PercentAssignmentsApprovedRequirement('GreaterThanOrEqualTo', 95) number = NumberHitsApprovedRequirement('GreaterThanOrEqualTo', 200) quals = Qualifications() quals.add(percent) quals.add(number) #--------------- CREATE THE HIT ------------------- mtc.create_hit(questions=question_form, max_assignments=1, title=title, description=description, keywords=keywords, qualifications=quals, annotation=image_url, duration=60 * 10, reward=0.03)
title = 'Give your opinion about categorizing shopping items' description = ('Visit a website and mark the categories' ' that you think are relevant about the product shown to you') keywords = 'categorization, amazon shopping, rating' ratings = [('Very Bad', '-2'), ('Bad', '-1'), ('Not bad', '0'), ('Good', '1'), ('Very Good', '1')] #--------------- BUILD OVERVIEW ------------------- overview = Overview() overview.append_field('Title', 'Give your opinion on this website') overview.append( FormattedContent('<a target="_blank"' ' href="http://www.toforge.com">' ' Mauro Rocco Personal Forge</a>')) #--------------- BUILD QUESTION 1 ------------------- qc1 = QuestionContent() qc1.append_field('Title', 'How looks the design ?') fta1 = SelectionAnswer(min=1, max=1, style='dropdown', selections=ratings, type='text', other=False) q1 = Question(identifier='design',
def generate_hits(mtc_type, subset, begin_index, args): from boto.mturk.connection import MTurkConnection from boto.mturk.question import QuestionContent, Question, QuestionForm, Overview, AnswerSpecification, SelectionAnswer, FormattedContent, FreeTextAnswer from boto.mturk.qualification import PercentAssignmentsApprovedRequirement, Qualifications, Requirement mtc = mtk_utils.get_mtc(mtc_type) title = 'Give your opinion of aesthetics level about images' description = ('View images and give us your opinion of aesthetics level about the images') keywords = 'image, aesthetic, aesthetics, rating, opinions' ratings =[('Very ugly','-2'), ('Ugly','-1'), ('Neutral','0'), ('Beautiful','1'), ('Very beautiful, I would like to take such beautiful photo too.','2')] #--------------- BUILD OVERVIEW ------------------- overview = Overview() overview.append_field('Title', 'Give your opinion about aesthetics level on those images') #--------------- BUILD QUESTIONs ------------------- questions = [] if (args.m != 'qua'): utils.write_file(subset, args.o + '.index_' + str(begin_index) + '.txt') if (args.m == 'qua_init' and begin_index > 0): return for image_url in subset: qc = QuestionContent() qc.append_field('Title','How beautiful the image to you?') qc.append(FormattedContent('<img src="' + image_url + '" alt="image" />')) fta = SelectionAnswer(min=1, max=1,style='dropdown', selections=ratings, type='text', other=False) q = Question(identifier='aesthetics', content=qc, answer_spec=AnswerSpecification(fta), is_required=True) questions.append(q) #--------------- BUILD THE QUESTION FORM ------------------- question_form = QuestionForm() question_form.append(overview) for question in questions: question_form.append(question) # BUILD QUALIFICATION qualifications = Qualifications() req = PercentAssignmentsApprovedRequirement(comparator = "GreaterThan", integer_value = "95") qualifications.add(req) if (args.m == 'qua'): if (args.q != None): qua_req = Requirement(qualification_type_id = args.q, comparator = 'EqualTo', integer_value = '1') qualifications.add(qua_req) else: print("Please give qualification type id in 'qua' mode.") sys.exit(0) #--------------- CREATE THE HIT ------------------- hit = mtc.create_hit(questions = question_form, qualifications = qualifications, max_assignments = 10 * 2, title = title, description = description, keywords = keywords, duration = 60 * 30 * 2, reward = 0.2 * 2) if (args.m == 'qua_init'): print("Create qualification type for HIT id: " + hit[0].HITId) quatype = mtc.create_qualification_type(name = hit[0].HITId, description = "Temporary qualification for HIT " + hit[0].HITId, status = 'Active') print("Qualification type id: " + quatype[0].QualificationTypeId)
def new_sugg_hit(PIN_IMAGE_URL, PIN_IMAGE_TITLE): mtc = MTurkConnection(aws_access_key_id=AWS_ACCESS_KEY_ID, aws_secret_access_key=AWS_SECRET_ACCESS_KEY, host=HOST) if debug: print mtc.get_account_balance() title = 'Match these Pictures to Macy\'s Products' description = 'Look at this photo and match it to Macy\'s products' keywords = 'clothing, rating, opinions, easy, quick, macys' #make overview overview = Overview() overview.append_field('Title', 'Find three Macys.com Product Web IDs That Match') overview.append( FormattedContent('<img src="' + PIN_IMAGE_URL + '" alt="Pintrest Image" />' '<br />' + PIN_IMAGE_TITLE)) #make webid1 qc1 = QuestionContent() qc1.append_field('Title', 'First WebID Code') fta1 = FreeTextAnswer(num_lines=1) q1 = Question(identifier="FirstWebCode", content=qc1, answer_spec=AnswerSpecification(fta1)) #make webid2 qc2 = QuestionContent() qc2.append_field('Title', 'Second WebID Code') fta2 = FreeTextAnswer(num_lines=1) q2 = Question(identifier="SecondWebCode", content=qc2, answer_spec=AnswerSpecification(fta2)) #make webid1 qc3 = QuestionContent() qc3.append_field('Title', 'Third WebID Code') fta3 = FreeTextAnswer(num_lines=1) q3 = Question(identifier="ThirdWebCode", content=qc3, answer_spec=AnswerSpecification(fta3)) #make question form question_form = QuestionForm() question_form.append(overview) question_form.append(q1) question_form.append(q2) question_form.append(q3) #--------------- CREATE THE HIT ------------------- mtc.create_hit(questions=question_form, max_assignments=1, title=title, description=description, keywords=keywords, duration=60 * 5, reward=0.05)