Kang Suhyun suhyun.kang commited on
Commit
a089fa0
1 Parent(s): f796553

[#6] Block vote when options are not set (#15)

Browse files

* [#6] Block vote when options are not set

Changes:
- Blocked voting when the response type is not set.
- Blocked voting when the response type is 'Translate' and the source/target languages are not set.
- Blocked voting when a user already voted.

* Fix

---------

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

Files changed (3) hide show
  1. app.py +22 -13
  2. requirements.txt +1 -1
  3. response.py +3 -1
app.py CHANGED
@@ -53,6 +53,8 @@ def vote(vote_button, response_a, response_b, model_a_name, model_b_name,
53
  doc_id = uuid4().hex
54
  winner = VoteOptions(vote_button).name.lower()
55
 
 
 
56
  doc = {
57
  "id": doc_id,
58
  "prompt": user_prompt,
@@ -68,14 +70,22 @@ def vote(vote_button, response_a, response_b, model_a_name, model_b_name,
68
  if category == response.Category.SUMMARIZE.value:
69
  doc_ref = db.collection("arena-summarizations").document(doc_id)
70
  doc_ref.set(doc)
71
- return
 
72
 
73
  if category == response.Category.TRANSLATE.value:
 
 
 
74
  doc_ref = db.collection("arena-translations").document(doc_id)
75
- doc["source_lang"] = source_lang.lower()
76
- doc["target_lang"] = target_lang.lower()
77
  doc_ref.set(doc)
78
 
 
 
 
 
79
 
80
  with gr.Blocks(title="Arena") as app:
81
  with gr.Row():
@@ -118,12 +128,10 @@ with gr.Blocks(title="Arena") as app:
118
  response_boxes[1] = gr.Textbox(label="Model B", interactive=False)
119
 
120
  # TODO(#5): Display it only after the user submits the prompt.
121
- # TODO(#6): Block voting if the category is not set.
122
- # TODO(#6): Block voting if the user already voted.
123
  with gr.Row():
124
  option_a = gr.Button(VoteOptions.MODEL_A.value)
125
- option_b = gr.Button("Model B is better")
126
- tie = gr.Button("Tie")
127
 
128
  # TODO(#7): Hide it until the user votes.
129
  with gr.Accordion("Show models", open=False):
@@ -131,19 +139,20 @@ with gr.Blocks(title="Arena") as app:
131
  model_names[0] = gr.Textbox(label="Model A", interactive=False)
132
  model_names[1] = gr.Textbox(label="Model B", interactive=False)
133
 
 
134
  instruction_state = gr.State("")
135
 
136
- submit.click(get_responses,
137
- [prompt, category_radio, source_language, target_language],
138
- response_boxes + model_names + [instruction_state])
139
 
140
  common_inputs = response_boxes + model_names + [
141
  prompt, instruction_state, category_radio, source_language,
142
  target_language
143
  ]
144
- option_a.click(vote, [option_a] + common_inputs)
145
- option_b.click(vote, [option_b] + common_inputs)
146
- tie.click(vote, [tie] + common_inputs)
147
 
148
  build_leaderboard(db)
149
 
 
53
  doc_id = uuid4().hex
54
  winner = VoteOptions(vote_button).name.lower()
55
 
56
+ deactivated_buttons = [gr.Button(interactive=False) for _ in range(3)]
57
+
58
  doc = {
59
  "id": doc_id,
60
  "prompt": user_prompt,
 
70
  if category == response.Category.SUMMARIZE.value:
71
  doc_ref = db.collection("arena-summarizations").document(doc_id)
72
  doc_ref.set(doc)
73
+
74
+ return deactivated_buttons
75
 
76
  if category == response.Category.TRANSLATE.value:
77
+ if not source_lang or not target_lang:
78
+ raise gr.Error("Please select source and target languages.")
79
+
80
  doc_ref = db.collection("arena-translations").document(doc_id)
81
+ doc["source_language"] = source_lang.lower()
82
+ doc["target_language"] = target_lang.lower()
83
  doc_ref.set(doc)
84
 
85
+ return deactivated_buttons
86
+
87
+ raise gr.Error("Please select a response type.")
88
+
89
 
90
  with gr.Blocks(title="Arena") as app:
91
  with gr.Row():
 
128
  response_boxes[1] = gr.Textbox(label="Model B", interactive=False)
129
 
130
  # TODO(#5): Display it only after the user submits the prompt.
 
 
131
  with gr.Row():
132
  option_a = gr.Button(VoteOptions.MODEL_A.value)
133
+ option_b = gr.Button(VoteOptions.MODEL_B.value)
134
+ tie = gr.Button(VoteOptions.TIE.value)
135
 
136
  # TODO(#7): Hide it until the user votes.
137
  with gr.Accordion("Show models", open=False):
 
139
  model_names[0] = gr.Textbox(label="Model A", interactive=False)
140
  model_names[1] = gr.Textbox(label="Model B", interactive=False)
141
 
142
+ vote_buttons = [option_a, option_b, tie]
143
  instruction_state = gr.State("")
144
 
145
+ submit.click(
146
+ get_responses, [prompt, category_radio, source_language, target_language],
147
+ response_boxes + model_names + vote_buttons + [instruction_state])
148
 
149
  common_inputs = response_boxes + model_names + [
150
  prompt, instruction_state, category_radio, source_language,
151
  target_language
152
  ]
153
+ option_a.click(vote, [option_a] + common_inputs, vote_buttons)
154
+ option_b.click(vote, [option_b] + common_inputs, vote_buttons)
155
+ tie.click(vote, [tie] + common_inputs, vote_buttons)
156
 
157
  build_leaderboard(db)
158
 
requirements.txt CHANGED
@@ -28,7 +28,7 @@ google-api-python-client==2.116.0
28
  google-auth==2.27.0
29
  google-auth-httplib2==0.2.0
30
  google-cloud-aiplatform==1.40.0
31
- google-cloud-bigquery==3.17.1
32
  google-cloud-core==2.4.1
33
  google-cloud-firestore==2.14.0
34
  google-cloud-resource-manager==1.12.0
 
28
  google-auth==2.27.0
29
  google-auth-httplib2==0.2.0
30
  google-cloud-aiplatform==1.40.0
31
+ google-cloud-bigquery==3.17.2
32
  google-cloud-core==2.4.1
33
  google-cloud-firestore==2.14.0
34
  google-cloud-resource-manager==1.12.0
response.py CHANGED
@@ -86,7 +86,9 @@ def get_responses(user_prompt, category, source_lang, target_lang):
86
  responses[i] += yielded
87
  stop = False
88
 
89
- yield responses + models + [instruction]
 
 
90
 
91
  except StopIteration:
92
  pass
 
86
  responses[i] += yielded
87
  stop = False
88
 
89
+ yield responses + models + [
90
+ gr.Button(interactive=True) for _ in range(3)
91
+ ] + [instruction]
92
 
93
  except StopIteration:
94
  pass