Tristan Thrush commited on
Commit
fb34e92
1 Parent(s): 4047dab
Files changed (1) hide show
  1. app.py +8 -8
app.py CHANGED
@@ -35,17 +35,17 @@ with demo:
35
  pred["label"] = pred["label"].title()
36
  ret = f"Target: **{tgt}**. Model prediction: **{pred['label']}**\n\n"
37
  if pred["label"] != tgt:
38
- state.value["fooled"] += 1
39
  ret += " You fooled the model! Well done!"
40
  else:
41
  ret += " You did not fool the model! Too bad, try again!"
42
- state.value["data"].append(ret)
43
- state.value["cnt"] += 1
44
 
45
- done = state.value["cnt"] == total_cnt
46
  toggle_final_submit = gr.update(visible=done)
47
  toggle_example_submit = gr.update(visible=not done)
48
- new_state_md = f"State: {state.value['cnt']}/{total_cnt} ({state.value['fooled']} fooled)"
49
  return pred_confidences, ret, state, toggle_example_submit, toggle_final_submit, new_state_md
50
 
51
  # Input fields
@@ -65,10 +65,10 @@ with demo:
65
  def _submit(state, dummy):
66
  query = parse_qs(dummy[1:])
67
  assert "assignmentId" in query, "No assignment ID provided, unable to submit"
68
- state.value["assignmentId"] = query["assignmentId"]
69
  url = "https://workersandbox.mturk.com/mturk/externalSubmit"
70
- x = requests.post(url, data=state.value)
71
- return str(x) + " With assignmentId " + state.value["assignmentId"][0] + "\n" + x.text, state, dummy
72
 
73
  # Button event handlers
74
  submit_ex_button.click(
 
35
  pred["label"] = pred["label"].title()
36
  ret = f"Target: **{tgt}**. Model prediction: **{pred['label']}**\n\n"
37
  if pred["label"] != tgt:
38
+ state["fooled"] += 1
39
  ret += " You fooled the model! Well done!"
40
  else:
41
  ret += " You did not fool the model! Too bad, try again!"
42
+ state["data"].append(ret)
43
+ state["cnt"] += 1
44
 
45
+ done = state["cnt"] == total_cnt
46
  toggle_final_submit = gr.update(visible=done)
47
  toggle_example_submit = gr.update(visible=not done)
48
+ new_state_md = f"State: {state['cnt']}/{total_cnt} ({state['fooled']} fooled)"
49
  return pred_confidences, ret, state, toggle_example_submit, toggle_final_submit, new_state_md
50
 
51
  # Input fields
 
65
  def _submit(state, dummy):
66
  query = parse_qs(dummy[1:])
67
  assert "assignmentId" in query, "No assignment ID provided, unable to submit"
68
+ state["assignmentId"] = query["assignmentId"][0]
69
  url = "https://workersandbox.mturk.com/mturk/externalSubmit"
70
+ x = requests.post(url, data=state)
71
+ return str(x) + " With assignmentId " + state["assignmentId"] + "\n" + x.text, state, dummy
72
 
73
  # Button event handlers
74
  submit_ex_button.click(