Spaces:
Running
on
Zero
Running
on
Zero
JS cache cookie fix
Browse files
app.py
CHANGED
@@ -1302,6 +1302,8 @@ def enable():
|
|
1302 |
def unblur_text():
|
1303 |
return gr.update(elem_classes=[])
|
1304 |
|
|
|
|
|
1305 |
unblur_js = 'document.getElementById("arena-text-input").classList.remove("blurred-text")'
|
1306 |
shortcut_js = """
|
1307 |
<script>
|
@@ -1326,8 +1328,11 @@ function shortcuts(e) {
|
|
1326 |
}
|
1327 |
}
|
1328 |
document.addEventListener('keypress', shortcuts, false);
|
1329 |
-
|
1330 |
"""
|
|
|
|
|
|
|
1331 |
|
1332 |
with gr.Blocks() as vote:
|
1333 |
session_hash = gr.Textbox(visible=False, value='')
|
@@ -1502,7 +1507,7 @@ with gr.Blocks() as tts_info:
|
|
1502 |
# ddb = gr.Button("Delete DB")
|
1503 |
# ddb.click(del_db, inputs=dbtext, outputs=ddb)
|
1504 |
# Blur cached sample text so the voting user picks up mispronouncements
|
1505 |
-
with gr.Blocks(theme=theme, css="footer {visibility: hidden}textbox{resize:none} .blurred-text {filter: blur(0.15em);}", head=
|
1506 |
gr.Markdown(DESCR)
|
1507 |
# gr.TabbedInterface([vote, leaderboard, about, admin], ['Vote', 'Leaderboard', 'About', 'Admin (ONLY IN BETA)'])
|
1508 |
gr.TabbedInterface([vote, leaderboard, about, tts_info], ['π³οΈ Vote', 'π Leaderboard', 'π About', 'π£ Contenders'])
|
|
|
1302 |
def unblur_text():
|
1303 |
return gr.update(elem_classes=[])
|
1304 |
|
1305 |
+
# JavaScript within HTML head
|
1306 |
+
head_js = ""
|
1307 |
unblur_js = 'document.getElementById("arena-text-input").classList.remove("blurred-text")'
|
1308 |
shortcut_js = """
|
1309 |
<script>
|
|
|
1328 |
}
|
1329 |
}
|
1330 |
document.addEventListener('keypress', shortcuts, false);
|
1331 |
+
|
1332 |
"""
|
1333 |
+
head_js += shortcut_js
|
1334 |
+
head_js += open("cookie.js").read()
|
1335 |
+
head_js += '</script>'
|
1336 |
|
1337 |
with gr.Blocks() as vote:
|
1338 |
session_hash = gr.Textbox(visible=False, value='')
|
|
|
1507 |
# ddb = gr.Button("Delete DB")
|
1508 |
# ddb.click(del_db, inputs=dbtext, outputs=ddb)
|
1509 |
# Blur cached sample text so the voting user picks up mispronouncements
|
1510 |
+
with gr.Blocks(theme=theme, css="footer {visibility: hidden}textbox{resize:none} .blurred-text {filter: blur(0.15em);}", head=head_js, title="TTS Arena") as demo:
|
1511 |
gr.Markdown(DESCR)
|
1512 |
# gr.TabbedInterface([vote, leaderboard, about, admin], ['Vote', 'Leaderboard', 'About', 'Admin (ONLY IN BETA)'])
|
1513 |
gr.TabbedInterface([vote, leaderboard, about, tts_info], ['π³οΈ Vote', 'π Leaderboard', 'π About', 'π£ Contenders'])
|
cookie.js
CHANGED
@@ -1,31 +1,30 @@
|
|
1 |
-
function () {
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
return c.substring(name.length, c.length);
|
13 |
-
}
|
14 |
}
|
15 |
-
return "";
|
16 |
}
|
|
|
|
|
17 |
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
}
|
|
|
1 |
+
window.getArenaCookie = function getArenaCookie(cname) {
|
2 |
+
let name = cname + "=";
|
3 |
+
let decodedCookie = decodeURIComponent(window.document.cookie);
|
4 |
+
let ca = decodedCookie.split(';');
|
5 |
+
for (let i = 0; i < ca.length; i++) {
|
6 |
+
let c = ca[i];
|
7 |
+
while (c.charAt(0) == ' ') {
|
8 |
+
c = c.substring(1);
|
9 |
+
}
|
10 |
+
if (c.indexOf(name) == 0) {
|
11 |
+
return c.substring(name.length, c.length);
|
|
|
|
|
12 |
}
|
|
|
13 |
}
|
14 |
+
return "";
|
15 |
+
}
|
16 |
|
17 |
+
window.setArenaCookie = function setArenaCookie(cname, cvalue, exdays) {
|
18 |
+
const d = new Date();
|
19 |
+
d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
|
20 |
+
let expires = "expires=" + d.toUTCString();
|
21 |
+
window.document.cookie = cname + "=" + cvalue + ";" + expires + ";Domain=.huggingface.co; path=/; SameSite=None;";
|
22 |
+
}
|
23 |
|
24 |
+
if (window.getArenaCookie('session').length == 0)
|
25 |
+
{
|
26 |
+
const d = new Date();
|
27 |
+
// store cookie for 90 days, about the time the the cached audio should be deleted
|
28 |
+
window.setArenaCookie('session', d.getTime().toString(), 90);
|
29 |
+
console.log('Session cookie created')
|
30 |
}
|