Spaces:
Running
on
Zero
Running
on
Zero
Autoplay other sample using JavaScript
Browse files
app.py
CHANGED
@@ -865,7 +865,10 @@ def synthandreturn(text):
|
|
865 |
raise gr.Error(f'You did not enter any text')
|
866 |
# Check language
|
867 |
try:
|
868 |
-
if
|
|
|
|
|
|
|
869 |
gr.Warning('Warning: The input text may not be in English')
|
870 |
except:
|
871 |
pass
|
@@ -1093,32 +1096,23 @@ def synthandreturn(text):
|
|
1093 |
# )
|
1094 |
|
1095 |
def unlock_vote(btn_index, aplayed, bplayed):
|
1096 |
-
aud2 = gr.update()
|
1097 |
# sample played
|
1098 |
if btn_index == 0:
|
1099 |
aplayed = True
|
1100 |
-
# autoplay the other once
|
1101 |
-
if not bplayed:
|
1102 |
-
# other options added just to get autoplay to work
|
1103 |
-
aud2 = gr.update(
|
1104 |
-
autoplay=True,
|
1105 |
-
interactive=True,
|
1106 |
-
sources=[],
|
1107 |
-
show_download_button=False,
|
1108 |
-
show_share_button=False,
|
1109 |
-
editable=False
|
1110 |
-
)
|
1111 |
if btn_index == 1:
|
1112 |
bplayed = True
|
1113 |
|
1114 |
# both audio samples played
|
1115 |
if bool(aplayed) and bool(bplayed):
|
1116 |
print('Both audio samples played, voting unlocked')
|
1117 |
-
return [gr.update(interactive=True), gr.update(interactive=True), True, True
|
1118 |
|
1119 |
-
return [gr.update(), gr.update(), aplayed, bplayed
|
1120 |
|
1121 |
-
def
|
|
|
|
|
|
|
1122 |
if request.username:
|
1123 |
# print('auth by username')
|
1124 |
# by HuggingFace username
|
@@ -1220,9 +1214,9 @@ def disable():
|
|
1220 |
def enable():
|
1221 |
return [gr.update(interactive=True), gr.update(interactive=True), gr.update(interactive=True), gr.update(interactive=True)]
|
1222 |
with gr.Blocks() as vote:
|
1223 |
-
# sample played
|
1224 |
-
aplayed = gr.
|
1225 |
-
bplayed = gr.
|
1226 |
# voter ID
|
1227 |
useridstate = gr.State()
|
1228 |
gr.Markdown(INSTR)
|
@@ -1245,7 +1239,7 @@ with gr.Blocks() as vote:
|
|
1245 |
show_label=False,
|
1246 |
show_download_button=False,
|
1247 |
show_share_button=False,
|
1248 |
-
waveform_options={'waveform_progress_color': '#EF4444'}
|
1249 |
# var(--color-red-500)'}); gradio only accepts HEX and CSS color
|
1250 |
)
|
1251 |
abetter = gr.Button("A is better", variant='primary', interactive=False)
|
@@ -1257,7 +1251,7 @@ with gr.Blocks() as vote:
|
|
1257 |
show_label=False,
|
1258 |
show_download_button=False,
|
1259 |
show_share_button=False,
|
1260 |
-
waveform_options={'waveform_progress_color': '#3C82F6'}
|
1261 |
# var(--secondary-500)'}); gradio only accepts HEX and CSS color
|
1262 |
)
|
1263 |
bbetter = gr.Button("B is better", variant='primary', interactive=False)
|
@@ -1306,9 +1300,24 @@ with gr.Blocks() as vote:
|
|
1306 |
.then(enable, outputs=[btn, gr.State(), gr.State(), cachedt])
|
1307 |
|
1308 |
# Allow interaction with the vote buttons only when both audio samples have finished playing
|
1309 |
-
aud1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1310 |
# autoplay if unplayed
|
1311 |
-
aud2
|
|
|
|
|
|
|
|
|
|
|
1312 |
|
1313 |
# nxt_outputs = [prevmodel1, prevmodel2, abetter, bbetter]
|
1314 |
nxt_outputs = [abetter, bbetter, prevmodel1, prevmodel2, nxtroundbtn]
|
|
|
865 |
raise gr.Error(f'You did not enter any text')
|
866 |
# Check language
|
867 |
try:
|
868 |
+
if (
|
869 |
+
text not in sents
|
870 |
+
and not detect(text) == "en"
|
871 |
+
):
|
872 |
gr.Warning('Warning: The input text may not be in English')
|
873 |
except:
|
874 |
pass
|
|
|
1096 |
# )
|
1097 |
|
1098 |
def unlock_vote(btn_index, aplayed, bplayed):
|
|
|
1099 |
# sample played
|
1100 |
if btn_index == 0:
|
1101 |
aplayed = True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1102 |
if btn_index == 1:
|
1103 |
bplayed = True
|
1104 |
|
1105 |
# both audio samples played
|
1106 |
if bool(aplayed) and bool(bplayed):
|
1107 |
print('Both audio samples played, voting unlocked')
|
1108 |
+
return [gr.update(interactive=True), gr.update(interactive=True), True, True]
|
1109 |
|
1110 |
+
return [gr.update(), gr.update(), aplayed, bplayed]
|
1111 |
|
1112 |
+
def play_other(bplayed):
|
1113 |
+
return bplayed
|
1114 |
+
|
1115 |
+
def get_userid(request):
|
1116 |
if request.username:
|
1117 |
# print('auth by username')
|
1118 |
# by HuggingFace username
|
|
|
1214 |
def enable():
|
1215 |
return [gr.update(interactive=True), gr.update(interactive=True), gr.update(interactive=True), gr.update(interactive=True)]
|
1216 |
with gr.Blocks() as vote:
|
1217 |
+
# sample played, using Checkbox so that JS can fetch the value
|
1218 |
+
aplayed = gr.Checkbox(visible=False, value=False)
|
1219 |
+
bplayed = gr.Checkbox(visible=False, value=False)
|
1220 |
# voter ID
|
1221 |
useridstate = gr.State()
|
1222 |
gr.Markdown(INSTR)
|
|
|
1239 |
show_label=False,
|
1240 |
show_download_button=False,
|
1241 |
show_share_button=False,
|
1242 |
+
waveform_options={'waveform_progress_color': '#EF4444'},
|
1243 |
# var(--color-red-500)'}); gradio only accepts HEX and CSS color
|
1244 |
)
|
1245 |
abetter = gr.Button("A is better", variant='primary', interactive=False)
|
|
|
1251 |
show_label=False,
|
1252 |
show_download_button=False,
|
1253 |
show_share_button=False,
|
1254 |
+
waveform_options={'waveform_progress_color': '#3C82F6'},
|
1255 |
# var(--secondary-500)'}); gradio only accepts HEX and CSS color
|
1256 |
)
|
1257 |
bbetter = gr.Button("B is better", variant='primary', interactive=False)
|
|
|
1300 |
.then(enable, outputs=[btn, gr.State(), gr.State(), cachedt])
|
1301 |
|
1302 |
# Allow interaction with the vote buttons only when both audio samples have finished playing
|
1303 |
+
aud1\
|
1304 |
+
.stop(
|
1305 |
+
unlock_vote,
|
1306 |
+
outputs=[abetter, bbetter, aplayed, bplayed],
|
1307 |
+
inputs=[gr.State(value=0), aplayed, bplayed],
|
1308 |
+
)\
|
1309 |
+
.then(
|
1310 |
+
None,
|
1311 |
+
inputs=[bplayed],
|
1312 |
+
js="(b) => {console.log(b); b ? 0 : document.querySelector('.stretch .gap+.gap button.play-pause-button').click()}",
|
1313 |
+
)
|
1314 |
# autoplay if unplayed
|
1315 |
+
aud2\
|
1316 |
+
.stop(
|
1317 |
+
unlock_vote,
|
1318 |
+
outputs=[abetter, bbetter, aplayed, bplayed],
|
1319 |
+
inputs=[gr.State(value=1), aplayed, bplayed],
|
1320 |
+
)
|
1321 |
|
1322 |
# nxt_outputs = [prevmodel1, prevmodel2, abetter, bbetter]
|
1323 |
nxt_outputs = [abetter, bbetter, prevmodel1, prevmodel2, nxtroundbtn]
|