Spaces:
Runtime error
Runtime error
Tristan Thrush
commited on
Commit
•
5a5a81e
1
Parent(s):
1d91315
storing hit in a way that will work for autoeval
Browse files
app.py
CHANGED
@@ -33,7 +33,7 @@ with demo:
|
|
33 |
dummy = gr.Textbox(visible=False) # dummy for passing assignmentId
|
34 |
|
35 |
# We keep track of state as a JSON
|
36 |
-
state_dict = {"assignmentId": "", "cnt": 0, "
|
37 |
state = gr.JSON(state_dict, visible=False)
|
38 |
|
39 |
gr.Markdown("# DADC in Gradio example")
|
@@ -50,12 +50,12 @@ with demo:
|
|
50 |
|
51 |
pred["label"] = pred["label"].title()
|
52 |
ret = f"Target: **{tgt}**. Model prediction: **{pred['label']}**\n\n"
|
53 |
-
|
54 |
-
|
55 |
ret += " You fooled the model! Well done!"
|
56 |
else:
|
57 |
ret += " You did not fool the model! Too bad, try again!"
|
58 |
-
state["data"].append(
|
59 |
state["cnt"] += 1
|
60 |
|
61 |
done = state["cnt"] == total_cnt
|
@@ -68,7 +68,7 @@ with demo:
|
|
68 |
# It seems that someone is using this app on mturk. We need to
|
69 |
# store the assignmentId in the state before submit_hit_button
|
70 |
# is clicked. We can do this here in _predict. We need to save the
|
71 |
-
# assignmentId so that the turker can get credit for their
|
72 |
state["assignmentId"] = query["assignmentId"][0]
|
73 |
|
74 |
return pred_confidences, ret, state, toggle_example_submit, toggle_final_submit, new_state_md, dummy
|
@@ -91,7 +91,9 @@ with demo:
|
|
91 |
# to automatically create a Hugging Face dataset from mturk.
|
92 |
def _store_in_huggingface_dataset(state):
|
93 |
with open(DATA_FILE, "a") as jsonlfile:
|
94 |
-
|
|
|
|
|
95 |
repo.push_to_hub()
|
96 |
return state
|
97 |
|
@@ -131,8 +133,8 @@ with demo:
|
|
131 |
// If there is no assignmentId, then we assume that the submitter is
|
132 |
// on huggingface.co and we can't submit a HIT to mturk. But
|
133 |
// _store_in_huggingface_dataset will still store their example in
|
134 |
-
// our dataset without an assignmentId.
|
135 |
-
//
|
136 |
window.location.href = window.location.href;
|
137 |
}
|
138 |
}
|
|
|
33 |
dummy = gr.Textbox(visible=False) # dummy for passing assignmentId
|
34 |
|
35 |
# We keep track of state as a JSON
|
36 |
+
state_dict = {"assignmentId": "", "cnt": 0, "data": []}
|
37 |
state = gr.JSON(state_dict, visible=False)
|
38 |
|
39 |
gr.Markdown("# DADC in Gradio example")
|
|
|
50 |
|
51 |
pred["label"] = pred["label"].title()
|
52 |
ret = f"Target: **{tgt}**. Model prediction: **{pred['label']}**\n\n"
|
53 |
+
fooled = pred["label"] != tgt
|
54 |
+
if fooled:
|
55 |
ret += " You fooled the model! Well done!"
|
56 |
else:
|
57 |
ret += " You did not fool the model! Too bad, try again!"
|
58 |
+
state["data"].append({"cnt": state["cnt"], "text": txt, "target": tgt, "model_pred": pred["label"], "fooled": fooled})
|
59 |
state["cnt"] += 1
|
60 |
|
61 |
done = state["cnt"] == total_cnt
|
|
|
68 |
# It seems that someone is using this app on mturk. We need to
|
69 |
# store the assignmentId in the state before submit_hit_button
|
70 |
# is clicked. We can do this here in _predict. We need to save the
|
71 |
+
# assignmentId so that the turker can get credit for their HIT.
|
72 |
state["assignmentId"] = query["assignmentId"][0]
|
73 |
|
74 |
return pred_confidences, ret, state, toggle_example_submit, toggle_final_submit, new_state_md, dummy
|
|
|
91 |
# to automatically create a Hugging Face dataset from mturk.
|
92 |
def _store_in_huggingface_dataset(state):
|
93 |
with open(DATA_FILE, "a") as jsonlfile:
|
94 |
+
json_data_with_assignment_id =\
|
95 |
+
[json.dumps(dict({"assignmentId": state["assignmentId"]}, **datum)) for datum in state["data"]]
|
96 |
+
jsonlfile.write("\n".join(json_data_with_assignment_id) + "\n")
|
97 |
repo.push_to_hub()
|
98 |
return state
|
99 |
|
|
|
133 |
// If there is no assignmentId, then we assume that the submitter is
|
134 |
// on huggingface.co and we can't submit a HIT to mturk. But
|
135 |
// _store_in_huggingface_dataset will still store their example in
|
136 |
+
// our dataset without an assignmentId. The following line here
|
137 |
+
// loads the app again so the user can enter in another "fake" HIT.
|
138 |
window.location.href = window.location.href;
|
139 |
}
|
140 |
}
|