Pendrokar commited on
Commit
5de1947
β€’
1 Parent(s): e4da5b1

keyboard shortcuts

Browse files
Files changed (1) hide show
  1. app.py +43 -4
app.py CHANGED
@@ -1276,6 +1276,31 @@ def unblur_text():
1276
  return gr.update(elem_classes=[])
1277
 
1278
  unblur_js = 'document.getElementById("arena-text-input").classList.remove("blurred-text")'
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1279
 
1280
  with gr.Blocks() as vote:
1281
  session_hash = gr.Textbox(visible=False, value='')
@@ -1318,7 +1343,12 @@ with gr.Blocks() as vote:
1318
  waveform_options={'waveform_progress_color': '#EF4444'},
1319
  # var(--color-red-500)'}); gradio only accepts HEX and CSS color
1320
  )
1321
- abetter = gr.Button("A is better", variant='primary', interactive=False)
 
 
 
 
 
1322
  prevmodel1 = gr.HTML(show_label=False, value="Vote to reveal model A", visible=False)
1323
  with gr.Column():
1324
  with gr.Group():
@@ -1330,9 +1360,18 @@ with gr.Blocks() as vote:
1330
  waveform_options={'waveform_progress_color': '#3C82F6'},
1331
  # var(--secondary-500)'}); gradio only accepts HEX and CSS color
1332
  )
1333
- bbetter = gr.Button("B is better", variant='primary', interactive=False)
 
 
 
 
 
1334
  prevmodel2 = gr.HTML(show_label=False, value="Vote to reveal model B", visible=False)
1335
- nxtroundbtn = gr.Button('⚑ Next round', visible=False)
 
 
 
 
1336
  # outputs = [text, btn, r2, model1, model2, prevmodel1, aud1, prevmodel2, aud2, abetter, bbetter]
1337
  outputs = [
1338
  text,
@@ -1444,7 +1483,7 @@ with gr.Blocks() as about:
1444
  # ddb = gr.Button("Delete DB")
1445
  # ddb.click(del_db, inputs=dbtext, outputs=ddb)
1446
  # Blur cached sample text so the voting user picks up mispronouncements
1447
- with gr.Blocks(theme=theme, css="footer {visibility: hidden}textbox{resize:none} .blurred-text {filter: blur(0.15em);}", js="cookie.js", title="TTS Arena") as demo:
1448
  gr.Markdown(DESCR)
1449
  # gr.TabbedInterface([vote, leaderboard, about, admin], ['Vote', 'Leaderboard', 'About', 'Admin (ONLY IN BETA)'])
1450
  gr.TabbedInterface([vote, leaderboard, about], ['πŸ—³οΈ Vote', 'πŸ† Leaderboard', 'πŸ“„ About'])
 
1276
  return gr.update(elem_classes=[])
1277
 
1278
  unblur_js = 'document.getElementById("arena-text-input").classList.remove("blurred-text")'
1279
+ shortcut_js = """
1280
+ <script>
1281
+ function shortcuts(e) {
1282
+ var event = document.all ? window.event : e;
1283
+ switch (e.target.tagName.toLowerCase()) {
1284
+ case "input":
1285
+ case "textarea":
1286
+ break;
1287
+ default:
1288
+ switch (e.key.toLowerCase()) {
1289
+ case "a":
1290
+ document.getElementById("arena-a-better").click();
1291
+ break;
1292
+ case "b":
1293
+ document.getElementById("arena-b-better").click();
1294
+ break;
1295
+ case "n":
1296
+ document.getElementById("arena-next-round").click();
1297
+ break;
1298
+ }
1299
+ }
1300
+ }
1301
+ document.addEventListener('keypress', shortcuts, false);
1302
+ </script>
1303
+ """
1304
 
1305
  with gr.Blocks() as vote:
1306
  session_hash = gr.Textbox(visible=False, value='')
 
1343
  waveform_options={'waveform_progress_color': '#EF4444'},
1344
  # var(--color-red-500)'}); gradio only accepts HEX and CSS color
1345
  )
1346
+ abetter = gr.Button(
1347
+ "A is better [a]",
1348
+ elem_id='arena-a-better',
1349
+ variant='primary',
1350
+ interactive=False,
1351
+ )
1352
  prevmodel1 = gr.HTML(show_label=False, value="Vote to reveal model A", visible=False)
1353
  with gr.Column():
1354
  with gr.Group():
 
1360
  waveform_options={'waveform_progress_color': '#3C82F6'},
1361
  # var(--secondary-500)'}); gradio only accepts HEX and CSS color
1362
  )
1363
+ bbetter = gr.Button(
1364
+ "B is better [b]",
1365
+ elem_id='arena-b-better',
1366
+ variant='primary',
1367
+ interactive=False
1368
+ )
1369
  prevmodel2 = gr.HTML(show_label=False, value="Vote to reveal model B", visible=False)
1370
+ nxtroundbtn = gr.Button(
1371
+ '⚑ Next round [n]',
1372
+ elem_id='arena-next-round',
1373
+ visible=False
1374
+ )
1375
  # outputs = [text, btn, r2, model1, model2, prevmodel1, aud1, prevmodel2, aud2, abetter, bbetter]
1376
  outputs = [
1377
  text,
 
1483
  # ddb = gr.Button("Delete DB")
1484
  # ddb.click(del_db, inputs=dbtext, outputs=ddb)
1485
  # Blur cached sample text so the voting user picks up mispronouncements
1486
+ with gr.Blocks(theme=theme, css="footer {visibility: hidden}textbox{resize:none} .blurred-text {filter: blur(0.15em);}", head=shortcut_js, js="cookie.js", title="TTS Arena") as demo:
1487
  gr.Markdown(DESCR)
1488
  # gr.TabbedInterface([vote, leaderboard, about, admin], ['Vote', 'Leaderboard', 'About', 'Admin (ONLY IN BETA)'])
1489
  gr.TabbedInterface([vote, leaderboard, about], ['πŸ—³οΈ Vote', 'πŸ† Leaderboard', 'πŸ“„ About'])