Tristan Thrush commited on
Commit
f1da0cf
β€’
1 Parent(s): 0bdf8a4

revert assignment_id change, clean up a comment, fix turk qualifying test bug

Browse files
Files changed (2) hide show
  1. app.py +8 -8
  2. collect.py +3 -6
app.py CHANGED
@@ -95,12 +95,12 @@ model_id2model = {chatbot.llm.repo_id: chatbot for chatbot in chatbots}
95
  demo = gr.Blocks()
96
 
97
  with demo:
98
- dummy = gr.Textbox(visible=False) # dummy for passing assignment_id
99
 
100
  # We keep track of state as a JSON
101
  state_dict = {
102
  "conversation_id": str(uuid.uuid4()),
103
- "assignment_id": "",
104
  "cnt": 0, "data": [],
105
  "past_user_inputs": [],
106
  "generated_responses": [],
@@ -149,17 +149,17 @@ with demo:
149
  # submitted everything now.
150
  with open(DATA_FILE, "a") as jsonlfile:
151
  json_data_with_assignment_id =\
152
- [json.dumps(dict({"assignment_id": state["assignment_id"], "conversation_id": state["conversation_id"]}, **datum)) for datum in state["data"]]
153
  jsonlfile.write("\n".join(json_data_with_assignment_id) + "\n")
154
  toggle_example_submit = gr.update(visible=not done)
155
  past_conversation_string = "<br />".join(["<br />".join(["πŸ˜ƒ: " + user_input, "πŸ€–: " + model_response]) for user_input, model_response in zip(state["past_user_inputs"], state["generated_responses"])])
156
  query = parse_qs(dummy[1:])
157
- if "assignment_id" in query and query["assignment_id"][0] != "ASSIGNMENT_ID_NOT_AVAILABLE":
158
  # It seems that someone is using this app on mturk. We need to
159
- # store the assignment_id in the state before submit_hit_button
160
  # is clicked. We can do this here in _predict. We need to save the
161
- # assignment_id so that the turker can get credit for their HIT.
162
- state["assignment_id"] = query["assignment_id"][0]
163
  toggle_final_submit = gr.update(visible=done)
164
  toggle_final_submit_preview = gr.update(visible=False)
165
  else:
@@ -214,7 +214,7 @@ with demo:
214
 
215
  post_hit_js = """
216
  function(state) {
217
- // If there is an assignment_id, then the submitter is on mturk
218
  // and has accepted the HIT. So, we need to submit their HIT.
219
  const form = document.createElement('form');
220
  form.action = 'https://workersandbox.mturk.com/mturk/externalSubmit';
 
95
  demo = gr.Blocks()
96
 
97
  with demo:
98
+ dummy = gr.Textbox(visible=False) # dummy for passing assignmentId
99
 
100
  # We keep track of state as a JSON
101
  state_dict = {
102
  "conversation_id": str(uuid.uuid4()),
103
+ "assignmentId": "",
104
  "cnt": 0, "data": [],
105
  "past_user_inputs": [],
106
  "generated_responses": [],
 
149
  # submitted everything now.
150
  with open(DATA_FILE, "a") as jsonlfile:
151
  json_data_with_assignment_id =\
152
+ [json.dumps(dict({"assignmentId": state["assignmentId"], "conversation_id": state["conversation_id"]}, **datum)) for datum in state["data"]]
153
  jsonlfile.write("\n".join(json_data_with_assignment_id) + "\n")
154
  toggle_example_submit = gr.update(visible=not done)
155
  past_conversation_string = "<br />".join(["<br />".join(["πŸ˜ƒ: " + user_input, "πŸ€–: " + model_response]) for user_input, model_response in zip(state["past_user_inputs"], state["generated_responses"])])
156
  query = parse_qs(dummy[1:])
157
+ if "assignmentId" in query and query["assignmentId"][0] != "ASSIGNMENT_ID_NOT_AVAILABLE":
158
  # It seems that someone is using this app on mturk. We need to
159
+ # store the assignmentId in the state before submit_hit_button
160
  # is clicked. We can do this here in _predict. We need to save the
161
+ # assignmentId so that the turker can get credit for their HIT.
162
+ state["assignmentId"] = query["assignmentId"][0]
163
  toggle_final_submit = gr.update(visible=done)
164
  toggle_final_submit_preview = gr.update(visible=False)
165
  else:
 
214
 
215
  post_hit_js = """
216
  function(state) {
217
+ // If there is an assignmentId, then the submitter is on mturk
218
  // and has accepted the HIT. So, we need to submit their HIT.
219
  const form = document.createElement('form');
220
  form.action = 'https://workersandbox.mturk.com/mturk/externalSubmit';
collect.py CHANGED
@@ -1,6 +1,3 @@
1
- # Basic example for running MTurk data collection against a Space
2
- # For more information see https://docs.aws.amazon.com/mturk/index.html
3
-
4
  import boto3
5
  from boto.mturk.question import ExternalQuestion
6
 
@@ -45,11 +42,11 @@ question = ExternalQuestion(f"https://hf.space/embed/{args.space_name}/+?__theme
45
  qualification_type_id = open("qualification_type_id.txt", "r").read() if path.exists("qualification_type_id.txt") else None
46
  if args.refresh_qualification_test or qualification_type_id is None:
47
  if qualification_type_id is not None:
48
- client.delete_qualification_type(
49
- QualificationTypeId='string'
50
  )
51
  response = mturk.create_qualification_type(
52
- Name='rlhf-qualification',
53
  Keywords='RLHF qualification',
54
  Description='Qualification test for RLHF task.',
55
  QualificationTypeStatus='Active',
 
 
 
 
1
  import boto3
2
  from boto.mturk.question import ExternalQuestion
3
 
 
42
  qualification_type_id = open("qualification_type_id.txt", "r").read() if path.exists("qualification_type_id.txt") else None
43
  if args.refresh_qualification_test or qualification_type_id is None:
44
  if qualification_type_id is not None:
45
+ mturk.delete_qualification_type(
46
+ QualificationTypeId=qualification_type_id
47
  )
48
  response = mturk.create_qualification_type(
49
+ Name='rlhf--qualification',
50
  Keywords='RLHF qualification',
51
  Description='Qualification test for RLHF task.',
52
  QualificationTypeStatus='Active',