Spaces:
Runtime error
Runtime error
sedrickkeh
commited on
Commit
•
34ac887
1
Parent(s):
5a72dbb
add start_instructions
Browse files
app.py
CHANGED
@@ -107,12 +107,12 @@ def ask_a_question(input, taskid, gs):
|
|
107 |
if top_prob > 0.8 or len(gs.history) > 19:
|
108 |
html += f"<p>The model identified <b>Image {top_pred+1}</b> as the image. Please select a new task ID to continue.</p>"
|
109 |
finish_html = "<h2>Congratulations on finishing the game! Please copy the Task Finish Code below to MTurk to complete your task. You can now exit this window.</h2>"
|
110 |
-
return html, gs, gr.Dropdown.update(visible=False), gr.Button.update(visible=False), gr.Button.update(visible=False), gr.Button.update(visible=False), gr.Number.update(visible=False), gr.Button.update(visible=False), gr.Number.update(visible=False), gr.Button.update(visible=False), gr.Textbox.update(value=get_code(taskid, gs.history, top_pred), visible=True), gr.HTML.update(value=finish_html, visible=True)
|
111 |
else:
|
112 |
if not gs.yn:
|
113 |
-
return html, gs, gr.Dropdown.update(visible=True, value=''), gr.Button.update(visible=True), gr.Button.update(visible=True), gr.Button.update(visible=True), gr.Number.update(visible=False), gr.Button.update(visible=False), gr.Number.update(visible=False), gr.Button.update(visible=False), gr.Textbox.update(visible=False), gr.HTML.update(visible=False)
|
114 |
else:
|
115 |
-
return html, gs, gr.Dropdown.update(visible=False), gr.Button.update(visible=False), gr.Button.update(visible=False), gr.Button.update(visible=False), gr.Number.update(visible=False), gr.Button.update(visible=False), gr.Number.update(visible=True), gr.Button.update(visible=True), gr.Textbox.update(visible=False), gr.HTML.update(visible=False)
|
116 |
|
117 |
|
118 |
def set_images(taskid):
|
@@ -150,9 +150,9 @@ def set_images(taskid):
|
|
150 |
gs.history.append(first_question)
|
151 |
# html = f"<p>Current Task ID: <b>{int(taskid_original)}</b></p>"
|
152 |
if not gs.yn:
|
153 |
-
return id1, id1, id2, id3, id4, id5, id6, id7, id8, id9, id10, gs, first_question_html, gr.Dropdown.update(visible=True, value=''), gr.Button.update(visible=True), gr.Button.update(visible=True), gr.Button.update(visible=True), gr.Number.update(visible=False), gr.Button.update(visible=False), gr.Button.update(visible=False), gr.Button.update(visible=False)
|
154 |
else:
|
155 |
-
return id1, id1, id2, id3, id4, id5, id6, id7, id8, id9, id10, gs, first_question_html, gr.Dropdown.update(visible=False), gr.Button.update(visible=False), gr.Button.update(visible=False), gr.Button.update(visible=False), gr.Number.update(visible=False), gr.Button.update(visible=False), gr.Button.update(visible=True), gr.Button.update(visible=True)
|
156 |
|
157 |
def reset_dropdown():
|
158 |
return gr.Dropdown.update(visible=True, value='')
|
@@ -178,6 +178,9 @@ with gr.Blocks(title="Image Q&A Guessing Game", css=css) as demo:
|
|
178 |
with gr.Column():
|
179 |
with gr.Row():
|
180 |
taskid = gr.Number(label="Task ID (Enter a number from 0 to 160)", visible=False)
|
|
|
|
|
|
|
181 |
start_button = gr.Button("Start")
|
182 |
|
183 |
with gr.Column() as img_block:
|
@@ -231,11 +234,11 @@ with gr.Blocks(title="Image Q&A Guessing Game", css=css) as demo:
|
|
231 |
img0 = gr.Image(label="Image 1", show_label=True).style(height=700, width=700)
|
232 |
|
233 |
### Button click events
|
234 |
-
start_button.click(fn=set_images, inputs=taskid, outputs=[img0, img1, img2, img3, img4, img5, img6, img7, img8, img9, img10, game_session_state, conversation, answer, na_box, clear_box, submit, taskid, start_button, yes_box, no_box])
|
235 |
-
submit.click(fn=ask_a_question, inputs=[answer, taskid, game_session_state], outputs=[conversation, game_session_state, answer, na_box, clear_box, submit, taskid, start_button, yes_box, no_box, reward_code, vocab_warning])
|
236 |
-
na_box.click(fn=ask_a_question, inputs=[null_answer, taskid, game_session_state], outputs=[conversation, game_session_state, answer, na_box, clear_box, submit, taskid, start_button, yes_box, no_box, reward_code, vocab_warning])
|
237 |
-
yes_box.click(fn=ask_a_question, inputs=[yes_answer, taskid, game_session_state], outputs=[conversation, game_session_state, answer, na_box, clear_box, submit, taskid, start_button, yes_box, no_box, reward_code, vocab_warning])
|
238 |
-
no_box.click(fn=ask_a_question, inputs=[no_answer, taskid, game_session_state], outputs=[conversation, game_session_state, answer, na_box, clear_box, submit, taskid, start_button, yes_box, no_box, reward_code, vocab_warning])
|
239 |
clear_box.click(fn=reset_dropdown, inputs=[], outputs=[answer])
|
240 |
|
241 |
url_params = gr.JSON({}, visible=False, label="URL Params")
|
|
|
107 |
if top_prob > 0.8 or len(gs.history) > 19:
|
108 |
html += f"<p>The model identified <b>Image {top_pred+1}</b> as the image. Please select a new task ID to continue.</p>"
|
109 |
finish_html = "<h2>Congratulations on finishing the game! Please copy the Task Finish Code below to MTurk to complete your task. You can now exit this window.</h2>"
|
110 |
+
return html, gs, gr.Dropdown.update(visible=False), gr.Button.update(visible=False), gr.Button.update(visible=False), gr.Button.update(visible=False), gr.Number.update(visible=False), gr.HTML.update(visible=False), gr.Button.update(visible=False), gr.Number.update(visible=False), gr.Button.update(visible=False), gr.Textbox.update(value=get_code(taskid, gs.history, top_pred), visible=True), gr.HTML.update(value=finish_html, visible=True)
|
111 |
else:
|
112 |
if not gs.yn:
|
113 |
+
return html, gs, gr.Dropdown.update(visible=True, value=''), gr.Button.update(visible=True), gr.Button.update(visible=True), gr.Button.update(visible=True), gr.Number.update(visible=False), gr.HTML.update(visible=False), gr.Button.update(visible=False), gr.Number.update(visible=False), gr.Button.update(visible=False), gr.Textbox.update(visible=False), gr.HTML.update(visible=False)
|
114 |
else:
|
115 |
+
return html, gs, gr.Dropdown.update(visible=False), gr.Button.update(visible=False), gr.Button.update(visible=False), gr.Button.update(visible=False), gr.Number.update(visible=False), gr.HTML.update(visible=False), gr.Button.update(visible=False), gr.Number.update(visible=True), gr.Button.update(visible=True), gr.Textbox.update(visible=False), gr.HTML.update(visible=False)
|
116 |
|
117 |
|
118 |
def set_images(taskid):
|
|
|
150 |
gs.history.append(first_question)
|
151 |
# html = f"<p>Current Task ID: <b>{int(taskid_original)}</b></p>"
|
152 |
if not gs.yn:
|
153 |
+
return id1, id1, id2, id3, id4, id5, id6, id7, id8, id9, id10, gs, first_question_html, gr.Dropdown.update(visible=True, value=''), gr.Button.update(visible=True), gr.Button.update(visible=True), gr.Button.update(visible=True), gr.Number.update(visible=False), gr.HTML.update(visible=False), gr.Button.update(visible=False), gr.Button.update(visible=False), gr.Button.update(visible=False)
|
154 |
else:
|
155 |
+
return id1, id1, id2, id3, id4, id5, id6, id7, id8, id9, id10, gs, first_question_html, gr.Dropdown.update(visible=False), gr.Button.update(visible=False), gr.Button.update(visible=False), gr.Button.update(visible=False), gr.Number.update(visible=False), gr.HTML.update(visible=False), gr.Button.update(visible=False), gr.Button.update(visible=True), gr.Button.update(visible=True)
|
156 |
|
157 |
def reset_dropdown():
|
158 |
return gr.Dropdown.update(visible=True, value='')
|
|
|
178 |
with gr.Column():
|
179 |
with gr.Row():
|
180 |
taskid = gr.Number(label="Task ID (Enter a number from 0 to 160)", visible=False)
|
181 |
+
with gr.Row():
|
182 |
+
start_instruction = gr.HTML("<h2>Press the start button to begin.</h2>")
|
183 |
+
with gr.Row():
|
184 |
start_button = gr.Button("Start")
|
185 |
|
186 |
with gr.Column() as img_block:
|
|
|
234 |
img0 = gr.Image(label="Image 1", show_label=True).style(height=700, width=700)
|
235 |
|
236 |
### Button click events
|
237 |
+
start_button.click(fn=set_images, inputs=taskid, outputs=[img0, img1, img2, img3, img4, img5, img6, img7, img8, img9, img10, game_session_state, conversation, answer, na_box, clear_box, submit, taskid, start_instruction, start_button, yes_box, no_box])
|
238 |
+
submit.click(fn=ask_a_question, inputs=[answer, taskid, game_session_state], outputs=[conversation, game_session_state, answer, na_box, clear_box, submit, taskid, start_instruction, start_button, yes_box, no_box, reward_code, vocab_warning])
|
239 |
+
na_box.click(fn=ask_a_question, inputs=[null_answer, taskid, game_session_state], outputs=[conversation, game_session_state, answer, na_box, clear_box, submit, taskid, start_instruction, start_button, yes_box, no_box, reward_code, vocab_warning])
|
240 |
+
yes_box.click(fn=ask_a_question, inputs=[yes_answer, taskid, game_session_state], outputs=[conversation, game_session_state, answer, na_box, clear_box, submit, taskid, start_instruction, start_button, yes_box, no_box, reward_code, vocab_warning])
|
241 |
+
no_box.click(fn=ask_a_question, inputs=[no_answer, taskid, game_session_state], outputs=[conversation, game_session_state, answer, na_box, clear_box, submit, taskid, start_instruction, start_button, yes_box, no_box, reward_code, vocab_warning])
|
242 |
clear_box.click(fn=reset_dropdown, inputs=[], outputs=[answer])
|
243 |
|
244 |
url_params = gr.JSON({}, visible=False, label="URL Params")
|