Tristan Thrush commited on
Commit
963adc8
1 Parent(s): 29025ba

added bugfix for submit hit on huggingface.co

Browse files
Files changed (1) hide show
  1. app.py +13 -17
app.py CHANGED
@@ -94,17 +94,6 @@ with demo:
94
  jsonlfile.write(json.dumps(state) + "\n")
95
  repo.push_to_hub()
96
 
97
- if state["assignmentId"] == "":
98
- # If assignmentId is not set, then someone is using this app on
99
- # huggingface.co, and we can reset the app to it's initial state
100
- # after they submit their fake "HIT".
101
- state = {"assignmentId": "", "cnt": 0, "fooled": 0, "data": [], "metadata": {}}
102
- toggle_final_submit = gr.update(visible=False)
103
- toggle_example_submit = gr.update(visible=True)
104
- new_state_md = gr.Markdown(f"State: 0/{total_cnt} (0 fooled)")
105
-
106
- return state, toggle_final_submit, toggle_example_submit, new_state_md
107
-
108
  # Button event handlers
109
  get_window_location_search_js = """
110
  function(text_input, label_input, state, dummy) {
@@ -120,9 +109,10 @@ with demo:
120
  )
121
 
122
  post_hit_js = """
123
- function(state, toggle_final_submit, toggle_example_submit, new_state_md) {
124
- if (state["assignmentId"] !== "") {
125
- //It seems that someone is using this app on mturk, so submit the HIT.
 
126
  const form = document.createElement('form');
127
  form.action = 'https://workersandbox.mturk.com/mturk/externalSubmit';
128
  form.method = 'post';
@@ -131,19 +121,25 @@ with demo:
131
  hiddenField.type = 'hidden';
132
  hiddenField.name = key;
133
  hiddenField.value = state[key];
134
- form.appendChild(hiddenField)
135
  };
136
  document.body.appendChild(form);
137
  form.submit();
 
 
 
 
 
 
 
138
  }
139
- return [state];
140
  }
141
  """
142
 
143
  submit_hit_button.click(
144
  _store_in_huggingface_dataset,
145
  inputs=[state],
146
- outputs=[state, final_submit, example_submit, state_display],
147
  _js=post_hit_js,
148
  )
149
 
 
94
  jsonlfile.write(json.dumps(state) + "\n")
95
  repo.push_to_hub()
96
 
 
 
 
 
 
 
 
 
 
 
 
97
  # Button event handlers
98
  get_window_location_search_js = """
99
  function(text_input, label_input, state, dummy) {
 
109
  )
110
 
111
  post_hit_js = """
112
+ function(state) {
113
+ if (state["assignmentId"] !== ""){
114
+ // If there is an assignmentId, then the submitter is on mturk
115
+ // and we need to submit their HIT.
116
  const form = document.createElement('form');
117
  form.action = 'https://workersandbox.mturk.com/mturk/externalSubmit';
118
  form.method = 'post';
 
121
  hiddenField.type = 'hidden';
122
  hiddenField.name = key;
123
  hiddenField.value = state[key];
124
+ form.appendChild(hiddenField);
125
  };
126
  document.body.appendChild(form);
127
  form.submit();
128
+ return [state];
129
+ } else {
130
+ // If there is no assignmentId, then we assume that the submitter is
131
+ // on huggingface.co and we can't submit at HIT to mturk. But
132
+ // _store_in_huggingface_dataset will still store their example in
133
+ // our dataset without an assignmentId.
134
+ window.location.href = "https://huggingface.co/spaces/Tristan/dadc";
135
  }
 
136
  }
137
  """
138
 
139
  submit_hit_button.click(
140
  _store_in_huggingface_dataset,
141
  inputs=[state],
142
+ outputs=None,
143
  _js=post_hit_js,
144
  )
145