Spaces:
Running
on
Zero
Running
on
Zero
autoplay checkbox & unlock vote
Browse files- app/synth.py +6 -6
- app/ui_battle.py +18 -2
- app/ui_vote.py +66 -15
app/synth.py
CHANGED
@@ -21,7 +21,7 @@ def check_toxicity(text):
|
|
21 |
return False
|
22 |
return toxicity.predict(text)['toxicity'] > 0.8
|
23 |
|
24 |
-
def synthandreturn(text, request: gr.Request):
|
25 |
text = text.strip()
|
26 |
if len(text) > MAX_SAMPLE_TXT_LENGTH:
|
27 |
raise gr.Error(f'You exceeded the limit of {MAX_SAMPLE_TXT_LENGTH} characters')
|
@@ -250,8 +250,8 @@ def synthandreturn(text, request: gr.Request):
|
|
250 |
gr.update(visible=True), # r2
|
251 |
mdl1, # model1
|
252 |
mdl2, # model2
|
253 |
-
gr.update(visible=True, value=results[mdl1k]), # aud1
|
254 |
-
gr.update(visible=True, value=results[mdl2k]), # aud2
|
255 |
gr.update(visible=True, interactive=False), #abetter
|
256 |
gr.update(visible=True, interactive=False), #bbetter
|
257 |
gr.update(visible=False), #prevmodel1
|
@@ -261,7 +261,7 @@ def synthandreturn(text, request: gr.Request):
|
|
261 |
|
262 |
# Battle Mode
|
263 |
|
264 |
-
def synthandreturn_battle(text, mdl1, mdl2):
|
265 |
if mdl1 == mdl2:
|
266 |
raise gr.Error('You can\'t pick two of the same models.')
|
267 |
text = text.strip()
|
@@ -346,8 +346,8 @@ def synthandreturn_battle(text, mdl1, mdl2):
|
|
346 |
gr.update(visible=True), # r2
|
347 |
mdl1, # model1
|
348 |
mdl2, # model2
|
349 |
-
gr.update(visible=True, value=results[mdl1k]), # aud1
|
350 |
-
gr.update(visible=True, value=results[mdl2k]), # aud2
|
351 |
gr.update(visible=True, interactive=False), #abetter
|
352 |
gr.update(visible=True, interactive=False), #bbetter
|
353 |
gr.update(visible=False), #prevmodel1
|
|
|
21 |
return False
|
22 |
return toxicity.predict(text)['toxicity'] > 0.8
|
23 |
|
24 |
+
def synthandreturn(text, autoplay, request: gr.Request):
|
25 |
text = text.strip()
|
26 |
if len(text) > MAX_SAMPLE_TXT_LENGTH:
|
27 |
raise gr.Error(f'You exceeded the limit of {MAX_SAMPLE_TXT_LENGTH} characters')
|
|
|
250 |
gr.update(visible=True), # r2
|
251 |
mdl1, # model1
|
252 |
mdl2, # model2
|
253 |
+
gr.update(visible=True, value=results[mdl1k], autoplay=autoplay), # aud1
|
254 |
+
gr.update(visible=True, value=results[mdl2k], autoplay=False), # aud2
|
255 |
gr.update(visible=True, interactive=False), #abetter
|
256 |
gr.update(visible=True, interactive=False), #bbetter
|
257 |
gr.update(visible=False), #prevmodel1
|
|
|
261 |
|
262 |
# Battle Mode
|
263 |
|
264 |
+
def synthandreturn_battle(text, mdl1, mdl2, autoplay):
|
265 |
if mdl1 == mdl2:
|
266 |
raise gr.Error('You can\'t pick two of the same models.')
|
267 |
text = text.strip()
|
|
|
346 |
gr.update(visible=True), # r2
|
347 |
mdl1, # model1
|
348 |
mdl2, # model2
|
349 |
+
gr.update(visible=True, value=results[mdl1k], autoplay=autoplay), # aud1
|
350 |
+
gr.update(visible=True, value=results[mdl2k], autoplay=False), # aud2
|
351 |
gr.update(visible=True, interactive=False), #abetter
|
352 |
gr.update(visible=True, interactive=False), #bbetter
|
353 |
gr.update(visible=False), #prevmodel1
|
app/ui_battle.py
CHANGED
@@ -13,7 +13,7 @@ def enable():
|
|
13 |
|
14 |
with gr.Blocks() as battle:
|
15 |
battle_useridstate = gr.State()
|
16 |
-
|
17 |
gr.Markdown(BATTLE_INSTR)
|
18 |
model1 = gr.Textbox(interactive=False, lines=1, max_lines=1, visible=False)
|
19 |
model2 = gr.Textbox(interactive=False, lines=1, max_lines=1, visible=False)
|
@@ -39,6 +39,11 @@ with gr.Blocks() as battle:
|
|
39 |
aud2 = gr.Audio(interactive=False, show_label=False, show_download_button=False, show_share_button=False)
|
40 |
bbetter = gr.Button("B is better", variant='primary')
|
41 |
prevmodel2 = gr.Textbox(interactive=False, show_label=False, container=False, value="Vote to reveal model B", text_align="center", lines=1, max_lines=1, visible=False)
|
|
|
|
|
|
|
|
|
|
|
42 |
outputs = [
|
43 |
text,
|
44 |
btn,
|
@@ -52,8 +57,19 @@ with gr.Blocks() as battle:
|
|
52 |
prevmodel1,
|
53 |
prevmodel2,
|
54 |
]
|
55 |
-
btn
|
|
|
|
|
|
|
56 |
nxt_outputs = [abetter, bbetter, prevmodel1, prevmodel2]
|
57 |
abetter.click(a_is_better_battle, outputs=nxt_outputs, inputs=[model1, model2, battle_useridstate])
|
58 |
bbetter.click(b_is_better_battle, outputs=nxt_outputs, inputs=[model1, model2, battle_useridstate])
|
59 |
battle.load(random_m, outputs=[model1s, model2s])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
with gr.Blocks() as battle:
|
15 |
battle_useridstate = gr.State()
|
16 |
+
|
17 |
gr.Markdown(BATTLE_INSTR)
|
18 |
model1 = gr.Textbox(interactive=False, lines=1, max_lines=1, visible=False)
|
19 |
model2 = gr.Textbox(interactive=False, lines=1, max_lines=1, visible=False)
|
|
|
39 |
aud2 = gr.Audio(interactive=False, show_label=False, show_download_button=False, show_share_button=False)
|
40 |
bbetter = gr.Button("B is better", variant='primary')
|
41 |
prevmodel2 = gr.Textbox(interactive=False, show_label=False, container=False, value="Vote to reveal model B", text_align="center", lines=1, max_lines=1, visible=False)
|
42 |
+
autoplay = gr.Checkbox(
|
43 |
+
label="Autoplay audio",
|
44 |
+
value=True
|
45 |
+
)
|
46 |
+
|
47 |
outputs = [
|
48 |
text,
|
49 |
btn,
|
|
|
57 |
prevmodel1,
|
58 |
prevmodel2,
|
59 |
]
|
60 |
+
btn\
|
61 |
+
.click(disable, outputs=[btn, abetter, bbetter])\
|
62 |
+
.then(synthandreturn_battle, inputs=[text, model1s, model2s, autoplay], outputs=outputs)\
|
63 |
+
.then(enable, outputs=[btn, abetter, bbetter])
|
64 |
nxt_outputs = [abetter, bbetter, prevmodel1, prevmodel2]
|
65 |
abetter.click(a_is_better_battle, outputs=nxt_outputs, inputs=[model1, model2, battle_useridstate])
|
66 |
bbetter.click(b_is_better_battle, outputs=nxt_outputs, inputs=[model1, model2, battle_useridstate])
|
67 |
battle.load(random_m, outputs=[model1s, model2s])
|
68 |
+
|
69 |
+
# Autoplay second audio using JS
|
70 |
+
aud1\
|
71 |
+
.stop(
|
72 |
+
None,
|
73 |
+
inputs=[autoplay],
|
74 |
+
js="(b) => b ? 0 : document.querySelector('.row .gap+.gap button.play-pause-button[aria-label=Play]').click()",
|
75 |
+
)
|
app/ui_vote.py
CHANGED
@@ -16,10 +16,27 @@ def blur_text():
|
|
16 |
def unblur_text():
|
17 |
return gr.update(elem_classes=[])
|
18 |
|
19 |
-
|
|
|
|
|
|
|
20 |
# sample played
|
21 |
-
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
# voter ID
|
24 |
useridstate = gr.State()
|
25 |
gr.Markdown(INSTR)
|
@@ -47,7 +64,14 @@ with gr.Blocks() as vote:
|
|
47 |
with gr.Row(visible=False) as r2:
|
48 |
with gr.Column():
|
49 |
with gr.Group():
|
50 |
-
aud1 = gr.Audio(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
abetter = gr.Button(
|
52 |
"[A] is better",
|
53 |
elem_id='arena-a-better',
|
@@ -57,7 +81,14 @@ with gr.Blocks() as vote:
|
|
57 |
prevmodel1 = gr.Textbox(interactive=False, show_label=False, container=False, value="Vote to reveal model A", text_align="center", lines=1, max_lines=1, visible=False)
|
58 |
with gr.Column():
|
59 |
with gr.Group():
|
60 |
-
aud2 = gr.Audio(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
bbetter = gr.Button(
|
62 |
"[B] is better",
|
63 |
elem_id='arena-b-better',
|
@@ -71,7 +102,11 @@ with gr.Blocks() as vote:
|
|
71 |
visible=False,
|
72 |
variant='primary',
|
73 |
)
|
74 |
-
|
|
|
|
|
|
|
|
|
75 |
outputs = [
|
76 |
text,
|
77 |
btn,
|
@@ -99,27 +134,43 @@ with gr.Blocks() as vote:
|
|
99 |
gr.update(visible=False), #prevmodel1
|
100 |
gr.update(visible=False), #prevmodel2
|
101 |
gr.update(visible=False), #nxt round btn"""
|
|
|
102 |
btn\
|
103 |
.click(disable, outputs=[btn, abetter, bbetter])\
|
104 |
-
.then(synthandreturn, inputs=[text], outputs=outputs)\
|
105 |
-
.then(enable, outputs=[btn,
|
106 |
.then(None, js="() => "+ unblur_text_js)
|
107 |
# Next Round ; blur text
|
108 |
nxtroundbtn\
|
109 |
.click(clear_stuff, outputs=outputs)\
|
110 |
.then(randomsent, outputs=[text, randomt])\
|
111 |
-
.then(synthandreturn, inputs=[text], outputs=outputs)\
|
112 |
-
.then(enable, outputs=[btn,
|
113 |
# blur text
|
114 |
nxtroundbtn.click(None, js="() => "+ blur_text_js)
|
115 |
|
116 |
# Allow interaction with the vote buttons only when both audio samples have finished playing
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
121 |
|
122 |
-
# nxt_outputs = [prevmodel1, prevmodel2, abetter, bbetter]
|
123 |
nxt_outputs = [abetter, bbetter, prevmodel1, prevmodel2, nxtroundbtn]
|
124 |
abetter.click(a_is_better, outputs=nxt_outputs, inputs=[model1, model2, useridstate])
|
125 |
bbetter.click(b_is_better, outputs=nxt_outputs, inputs=[model1, model2, useridstate])
|
|
|
16 |
def unblur_text():
|
17 |
return gr.update(elem_classes=[])
|
18 |
|
19 |
+
def unlock_vote(autoplay, btn_index, aplayed, bplayed):
|
20 |
+
if autoplay == False:
|
21 |
+
return [gr.update(), gr.update(), aplayed, bplayed]
|
22 |
+
|
23 |
# sample played
|
24 |
+
if btn_index == 0:
|
25 |
+
aplayed = True
|
26 |
+
if btn_index == 1:
|
27 |
+
bplayed = True
|
28 |
+
|
29 |
+
# both audio samples played
|
30 |
+
if bool(aplayed) and bool(bplayed):
|
31 |
+
# print('Both audio samples played, voting unlocked')
|
32 |
+
return [gr.update(interactive=True), gr.update(interactive=True), True, True]
|
33 |
+
|
34 |
+
return [gr.update(), gr.update(), aplayed, bplayed]
|
35 |
+
|
36 |
+
with gr.Blocks() as vote:
|
37 |
+
# sample played, using Checkbox so that JS can fetch the value
|
38 |
+
aplayed = gr.Checkbox(visible=False, value=False)
|
39 |
+
bplayed = gr.Checkbox(visible=False, value=False)
|
40 |
# voter ID
|
41 |
useridstate = gr.State()
|
42 |
gr.Markdown(INSTR)
|
|
|
64 |
with gr.Row(visible=False) as r2:
|
65 |
with gr.Column():
|
66 |
with gr.Group():
|
67 |
+
aud1 = gr.Audio(
|
68 |
+
interactive=False,
|
69 |
+
show_label=False,
|
70 |
+
show_download_button=False,
|
71 |
+
show_share_button=False,
|
72 |
+
# waveform_options={'waveform_progress_color': '#EF4444'},
|
73 |
+
# var(--color-red-500)'}); gradio only accepts HEX and CSS color
|
74 |
+
)
|
75 |
abetter = gr.Button(
|
76 |
"[A] is better",
|
77 |
elem_id='arena-a-better',
|
|
|
81 |
prevmodel1 = gr.Textbox(interactive=False, show_label=False, container=False, value="Vote to reveal model A", text_align="center", lines=1, max_lines=1, visible=False)
|
82 |
with gr.Column():
|
83 |
with gr.Group():
|
84 |
+
aud2 = gr.Audio(
|
85 |
+
interactive=False,
|
86 |
+
show_label=False,
|
87 |
+
show_download_button=False,
|
88 |
+
show_share_button=False,
|
89 |
+
waveform_options={'waveform_progress_color': '#3C82F6'},
|
90 |
+
# var(--secondary-500)'}); gradio only accepts HEX and CSS color
|
91 |
+
)
|
92 |
bbetter = gr.Button(
|
93 |
"[B] is better",
|
94 |
elem_id='arena-b-better',
|
|
|
102 |
visible=False,
|
103 |
variant='primary',
|
104 |
)
|
105 |
+
autoplay = gr.Checkbox(
|
106 |
+
label="Autoplay audio",
|
107 |
+
value=True
|
108 |
+
)
|
109 |
+
|
110 |
outputs = [
|
111 |
text,
|
112 |
btn,
|
|
|
134 |
gr.update(visible=False), #prevmodel1
|
135 |
gr.update(visible=False), #prevmodel2
|
136 |
gr.update(visible=False), #nxt round btn"""
|
137 |
+
# , concurrency_count=1, concurrency_id="sync_queue"
|
138 |
btn\
|
139 |
.click(disable, outputs=[btn, abetter, bbetter])\
|
140 |
+
.then(synthandreturn, inputs=[text, autoplay], outputs=outputs)\
|
141 |
+
.then(enable, outputs=[btn, gr.State(), gr.State()])\
|
142 |
.then(None, js="() => "+ unblur_text_js)
|
143 |
# Next Round ; blur text
|
144 |
nxtroundbtn\
|
145 |
.click(clear_stuff, outputs=outputs)\
|
146 |
.then(randomsent, outputs=[text, randomt])\
|
147 |
+
.then(synthandreturn, inputs=[text, autoplay], outputs=outputs)\
|
148 |
+
.then(enable, outputs=[btn, gr.State(), gr.State()])
|
149 |
# blur text
|
150 |
nxtroundbtn.click(None, js="() => "+ blur_text_js)
|
151 |
|
152 |
# Allow interaction with the vote buttons only when both audio samples have finished playing
|
153 |
+
aud1\
|
154 |
+
.stop(
|
155 |
+
unlock_vote,
|
156 |
+
outputs=[abetter, bbetter, aplayed, bplayed],
|
157 |
+
inputs=[autoplay, gr.State(value=0), aplayed, bplayed],
|
158 |
+
)\
|
159 |
+
.then(
|
160 |
+
None,
|
161 |
+
inputs=[bplayed if autoplay else True],
|
162 |
+
js="(b) => b ? 0 : document.querySelector('.row .gap+.gap button.play-pause-button[aria-label=Play]').click()",
|
163 |
+
)
|
164 |
+
# autoplay if unplayed
|
165 |
+
aud2\
|
166 |
+
.stop(
|
167 |
+
unlock_vote,
|
168 |
+
outputs=[abetter, bbetter, aplayed, bplayed],
|
169 |
+
inputs=[autoplay, gr.State(value=1), aplayed, bplayed],
|
170 |
+
)
|
171 |
+
# unblur text with JS; faster than sending output with elem_classes
|
172 |
+
aud2.stop(None, inputs=[aplayed], js="(a) => a ? "+ unblur_text_js +" : 0;")
|
173 |
|
|
|
174 |
nxt_outputs = [abetter, bbetter, prevmodel1, prevmodel2, nxtroundbtn]
|
175 |
abetter.click(a_is_better, outputs=nxt_outputs, inputs=[model1, model2, useridstate])
|
176 |
bbetter.click(b_is_better, outputs=nxt_outputs, inputs=[model1, model2, useridstate])
|