rwitz commited on
Commit
628ad2b
β€’
1 Parent(s): 975dcc0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -22
app.py CHANGED
@@ -128,12 +128,13 @@ def vote_up_model(state, chatbot, chatbot2, collection):
128
  update_message = update_ratings(state, 0, collection)
129
  chatbot.append(update_message[0])
130
  chatbot2.append(update_message[1])
131
- return chatbot, chatbot2,gr.Button.update(interactive=False),gr.Button.update(interactive=False),gr.Textbox.update(interactive=False),gr.Button.update(interactive=False) # Disable voting buttons
 
132
  def vote_down_model(state, chatbot, chatbot2, collection):
133
  update_message = update_ratings(state, 1, collection)
134
  chatbot2.append(update_message[0])
135
  chatbot.append(update_message[1])
136
- return chatbot,chatbot2, gr.Button.update(interactive=False),gr.Button.update(interactive=False),gr.Textbox.update(interactive=False),gr.Button.update(interactive=False) # Disable voting buttons
137
 
138
  async def user_ask(state, chatbot1, chatbot2, textbox):
139
  global enable_btn
@@ -180,43 +181,39 @@ def generate_leaderboard(collection):
180
  def refresh_leaderboard():
181
  return generate_leaderboard()
182
  # Gradio interface setup
 
183
  with gr.Blocks() as demo:
184
  state = gr.State({})
185
  with gr.Tab("Chatbot Arena"):
186
  with gr.Row():
187
  with gr.Column():
188
  chatbot1 = gr.Chatbot(label='Model A').style(height=600)
189
- upvote_btn_a = gr.Button(value="πŸ‘ Upvote A",interactive=False)
190
 
191
  with gr.Column():
192
  chatbot2 = gr.Chatbot(label='Model B').style(height=600)
193
- upvote_btn_b = gr.Button(value="πŸ‘ Upvote B",interactive=False)
194
 
195
- textbox = gr.Textbox(placeholder="Enter your prompt (up to 200 characters)", max_chars=200)
196
  with gr.Row():
197
  submit_btn = gr.Button(value="Send")
198
  reset_btn = gr.Button(value="Reset")
199
- reset_btn.click(clear_chat, inputs=[state], outputs=[state, chatbot1, chatbot2, upvote_btn_a, upvote_btn_b,textbox,submit_btn])
200
- textbox.submit(user_ask, inputs=[state, chatbot1, chatbot2, textbox], outputs=[state, chatbot1, chatbot2, textbox,upvote_btn_a,upvote_btn_b], queue=True)
201
- submit_btn.click(user_ask, inputs=[state, chatbot1, chatbot2, textbox], outputs=[state, chatbot1, chatbot2, textbox,upvote_btn_a,upvote_btn_b], queue=True)
202
- upvote_btn_a.click(vote_up_model, inputs=[state, chatbot1,chatbot2], outputs=[chatbot1,chatbot2,upvote_btn_a,upvote_btn_b,textbox,submit_btn])
203
- upvote_btn_b.click(vote_down_model, inputs=[state, chatbot1,chatbot2], outputs=[chatbot1,chatbot2,upvote_btn_a,upvote_btn_b,textbox,submit_btn])
 
 
 
204
  with gr.Tab("Leaderboard"):
205
  try:
206
- leaderboard = gr.Dataframe(refresh_leaderboard())
207
  except:
208
- leaderboard=gr.Dataframe(columns=['Chatbot', 'ELO Score', 'Games Played'])
209
  refresh_btn = gr.Button("Refresh Leaderboard")
 
210
 
211
- # Function to refresh leaderboard
212
-
213
-
214
- # Event handler for the refresh button
215
- refresh_btn.click(refresh_leaderboard, inputs=[], outputs=[leaderboard])
216
-
217
- # Launch the Gradio interface
218
  if __name__ == "__main__":
