Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
GitHub Actions
commited on
Commit
·
31e54a8
1
Parent(s):
afeed38
Sync from GitHub repo
Browse files- templates/arena.html +65 -23
templates/arena.html
CHANGED
|
@@ -28,6 +28,10 @@
|
|
| 28 |
<button type="submit" class="mobile-synth-btn">Synthesize</button>
|
| 29 |
</form>
|
| 30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
<div class="loading-container" style="display: none;">
|
| 32 |
<div class="loader-wrapper">
|
| 33 |
<div class="loader-animation">
|
|
@@ -71,10 +75,6 @@
|
|
| 71 |
</button>
|
| 72 |
</div>
|
| 73 |
</div>
|
| 74 |
-
|
| 75 |
-
<div class="keyboard-hint">
|
| 76 |
-
Press <kbd>Space</kbd> to play/pause audio, <kbd>A</kbd> or <kbd>B</kbd> to vote after listening, <kbd>R</kbd> for random audio, <kbd>Enter</kbd> to generate
|
| 77 |
-
</div>
|
| 78 |
</div>
|
| 79 |
|
| 80 |
<div class="vote-results" style="display: none;">
|
|
@@ -90,7 +90,11 @@
|
|
| 90 |
</div>
|
| 91 |
|
| 92 |
<div class="next-round-container" style="display: none;">
|
| 93 |
-
<button class="next-round-btn">Next Round
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
</div>
|
| 95 |
</div>
|
| 96 |
|
|
@@ -166,10 +170,6 @@
|
|
| 166 |
</div>
|
| 167 |
</div>
|
| 168 |
|
| 169 |
-
<div class="keyboard-hint">
|
| 170 |
-
Press <kbd>Space</kbd> to play/pause audio, <kbd>A</kbd> or <kbd>B</kbd> to vote after listening, <kbd>R</kbd> for random audio, <kbd>Enter</kbd> to generate
|
| 171 |
-
</div>
|
| 172 |
-
|
| 173 |
<div class="podcast-vote-results vote-results" style="display: none;">
|
| 174 |
<h3 class="results-heading">Vote Recorded!</h3>
|
| 175 |
<div class="results-content">
|
|
@@ -1008,6 +1008,10 @@
|
|
| 1008 |
const modelNameDisplays = document.querySelectorAll('.model-name-display');
|
| 1009 |
const wavePlayerContainers = document.querySelectorAll('.wave-player-container');
|
| 1010 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1011 |
let bothSamplesPlayed = false;
|
| 1012 |
let currentSessionId = null;
|
| 1013 |
let modelNames = { a: '', b: '' };
|
|
@@ -1025,8 +1029,10 @@
|
|
| 1025 |
});
|
| 1026 |
|
| 1027 |
// Load fallback sentences directly from Flask variable (JSON string)
|
| 1028 |
-
//
|
| 1029 |
-
|
|
|
|
|
|
|
| 1030 |
|
| 1031 |
// Fetch cached sentences on load
|
| 1032 |
function fetchCachedSentences() {
|
|
@@ -1109,11 +1115,13 @@
|
|
| 1109 |
|
| 1110 |
textInput.blur();
|
| 1111 |
|
| 1112 |
-
// Show loading animation
|
| 1113 |
loadingContainer.style.display = 'flex';
|
| 1114 |
playersContainer.style.display = 'none';
|
| 1115 |
voteResultsContainer.style.display = 'none';
|
| 1116 |
nextRoundContainer.style.display = 'none';
|
|
|
|
|
|
|
| 1117 |
|
| 1118 |
// Reset vote buttons
|
| 1119 |
voteButtons.forEach(btn => {
|
|
@@ -1153,9 +1161,11 @@
|
|
| 1153 |
wavePlayers.a.loadAudio(data.audio_a);
|
| 1154 |
wavePlayers.b.loadAudio(data.audio_b);
|
| 1155 |
|
| 1156 |
-
// Show players
|
| 1157 |
loadingContainer.style.display = 'none';
|
| 1158 |
playersContainer.style.display = 'flex';
|
|
|
|
|
|
|
| 1159 |
|
| 1160 |
// Setup automatic sequential playback
|
| 1161 |
wavePlayers.a.wavesurfer.once('ready', function() {
|
|
@@ -1297,6 +1307,10 @@
|
|
| 1297 |
|
| 1298 |
// Reset the flag for both samples played
|
| 1299 |
bothSamplesPlayed = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1300 |
}
|
| 1301 |
|
| 1302 |
function handleRandom() {
|
|
@@ -1324,6 +1338,18 @@
|
|
| 1324 |
openToast("Please listen to both audio samples before voting", "info");
|
| 1325 |
}
|
| 1326 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1327 |
// Add submit event listener to form
|
| 1328 |
synthForm.addEventListener('submit', handleSynthesize);
|
| 1329 |
|
|
@@ -1347,10 +1373,27 @@
|
|
| 1347 |
|
| 1348 |
// Only process keyboard shortcuts if text input is not focused
|
| 1349 |
if (document.activeElement === textInput) {
|
| 1350 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1351 |
}
|
| 1352 |
-
|
| 1353 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1354 |
if (bothSamplesPlayed && !voteButtons[0].disabled) {
|
| 1355 |
handleVote('a');
|
| 1356 |
} else if (playersContainer.style.display !== 'none' && !bothSamplesPlayed) {
|
|
@@ -1363,15 +1406,14 @@
|
|
| 1363 |
showListenToastMessage();
|
| 1364 |
}
|
| 1365 |
} else if (e.key.toLowerCase() === 'n') {
|
| 1366 |
-
|
| 1367 |
-
|
| 1368 |
-
|
| 1369 |
-
|
| 1370 |
-
resetToInitialState();
|
| 1371 |
}
|
| 1372 |
} else if (e.key.toLowerCase() === 'r') {
|
| 1373 |
-
//
|
| 1374 |
-
if (!e.ctrlKey && !e.metaKey) {
|
| 1375 |
e.preventDefault();
|
| 1376 |
handleRandom();
|
| 1377 |
}
|
|
|
|
| 28 |
<button type="submit" class="mobile-synth-btn">Synthesize</button>
|
| 29 |
</form>
|
| 30 |
|
| 31 |
+
<div id="initial-keyboard-hint" class="keyboard-hint">
|
| 32 |
+
Press <kbd>R</kbd> for random text, <kbd>N</kbd> for next random round, <kbd>Enter</kbd> to generate
|
| 33 |
+
</div>
|
| 34 |
+
|
| 35 |
<div class="loading-container" style="display: none;">
|
| 36 |
<div class="loader-wrapper">
|
| 37 |
<div class="loader-animation">
|
|
|
|
| 75 |
</button>
|
| 76 |
</div>
|
| 77 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
</div>
|
| 79 |
|
| 80 |
<div class="vote-results" style="display: none;">
|
|
|
|
| 90 |
</div>
|
| 91 |
|
| 92 |
<div class="next-round-container" style="display: none;">
|
| 93 |
+
<button class="next-round-btn">Next Round</button>
|
| 94 |
+
</div>
|
| 95 |
+
|
| 96 |
+
<div id="playback-keyboard-hint" class="keyboard-hint" style="display: none;">
|
| 97 |
+
Press <kbd>Space</kbd> to play/pause, <kbd>A</kbd>/<kbd>B</kbd> to vote, <kbd>R</kbd> for random text, <kbd>N</kbd> for next random round
|
| 98 |
</div>
|
| 99 |
</div>
|
| 100 |
|
|
|
|
| 170 |
</div>
|
| 171 |
</div>
|
| 172 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 173 |
<div class="podcast-vote-results vote-results" style="display: none;">
|
| 174 |
<h3 class="results-heading">Vote Recorded!</h3>
|
| 175 |
<div class="results-content">
|
|
|
|
| 1008 |
const modelNameDisplays = document.querySelectorAll('.model-name-display');
|
| 1009 |
const wavePlayerContainers = document.querySelectorAll('.wave-player-container');
|
| 1010 |
|
| 1011 |
+
// Get references to the keyboard hint elements
|
| 1012 |
+
const initialKeyboardHint = document.getElementById('initial-keyboard-hint');
|
| 1013 |
+
const playbackKeyboardHint = document.getElementById('playback-keyboard-hint');
|
| 1014 |
+
|
| 1015 |
let bothSamplesPlayed = false;
|
| 1016 |
let currentSessionId = null;
|
| 1017 |
let modelNames = { a: '', b: '' };
|
|
|
|
| 1029 |
});
|
| 1030 |
|
| 1031 |
// Load fallback sentences directly from Flask variable (JSON string)
|
| 1032 |
+
// Assign to a variable first to help linters
|
| 1033 |
+
// eslint-disable-next-line
|
| 1034 |
+
const fallbackSentencesJson = {{ harvard_sentences | tojson | safe }};
|
| 1035 |
+
const fallbackRandomTexts = JSON.parse(fallbackSentencesJson);
|
| 1036 |
|
| 1037 |
// Fetch cached sentences on load
|
| 1038 |
function fetchCachedSentences() {
|
|
|
|
| 1115 |
|
| 1116 |
textInput.blur();
|
| 1117 |
|
| 1118 |
+
// Show loading animation and hide hints
|
| 1119 |
loadingContainer.style.display = 'flex';
|
| 1120 |
playersContainer.style.display = 'none';
|
| 1121 |
voteResultsContainer.style.display = 'none';
|
| 1122 |
nextRoundContainer.style.display = 'none';
|
| 1123 |
+
initialKeyboardHint.style.display = 'none';
|
| 1124 |
+
playbackKeyboardHint.style.display = 'none';
|
| 1125 |
|
| 1126 |
// Reset vote buttons
|
| 1127 |
voteButtons.forEach(btn => {
|
|
|
|
| 1161 |
wavePlayers.a.loadAudio(data.audio_a);
|
| 1162 |
wavePlayers.b.loadAudio(data.audio_b);
|
| 1163 |
|
| 1164 |
+
// Show players and playback hint, hide initial hint
|
| 1165 |
loadingContainer.style.display = 'none';
|
| 1166 |
playersContainer.style.display = 'flex';
|
| 1167 |
+
initialKeyboardHint.style.display = 'none';
|
| 1168 |
+
playbackKeyboardHint.style.display = 'block';
|
| 1169 |
|
| 1170 |
// Setup automatic sequential playback
|
| 1171 |
wavePlayers.a.wavesurfer.once('ready', function() {
|
|
|
|
| 1307 |
|
| 1308 |
// Reset the flag for both samples played
|
| 1309 |
bothSamplesPlayed = false;
|
| 1310 |
+
|
| 1311 |
+
// Show initial hint, hide playback hint
|
| 1312 |
+
initialKeyboardHint.style.display = 'block';
|
| 1313 |
+
playbackKeyboardHint.style.display = 'none';
|
| 1314 |
}
|
| 1315 |
|
| 1316 |
function handleRandom() {
|
|
|
|
| 1338 |
openToast("Please listen to both audio samples before voting", "info");
|
| 1339 |
}
|
| 1340 |
|
| 1341 |
+
// New function for N shortcut: Random + Synthesize
|
| 1342 |
+
function handleNextRandomRound() {
|
| 1343 |
+
console.log("Handling Next Random Round (N shortcut)");
|
| 1344 |
+
handleRandom(); // Selects random text and puts it in input
|
| 1345 |
+
|
| 1346 |
+
// Use setTimeout to ensure the input value is updated before synthesizing
|
| 1347 |
+
// Especially important if handleRandom involves async operations (though it doesn't currently)
|
| 1348 |
+
setTimeout(() => {
|
| 1349 |
+
handleSynthesize(); // Triggers synthesis with the text now in the input
|
| 1350 |
+
}, 0);
|
| 1351 |
+
}
|
| 1352 |
+
|
| 1353 |
// Add submit event listener to form
|
| 1354 |
synthForm.addEventListener('submit', handleSynthesize);
|
| 1355 |
|
|
|
|
| 1373 |
|
| 1374 |
// Only process keyboard shortcuts if text input is not focused
|
| 1375 |
if (document.activeElement === textInput) {
|
| 1376 |
+
// Allow Enter key to submit form from text input
|
| 1377 |
+
if (e.key === 'Enter') {
|
| 1378 |
+
// Check if Shift, Ctrl, Alt, or Meta keys are pressed
|
| 1379 |
+
if (!e.shiftKey && !e.ctrlKey && !e.altKey && !e.metaKey) {
|
| 1380 |
+
e.preventDefault(); // Prevent default form submission if needed
|
| 1381 |
+
handleSynthesize(); // Trigger synthesis
|
| 1382 |
+
}
|
| 1383 |
+
}
|
| 1384 |
+
return; // Don't process other keys if input is focused
|
| 1385 |
}
|
| 1386 |
+
|
| 1387 |
+
// Allow Enter key to submit form when button is focused maybe?
|
| 1388 |
+
// Or just generally allow Enter if not focused on input
|
| 1389 |
+
if (e.key === 'Enter' && !e.ctrlKey && !e.metaKey && !e.altKey) {
|
| 1390 |
+
// Check if the initial form is visible (or loading is not happening)
|
| 1391 |
+
if (playersContainer.style.display === 'none' && loadingContainer.style.display === 'none') {
|
| 1392 |
+
e.preventDefault();
|
| 1393 |
+
handleSynthesize();
|
| 1394 |
+
}
|
| 1395 |
+
// Do nothing if players are visible (don't want Enter to re-submit)
|
| 1396 |
+
} else if (e.key.toLowerCase() === 'a') {
|
| 1397 |
if (bothSamplesPlayed && !voteButtons[0].disabled) {
|
| 1398 |
handleVote('a');
|
| 1399 |
} else if (playersContainer.style.display !== 'none' && !bothSamplesPlayed) {
|
|
|
|
| 1406 |
showListenToastMessage();
|
| 1407 |
}
|
| 1408 |
} else if (e.key.toLowerCase() === 'n') {
|
| 1409 |
+
// N for Next Random Round (works anytime except when input focused)
|
| 1410 |
+
if (!e.ctrlKey && !e.metaKey && !e.altKey) { // Ensure Alt isn't pressed either
|
| 1411 |
+
e.preventDefault();
|
| 1412 |
+
handleNextRandomRound(); // New function for random + synthesize
|
|
|
|
| 1413 |
}
|
| 1414 |
} else if (e.key.toLowerCase() === 'r') {
|
| 1415 |
+
// R for Random Text (works anytime except when input focused)
|
| 1416 |
+
if (!e.ctrlKey && !e.metaKey && !e.altKey) { // Ensure Alt isn't pressed either
|
| 1417 |
e.preventDefault();
|
| 1418 |
handleRandom();
|
| 1419 |
}
|