Kang Suhyun suhyun.kang commited on
Commit
4b31650
1 Parent(s): f00b7ff

[#5] Hide voting buttons until responses are displayed (#14)

Browse files

* [#5] Hide voting buttons until responses are displayed

Changes:
- Displayed the voting buttons only after the user has seen the full responses.

Screenshots:
- While the responses are being displayed: https://screen.yanolja.in/WJqqiGduLdAFssPT.png
- After the responses are displayed: https://screen.yanolja.in/LSD0wNpARLY3ELTB.png

* apply code review

* fix

---------

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

Files changed (2) hide show
  1. app.py +2 -3
  2. response.py +15 -3
app.py CHANGED
@@ -133,8 +133,7 @@ with gr.Blocks(title="Arena") as app:
133
  model_names[0] = gr.Textbox(show_label=False)
134
  model_names[1] = gr.Textbox(show_label=False)
135
 
136
- # TODO(#5): Display it only after the user submits the prompt.
137
- with gr.Row():
138
  option_a = gr.Button(VoteOptions.MODEL_A.value)
139
  option_b = gr.Button(VoteOptions.MODEL_B.value)
140
  tie = gr.Button(VoteOptions.TIE.value)
@@ -145,7 +144,7 @@ with gr.Blocks(title="Arena") as app:
145
  submit.click(
146
  get_responses, [prompt, category_radio, source_language, target_language],
147
  response_boxes + model_names + vote_buttons +
148
- [instruction_state, model_name_row])
149
 
150
  common_inputs = response_boxes + model_names + [
151
  prompt, instruction_state, category_radio, source_language,
 
133
  model_names[0] = gr.Textbox(show_label=False)
134
  model_names[1] = gr.Textbox(show_label=False)
135
 
136
+ with gr.Row(visible=False) as vote_row:
 
137
  option_a = gr.Button(VoteOptions.MODEL_A.value)
138
  option_b = gr.Button(VoteOptions.MODEL_B.value)
139
  tie = gr.Button(VoteOptions.TIE.value)
 
144
  submit.click(
145
  get_responses, [prompt, category_radio, source_language, target_language],
146
  response_boxes + model_names + vote_buttons +
147
+ [instruction_state, model_name_row, vote_row])
148
 
149
  common_inputs = response_boxes + model_names + [
150
  prompt, instruction_state, category_radio, source_language,
response.py CHANGED
@@ -49,6 +49,8 @@ def get_responses(user_prompt, category, source_lang, target_lang):
49
 
50
  models = sample(SUPPORTED_MODELS, 2)
51
  instruction = get_instruction(category, source_lang, target_lang)
 
 
52
 
53
  generators = []
54
  for model in models:
@@ -86,9 +88,12 @@ def get_responses(user_prompt, category, source_lang, target_lang):
86
  responses[i] += yielded
87
  stop = False
88
 
89
- yield responses + models + [
90
- gr.Button(interactive=True) for _ in range(3)
91
- ] + [instruction, gr.Row(visible=False)]
 
 
 
92
 
93
  except StopIteration:
94
  pass
@@ -100,3 +105,10 @@ def get_responses(user_prompt, category, source_lang, target_lang):
100
 
101
  if stop:
102
  break
 
 
 
 
 
 
 
 
49
 
50
  models = sample(SUPPORTED_MODELS, 2)
51
  instruction = get_instruction(category, source_lang, target_lang)
52
+ activated_vote_buttons = [gr.Button(interactive=True) for _ in range(3)]
53
+ deactivated_vote_buttons = [gr.Button(interactive=False) for _ in range(3)]
54
 
55
  generators = []
56
  for model in models:
 
88
  responses[i] += yielded
89
  stop = False
90
 
91
+ # model_name_row and vote_row are hidden during response generation.
92
+ yield responses + models + deactivated_vote_buttons + [
93
+ instruction,
94
+ gr.Row(visible=False),
95
+ gr.Row(visible=False)
96
+ ]
97
 
98
  except StopIteration:
99
  pass
 
105
 
106
  if stop:
107
  break
108
+
109
+ # After generating the response, the vote_row should become visible,
110
+ # while the model_name_row should remain hidden.
111
+ yield responses + models + activated_vote_buttons + [
112
+ instruction, gr.Row(visible=False),
113
+ gr.Row(visible=True)
114
+ ]