219
- collection = init_database()
220
- upvote_btn_a.click(vote_up_model, inputs=[state, chatbot1, chatbot2, collection], outputs=[chatbot1, chatbot2, upvote_btn_a, upvote_btn_b, textbox, submit_btn])
221
- upvote_btn_b.click(vote_down_model, inputs=[state, chatbot1, chatbot2, collection], outputs=[chatbot1, chatbot2, upvote_btn_a, upvote_btn_b, textbox, submit_btn])
222
  demo.launch(share=False)
 
128
  update_message = update_ratings(state, 0, collection)
129
  chatbot.append(update_message[0])
130
  chatbot2.append(update_message[1])
131
+ return chatbot, chatbot2, gr.Button.update(interactive=False), gr.Button.update(interactive=False), gr.Textbox.update(interactive=False), gr.Button.update(interactive=False)
132
+
133
  def vote_down_model(state, chatbot, chatbot2, collection):
134
  update_message = update_ratings(state, 1, collection)
135
  chatbot2.append(update_message[0])
136
  chatbot.append(update_message[1])
137
+ return chatbot, chatbot2, gr.Button.update(interactive=False), gr.Button.update(interactive=False), gr.Textbox.update(interactive=False), gr.Button.update(interactive=False)
138
 
139
  async def user_ask(state, chatbot1, chatbot2, textbox):
140
  global enable_btn
 
181
  def refresh_leaderboard():
182
  return generate_leaderboard()
183
  # Gradio interface setup
184
+ # Gradio interface setup
185
  with gr.Blocks() as demo:
186
  state = gr.State({})
187
  with gr.Tab("Chatbot Arena"):
188
  with gr.Row():
189
  with gr.Column():
190
  chatbot1 = gr.Chatbot(label='Model A').style(height=600)
191
+ upvote_btn_a = gr.Button(value="πŸ‘ Upvote A", interactive=False)
192
 
193
  with gr.Column():
194
  chatbot2 = gr.Chatbot(label='Model B').style(height=600)
195
+ upvote_btn_b = gr.Button(value="πŸ‘ Upvote B", interactive=False)
196
 
197
+ textbox = gr.Textbox(placeholder="Enter your prompt (up to 200 characters)")
198
  with gr.Row():
199
  submit_btn = gr.Button(value="Send")
200
  reset_btn = gr.Button(value="Reset")
201
+ reset_btn.click(clear_chat, inputs=[state], outputs=[state, chatbot1, chatbot2, upvote_btn_a, upvote_btn_b, textbox, submit_btn])
202
+ textbox.submit(user_ask, inputs=[state, chatbot1, chatbot2, textbox], outputs=[state, chatbot1, chatbot2, textbox, upvote_btn_a, upvote_btn_b], queue=True)
203
+ submit_btn.click(user_ask, inputs=[state, chatbot1, chatbot2, textbox], outputs=[state, chatbot1, chatbot2, textbox, upvote_btn_a, upvote_btn_b], queue=True)
204
+
205
+ collection = init_database()
206
+ upvote_btn_a.click(vote_up_model, inputs=[state, chatbot1, chatbot2, collection], outputs=[chatbot1, chatbot2, upvote_btn_a, upvote_btn_b, textbox, submit_btn])
207
+ upvote_btn_b.click(vote_down_model, inputs=[state, chatbot1, chatbot2, collection], outputs=[chatbot1, chatbot2, upvote_btn_a, upvote_btn_b, textbox, submit_btn])
208
+
209
  with gr.Tab("Leaderboard"):
210
  try:
211
+ leaderboard = gr.Dataframe(refresh_leaderboard(collection))
212
  except:
213
+ leaderboard = gr.Dataframe()
214
  refresh_btn = gr.Button("Refresh Leaderboard")
215
+ refresh_btn.click(refresh_leaderboard, inputs=[collection], outputs=[leaderboard])
216
 
217
+ # Launch the Gradio interface
 
 
 
 
 
 
218
  if __name__ == "__main__":
 
 
 
219
  demo.launch(share=False)