mrfakename commited on
Commit
433517c
1 Parent(s): 82bf73d

Username -> UUID

Browse files
Files changed (1) hide show
  1. app.py +28 -27
app.py CHANGED
@@ -7,6 +7,7 @@ import sqlite3
7
  from datasets import load_dataset
8
  import threading
9
  import time
 
10
  from pathlib import Path
11
  from huggingface_hub import CommitScheduler, delete_file, hf_hub_download
12
 
@@ -266,6 +267,9 @@ model_links = {
266
  # choice1 = get_random_split()
267
  # choice2 = get_random_split(choice1)
268
  # return (choice1, choice2)
 
 
 
269
  def upvote_model(model, uname):
270
  conn = get_db()
271
  cursor = conn.cursor()
@@ -288,33 +292,29 @@ def downvote_model(model, uname):
288
  conn.commit()
289
  cursor.close()
290
 
291
- def a_is_better(model1, model2, profile: gr.OAuthProfile | None):
292
- if not profile:
293
- raise gr.Error(MUST_BE_LOGGEDIN)
294
  if model1 and model2:
295
- upvote_model(model1, profile.username)
296
- downvote_model(model2, profile.username)
297
  return reload(model1, model2)
298
- def b_is_better(model1, model2, profile: gr.OAuthProfile | None):
299
- if not profile:
300
- raise gr.Error(MUST_BE_LOGGEDIN)
301
  if model1 and model2:
302
- upvote_model(model2, profile.username)
303
- downvote_model(model1, profile.username)
304
  return reload(model1, model2)
305
- def both_bad(model1, model2, profile: gr.OAuthProfile | None):
306
- if not profile:
307
- raise gr.Error(MUST_BE_LOGGEDIN)
308
  if model1 and model2:
309
- downvote_model(model1, profile.username)
310
- downvote_model(model2, profile.username)
311
  return reload(model1, model2)
312
- def both_good(model1, model2, profile: gr.OAuthProfile | None):
313
- if not profile:
314
- raise gr.Error(MUST_BE_LOGGEDIN)
315
  if model1 and model2:
316
- upvote_model(model1, profile.username)
317
- upvote_model(model2, profile.username)
318
  return reload(model1, model2)
319
  def reload(chosenmodel1=None, chosenmodel2=None):
320
  # Select random splits
@@ -346,8 +346,9 @@ with gr.Blocks() as leaderboard:
346
  gr.Markdown("DISCLAIMER: The licenses listed may not be accurate or up to date, you are responsible for checking the licenses before using the models. Also note that some models may have additional usage restrictions.")
347
 
348
  with gr.Blocks() as vote:
 
349
  gr.Markdown(INSTR)
350
- gr.LoginButton()
351
  with gr.Row():
352
  gr.HTML('<div align="left"><h3>Model A</h3></div>')
353
  gr.HTML('<div align="right"><h3>Model B</h3></div>')
@@ -380,13 +381,13 @@ with gr.Blocks() as vote:
380
  bothbad = gr.Button("Both are Bad", scale=2)
381
  skipbtn = gr.Button("Skip", scale=1)
382
  bothgood = gr.Button("Both are Good", scale=2)
383
- outputs = [aud1, aud2, model1, model2, prevmodel1, prevmodel2]
384
- abetter.click(a_is_better, outputs=outputs, inputs=[model1, model2])
385
- bbetter.click(b_is_better, outputs=outputs, inputs=[model1, model2])
386
- skipbtn.click(b_is_better, outputs=outputs, inputs=[model1, model2])
387
 
388
- bothbad.click(both_bad, outputs=outputs, inputs=[model1, model2])
389
- bothgood.click(both_good, outputs=outputs, inputs=[model1, model2])
390
 
391
  vote.load(reload, outputs=[aud1, aud2, model1, model2])
392
  with gr.Blocks() as about:
 
7
  from datasets import load_dataset
8
  import threading
9
  import time
10
+ import uuid
11
  from pathlib import Path
12
  from huggingface_hub import CommitScheduler, delete_file, hf_hub_download
13
 
 
267
  # choice1 = get_random_split()
268
  # choice2 = get_random_split(choice1)
269
  # return (choice1, choice2)
270
+ def mkuuid(uid):
271
+ if not uid:
272
+ uid = str(uuid.uuid4())
273
  def upvote_model(model, uname):
274
  conn = get_db()
275
  cursor = conn.cursor()
 
292
  conn.commit()
293
  cursor.close()
294
 
295
+ def a_is_better(model1, model2, userid):
296
+ mkuuid(userid)
 
297
  if model1 and model2:
298
+ upvote_model(model1, userid)
299
+ downvote_model(model2, userid)
300
  return reload(model1, model2)
301
+ def b_is_better(model1, model2, userid):
302
+ mkuuid(userid)
 
303
  if model1 and model2:
304
+ upvote_model(model2, userid)
305
+ downvote_model(model1, userid)
306
  return reload(model1, model2)
307
+ def both_bad(model1, model2, userid):
308
+ mkuuid(userid)
 
309
  if model1 and model2:
310
+ downvote_model(model1, userid)
311
+ downvote_model(model2, userid)
312
  return reload(model1, model2)
313
+ def both_good(model1, model2, userid):
314
+ mkuuid(userid)
 
315
  if model1 and model2:
316
+ upvote_model(model1, userid)
317
+ upvote_model(model2, userid)
318
  return reload(model1, model2)
319
  def reload(chosenmodel1=None, chosenmodel2=None):
320
  # Select random splits
 
346
  gr.Markdown("DISCLAIMER: The licenses listed may not be accurate or up to date, you are responsible for checking the licenses before using the models. Also note that some models may have additional usage restrictions.")
347
 
348
  with gr.Blocks() as vote:
349
+ userid = gr.State()
350
  gr.Markdown(INSTR)
351
+ # gr.LoginButton()
352
  with gr.Row():
353
  gr.HTML('<div align="left"><h3>Model A</h3></div>')
354
  gr.HTML('<div align="right"><h3>Model B</h3></div>')
 
381
  bothbad = gr.Button("Both are Bad", scale=2)
382
  skipbtn = gr.Button("Skip", scale=1)
383
  bothgood = gr.Button("Both are Good", scale=2)
384
+ outputs = [aud1, aud2, model1, model2, prevmodel1, prevmodel2, userid]
385
+ abetter.click(a_is_better, outputs=[outputs, userid], inputs=[model1, model2, userid])
386
+ bbetter.click(b_is_better, outputs=[outputs, userid], inputs=[model1, model2, userid])
387
+ skipbtn.click(b_is_better, outputs=[outputs, userid], inputs=[model1, model2, userid])
388
 
389
+ bothbad.click(both_bad, outputs=outputs, inputs=[model1, model2, userid])
390
+ bothgood.click(both_good, outputs=outputs, inputs=[model1, model2, userid])
391
 
392
  vote.load(reload, outputs=[aud1, aud2, model1, model2])
393
  with gr.Blocks() as about: