Kang Suhyun commited on
Commit
a9342b4
1 Parent(s): 43c8549

[#84] Block voting immediately after click and reactivate on rerun (#85)

Browse files

* [#84] Block voting immediately after click and reactivate on rerun

This change blocks voting immediately after a vote is cast and reactivates voting when the user reruns a prompt.

* apply code review

Files changed (1) hide show
  1. app.py +16 -11
app.py CHANGED
@@ -160,11 +160,11 @@ with gr.Blocks(title="Arena", css=css) as app:
160
  gr.Dropdown(interactive=False),
161
  gr.Button(interactive=False),
162
  gr.Row(visible=False),
163
- gr.Row(visible=False)
164
- ],
165
  outputs=[
166
  category_radio, source_language, target_language, submit, vote_row,
167
- model_name_row
168
  ]).then(fn=get_responses,
169
  inputs=[
170
  prompt_textarea, category_radio, source_language,
@@ -181,14 +181,19 @@ with gr.Blocks(title="Arena", css=css) as app:
181
  ],
182
  outputs=[category_radio, source_language, target_language, submit])
183
 
184
- common_inputs = response_boxes + model_names + [
185
- prompt_textarea, instruction_state, category_radio, source_language,
186
- target_language
187
- ]
188
- common_outputs = [option_a, option_b, tie, model_name_row]
189
- option_a.click(vote, [option_a] + common_inputs, common_outputs)
190
- option_b.click(vote, [option_b] + common_inputs, common_outputs)
191
- tie.click(vote, [tie] + common_inputs, common_outputs)
 
 
 
 
 
192
 
193
  build_leaderboard()
194
 
 
160
  gr.Dropdown(interactive=False),
161
  gr.Button(interactive=False),
162
  gr.Row(visible=False),
163
+ gr.Row(visible=False),
164
+ ] + [gr.Button(interactive=True) for _ in range(3)],
165
  outputs=[
166
  category_radio, source_language, target_language, submit, vote_row,
167
+ model_name_row, option_a, option_b, tie
168
  ]).then(fn=get_responses,
169
  inputs=[
170
  prompt_textarea, category_radio, source_language,
 
181
  ],
182
  outputs=[category_radio, source_language, target_language, submit])
183
 
184
+ def deactivate_after_voting(option_button: gr.Button):
185
+ option_button.click(
186
+ fn=vote,
187
+ inputs=[option_button] + response_boxes + model_names + [
188
+ prompt_textarea, instruction_state, category_radio, source_language,
189
+ target_language
190
+ ],
191
+ outputs=[option_a, option_b, tie, model_name_row]).then(
192
+ fn=lambda: [gr.Button(interactive=False) for _ in range(3)],
193
+ outputs=[option_a, option_b, tie])
194
+
195
+ for option in [option_a, option_b, tie]:
196
+ deactivate_after_voting(option)
197
 
198
  build_leaderboard()
199