Spaces:
Runtime error
Runtime error
Tristan Thrush
commited on
Commit
·
0b9ecb2
1
Parent(s):
5a5a81e
bugfix
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, "data": []}
|
| 37 |
state = gr.JSON(state_dict, visible=False)
|
| 38 |
|
| 39 |
gr.Markdown("# DADC in Gradio example")
|
|
@@ -52,6 +52,7 @@ with demo:
|
|
| 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!"
|
|
@@ -61,7 +62,7 @@ with demo:
|
|
| 61 |
done = state["cnt"] == total_cnt
|
| 62 |
toggle_final_submit = gr.update(visible=done)
|
| 63 |
toggle_example_submit = gr.update(visible=not done)
|
| 64 |
-
new_state_md = f"State: {state['cnt']}/{total_cnt} ({state['
|
| 65 |
|
| 66 |
query = parse_qs(dummy[1:])
|
| 67 |
if "assignmentId" in query:
|
|
|
|
| 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, "cnt_fooled": 0, "data": []}
|
| 37 |
state = gr.JSON(state_dict, visible=False)
|
| 38 |
|
| 39 |
gr.Markdown("# DADC in Gradio example")
|
|
|
|
| 52 |
ret = f"Target: **{tgt}**. Model prediction: **{pred['label']}**\n\n"
|
| 53 |
fooled = pred["label"] != tgt
|
| 54 |
if fooled:
|
| 55 |
+
state["cnt_fooled"] += 1
|
| 56 |
ret += " You fooled the model! Well done!"
|
| 57 |
else:
|
| 58 |
ret += " You did not fool the model! Too bad, try again!"
|
|
|
|
| 62 |
done = state["cnt"] == total_cnt
|
| 63 |
toggle_final_submit = gr.update(visible=done)
|
| 64 |
toggle_example_submit = gr.update(visible=not done)
|
| 65 |
+
new_state_md = f"State: {state['cnt']}/{total_cnt} ({state['cnt_fooled']} fooled)"
|
| 66 |
|
| 67 |
query = parse_qs(dummy[1:])
|
| 68 |
if "assignmentId" in query:
|