Kang Suhyun suhyun.kang commited on
Commit
3a85228
1 Parent(s): 50a5912

[#34] Block submission during response generation (#35)

Browse files

* [#34] Block submission during response generation

Changes
- Users cannot click the Run button while the response is being generated
- Component activation logic is moved from the response generation function to the Run button click handler

Screenshot: https://screen.yanolja.in/OkPOwEtERIM4NQro.png

* Remove unnecessary comments

* Add TODO

---------

Co-authored-by: suhyun.kang <suhyun.kang@yanolja.group>

Files changed (2) hide show
  1. app.py +15 -3
  2. response.py +3 -15
app.py CHANGED
@@ -139,9 +139,21 @@ with gr.Blocks(title="Arena") as app:
139
  instruction_state = gr.State("")
140
 
141
  submit.click(
142
- get_responses, [prompt, category_radio, source_language, target_language],
143
- response_boxes + model_names + vote_buttons +
144
- [instruction_state, model_name_row, vote_row])
 
 
 
 
 
 
 
 
 
 
 
 
145
 
146
  common_inputs = response_boxes + model_names + [
147
  prompt, instruction_state, category_radio, source_language,
 
139
  instruction_state = gr.State("")
140
 
141
  submit.click(
142
+ fn=get_responses,
143
+ inputs=[prompt, category_radio, source_language, target_language],
144
+ outputs=response_boxes + model_names + [instruction_state]).then(
145
+ fn=lambda: [gr.Button(interactive=True),
146
+ gr.Row(visible=True)
147
+ ] + [gr.Button(interactive=True) for _ in range(3)],
148
+ outputs=[submit, vote_row] + vote_buttons)
149
+
150
+ # TODO(#42): Hide vote buttons until response generation is successful.
151
+ submit.click(fn=lambda: [
152
+ gr.Button(interactive=False),
153
+ gr.Row(visible=False),
154
+ gr.Row(visible=False)
155
+ ],
156
+ outputs=[submit, vote_row, model_name_row])
157
 
158
  common_inputs = response_boxes + model_names + [
159
  prompt, instruction_state, category_radio, source_language,
response.py CHANGED
@@ -51,8 +51,6 @@ def get_responses(user_prompt, category, source_lang, target_lang):
51
 
52
  models = sample(list(supported_models), 2)
53
  instruction = get_instruction(category, source_lang, target_lang)
54
- activated_vote_buttons = [gr.Button(interactive=True) for _ in range(3)]
55
- deactivated_vote_buttons = [gr.Button(interactive=False) for _ in range(3)]
56
 
57
  responses = []
58
  for model in models:
@@ -85,16 +83,6 @@ def get_responses(user_prompt, category, source_lang, target_lang):
85
  # It simulates concurrent stream response generation.
86
  max_response_length = max(len(response) for response in responses)
87
  for i in range(max_response_length):
88
- yield [response[:i + 1] for response in responses
89
- ] + models + deactivated_vote_buttons + [
90
- instruction,
91
- gr.Row(visible=False),
92
- gr.Row(visible=False)
93
- ]
94
-
95
- # After generating the response, the vote_row should become visible,
96
- # while the model_name_row should remain hidden.
97
- yield responses + models + activated_vote_buttons + [
98
- instruction, gr.Row(visible=False),
99
- gr.Row(visible=True)
100
- ]
 
51
 
52
  models = sample(list(supported_models), 2)
53
  instruction = get_instruction(category, source_lang, target_lang)
 
 
54
 
55
  responses = []
56
  for model in models:
 
83
  # It simulates concurrent stream response generation.
84
  max_response_length = max(len(response) for response in responses)
85
  for i in range(max_response_length):
86
+ yield [response[:i + 1] for response in responses] + models + [instruction]
87
+
88
+ yield responses + models + [instruction]