Spaces:
Running
Running
Kang Suhyun
commited on
Commit
•
60e8d65
1
Parent(s):
8a26fe6
[#75|#79] Reactivate Run button after an error is thrown (#80)
Browse files* [#79] Reactivate Run button after an error is thrown
This change reactivates the Run button after an error is thrown so that users can retry the run without having to refresh the page.
Screenshot: https://screen.yanolja.in/fx4IuOJowzWBRIaF.png
* Remove activate_button function and update submit_event.then
* Refactor UI elements and reset on category, source language, or target language change
app.py
CHANGED
@@ -68,10 +68,6 @@ def vote(vote_button, response_a, response_b, model_a_name, model_b_name,
|
|
68 |
raise gr.Error("Please select a response type.")
|
69 |
|
70 |
|
71 |
-
def activate_button():
|
72 |
-
return gr.Button(interactive=True)
|
73 |
-
|
74 |
-
|
75 |
# Removes the persistent orange border from the leaderboard, which
|
76 |
# appears due to the 'generating' class when using the 'every' parameter.
|
77 |
css = """
|
@@ -134,30 +130,55 @@ with gr.Blocks(title="Arena", css=css) as app:
|
|
134 |
option_b = gr.Button(VoteOptions.MODEL_B.value)
|
135 |
tie = gr.Button(VoteOptions.TIE.value)
|
136 |
|
137 |
-
vote_buttons = [option_a, option_b, tie]
|
138 |
instruction_state = gr.State("")
|
139 |
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
155 |
|
156 |
common_inputs = response_boxes + model_names + [
|
157 |
prompt, instruction_state, category_radio, source_language,
|
158 |
target_language
|
159 |
]
|
160 |
-
common_outputs =
|
161 |
option_a.click(vote, [option_a] + common_inputs, common_outputs)
|
162 |
option_b.click(vote, [option_b] + common_inputs, common_outputs)
|
163 |
tie.click(vote, [tie] + common_inputs, common_outputs)
|
|
|
68 |
raise gr.Error("Please select a response type.")
|
69 |
|
70 |
|
|
|
|
|
|
|
|
|
71 |
# Removes the persistent orange border from the leaderboard, which
|
72 |
# appears due to the 'generating' class when using the 'every' parameter.
|
73 |
css = """
|
|
|
130 |
option_b = gr.Button(VoteOptions.MODEL_B.value)
|
131 |
tie = gr.Button(VoteOptions.TIE.value)
|
132 |
|
|
|
133 |
instruction_state = gr.State("")
|
134 |
|
135 |
+
# The following elements need to be reset when the user changes
|
136 |
+
# the category, source language, or target language.
|
137 |
+
ui_elements = [
|
138 |
+
response_boxes[0], response_boxes[1], model_names[0], model_names[1],
|
139 |
+
instruction_state, model_name_row, vote_row
|
140 |
+
]
|
141 |
+
|
142 |
+
def reset_ui():
|
143 |
+
return [gr.Textbox(value="") for _ in range(4)
|
144 |
+
] + [gr.State(""),
|
145 |
+
gr.Row(visible=False),
|
146 |
+
gr.Row(visible=False)]
|
147 |
+
|
148 |
+
category_radio.change(fn=reset_ui, outputs=ui_elements)
|
149 |
+
source_language.change(fn=reset_ui, outputs=ui_elements)
|
150 |
+
target_language.change(fn=reset_ui, outputs=ui_elements)
|
151 |
+
|
152 |
+
submit_event = submit.click(
|
153 |
+
fn=lambda: [
|
154 |
+
gr.Radio(interactive=False),
|
155 |
+
gr.Dropdown(interactive=False),
|
156 |
+
gr.Dropdown(interactive=False),
|
157 |
+
gr.Button(interactive=False),
|
158 |
+
gr.Row(visible=False),
|
159 |
+
gr.Row(visible=False)
|
160 |
+
],
|
161 |
+
outputs=[
|
162 |
+
category_radio, source_language, target_language, submit, vote_row,
|
163 |
+
model_name_row
|
164 |
+
]).then(fn=get_responses,
|
165 |
+
inputs=[prompt, category_radio, source_language, target_language],
|
166 |
+
outputs=response_boxes + model_names + [instruction_state])
|
167 |
+
submit_event.success(fn=lambda: gr.Row(visible=True), outputs=vote_row)
|
168 |
+
submit_event.then(
|
169 |
+
fn=lambda: [
|
170 |
+
gr.Radio(interactive=True),
|
171 |
+
gr.Dropdown(interactive=True),
|
172 |
+
gr.Dropdown(interactive=True),
|
173 |
+
gr.Button(interactive=True)
|
174 |
+
],
|
175 |
+
outputs=[category_radio, source_language, target_language, submit])
|
176 |
|
177 |
common_inputs = response_boxes + model_names + [
|
178 |
prompt, instruction_state, category_radio, source_language,
|
179 |
target_language
|
180 |
]
|
181 |
+
common_outputs = [option_a, option_b, tie, model_name_row]
|
182 |
option_a.click(vote, [option_a] + common_inputs, common_outputs)
|
183 |
option_b.click(vote, [option_b] + common_inputs, common_outputs)
|
184 |
tie.click(vote, [tie] + common_inputs, common_outputs)
|