Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -32,7 +32,9 @@ import markdown
|
|
32 |
import PyPDF2
|
33 |
import io
|
34 |
import copy
|
|
|
35 |
|
|
|
36 |
def get_instructor_name(speaker):
|
37 |
instructor_names = {
|
38 |
"feynman.mp3": "Professor Richard Feynman",
|
@@ -406,10 +408,8 @@ def create_zip_of_files(file_paths):
|
|
406 |
|
407 |
# Access local files
|
408 |
def get_gradio_file_url(local_path):
|
409 |
-
|
410 |
-
|
411 |
-
print(f"Full Path: {final_path}")
|
412 |
-
return final_path
|
413 |
|
414 |
# Async generate lecture materials and audio
|
415 |
async def on_generate(api_service, api_key, serpapi_key, title, lecture_content_description, lecture_type, lecture_style, speaker_audio, num_slides):
|
@@ -1306,84 +1306,100 @@ js_code = """
|
|
1306 |
// Start playback
|
1307 |
isPlaying = true;
|
1308 |
playIcon.className = 'fas fa-pause';
|
1309 |
-
currentSlide = 0;
|
1310 |
-
currentAudioIndex = 0;
|
1311 |
|
1312 |
-
|
1313 |
-
|
1314 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1315 |
isPlaying = false;
|
1316 |
playIcon.className = 'fas fa-play';
|
1317 |
-
audioElements.forEach(
|
1318 |
-
if (audio) audio.style.border = 'none';
|
1319 |
-
});
|
1320 |
-
console.log("Finished playing all slides or paused");
|
1321 |
return;
|
1322 |
}
|
1323 |
-
|
1324 |
currentSlide = currentAudioIndex;
|
1325 |
updateSlide(() => {
|
1326 |
-
|
1327 |
-
if (audio && audio.play) {
|
1328 |
-
audioElements.forEach(a => a.style.border = 'none');
|
1329 |
-
audio.style.border = '5px solid #16cd16';
|
1330 |
-
audio.style.borderRadius = '30px';
|
1331 |
-
console.log(`Attempting to play audio for slide ${currentAudioIndex + 1}`);
|
1332 |
-
|
1333 |
-
audio.play().then(() => {
|
1334 |
-
console.log(`Playing audio for slide ${currentAudioIndex + 1}`);
|
1335 |
-
audio.onended = null;
|
1336 |
-
audio.addEventListener('ended', () => {
|
1337 |
-
if (isPlaying) {
|
1338 |
-
console.log(`Audio ended for slide ${currentAudioIndex + 1}`);
|
1339 |
-
currentAudioIndex++;
|
1340 |
-
playNext();
|
1341 |
-
}
|
1342 |
-
}, { once: true });
|
1343 |
-
|
1344 |
-
const checkDuration = setInterval(() => {
|
1345 |
-
if (!isPlaying) {
|
1346 |
-
clearInterval(checkDuration);
|
1347 |
-
return;
|
1348 |
-
}
|
1349 |
-
if (audio.duration && audio.currentTime >= audio.duration - 0.1) {
|
1350 |
-
console.log(`Fallback: Audio for slide ${currentAudioIndex + 1} considered ended`);
|
1351 |
-
clearInterval(checkDuration);
|
1352 |
-
audio.onended = null;
|
1353 |
-
currentAudioIndex++;
|
1354 |
-
playNext();
|
1355 |
-
}
|
1356 |
-
}, 1000);
|
1357 |
-
}).catch(e => {
|
1358 |
-
console.error(`Audio play failed for slide ${currentAudioIndex + 1}:`, e);
|
1359 |
-
setTimeout(() => {
|
1360 |
-
if (isPlaying) {
|
1361 |
-
audio.play().then(() => {
|
1362 |
-
console.log(`Retry succeeded for slide ${currentAudioIndex + 1}`);
|
1363 |
-
audio.onended = null;
|
1364 |
-
audio.addEventListener('ended', () => {
|
1365 |
-
if (isPlaying) {
|
1366 |
-
console.log(`Audio ended for slide ${currentAudioIndex + 1}`);
|
1367 |
-
currentAudioIndex++;
|
1368 |
-
playNext();
|
1369 |
-
}
|
1370 |
-
}, { once: true });
|
1371 |
-
}).catch(e => {
|
1372 |
-
console.error(`Retry failed for slide ${currentAudioIndex + 1}:`, e);
|
1373 |
-
currentAudioIndex++;
|
1374 |
-
playNext();
|
1375 |
-
});
|
1376 |
-
}
|
1377 |
-
}, 500);
|
1378 |
-
});
|
1379 |
-
} else {
|
1380 |
-
currentAudioIndex++;
|
1381 |
-
playNext();
|
1382 |
-
}
|
1383 |
});
|
1384 |
}
|
1385 |
-
|
1386 |
-
});
|
1387 |
}
|
1388 |
|
1389 |
function toggleFullScreen() {
|
@@ -1426,10 +1442,33 @@ js_code = """
|
|
1426 |
|
1427 |
waitForElement('#reload-btn', (reloadBtn) => {
|
1428 |
reloadBtn.addEventListener('click', () => {
|
1429 |
-
|
1430 |
currentSlide = 0;
|
1431 |
-
|
1432 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1433 |
});
|
1434 |
console.log("Attached event listener to reload-btn");
|
1435 |
});
|
@@ -2302,7 +2341,11 @@ with gr.Blocks(
|
|
2302 |
"audience": audience_val or "University"
|
2303 |
}
|
2304 |
|
2305 |
-
def show_note_content(evt: dict, notes):
|
|
|
|
|
|
|
|
|
2306 |
# evt['index'] gives the row index
|
2307 |
idx = evt.get('index', 0)
|
2308 |
if 0 <= idx < len(notes):
|
|
|
32 |
import PyPDF2
|
33 |
import io
|
34 |
import copy
|
35 |
+
from pathlib import Path
|
36 |
|
37 |
+
gr.set_static_paths(paths=[Path.cwd().absolute()/"outputs"])
|
38 |
def get_instructor_name(speaker):
|
39 |
instructor_names = {
|
40 |
"feynman.mp3": "Professor Richard Feynman",
|
|
|
408 |
|
409 |
# Access local files
|
410 |
def get_gradio_file_url(local_path):
|
411 |
+
return f"/gradio_api/file={local_path}"
|
412 |
+
|
|
|
|
|
413 |
|
414 |
# Async generate lecture materials and audio
|
415 |
async def on_generate(api_service, api_key, serpapi_key, title, lecture_content_description, lecture_type, lecture_style, speaker_audio, num_slides):
|
|
|
1306 |
// Start playback
|
1307 |
isPlaying = true;
|
1308 |
playIcon.className = 'fas fa-pause';
|
|
|
|
|
1309 |
|
1310 |
+
// Only update slide if we're not already on the correct slide
|
1311 |
+
if (currentSlide !== currentAudioIndex) {
|
1312 |
+
currentSlide = currentAudioIndex;
|
1313 |
+
updateSlide(() => {
|
1314 |
+
playCurrentAudio();
|
1315 |
+
});
|
1316 |
+
} else {
|
1317 |
+
playCurrentAudio();
|
1318 |
+
}
|
1319 |
+
|
1320 |
+
function playCurrentAudio() {
|
1321 |
+
if (!isPlaying) return;
|
1322 |
+
|
1323 |
+
const audio = audioElements[currentAudioIndex];
|
1324 |
+
if (audio && audio.play) {
|
1325 |
+
audioElements.forEach(a => a.style.border = 'none');
|
1326 |
+
audio.style.border = '5px solid #16cd16';
|
1327 |
+
audio.style.borderRadius = '30px';
|
1328 |
+
console.log(`Attempting to play audio for slide ${currentAudioIndex + 1}`);
|
1329 |
+
|
1330 |
+
audio.play().then(() => {
|
1331 |
+
console.log(`Playing audio for slide ${currentAudioIndex + 1}`);
|
1332 |
+
audio.onended = null;
|
1333 |
+
audio.addEventListener('ended', () => {
|
1334 |
+
if (isPlaying) {
|
1335 |
+
console.log(`Audio ended for slide ${currentAudioIndex + 1}`);
|
1336 |
+
currentAudioIndex++;
|
1337 |
+
if (currentAudioIndex >= totalSlides) {
|
1338 |
+
isPlaying = false;
|
1339 |
+
playIcon.className = 'fas fa-play';
|
1340 |
+
audioElements.forEach(a => a.style.border = 'none');
|
1341 |
+
return;
|
1342 |
+
}
|
1343 |
+
currentSlide = currentAudioIndex;
|
1344 |
+
updateSlide(() => {
|
1345 |
+
playCurrentAudio();
|
1346 |
+
});
|
1347 |
+
}
|
1348 |
+
}, { once: true });
|
1349 |
+
}).catch(e => {
|
1350 |
+
console.error(`Audio play failed for slide ${currentAudioIndex + 1}:`, e);
|
1351 |
+
setTimeout(() => {
|
1352 |
+
if (isPlaying) {
|
1353 |
+
audio.play().then(() => {
|
1354 |
+
console.log(`Retry succeeded for slide ${currentAudioIndex + 1}`);
|
1355 |
+
audio.onended = null;
|
1356 |
+
audio.addEventListener('ended', () => {
|
1357 |
+
if (isPlaying) {
|
1358 |
+
console.log(`Audio ended for slide ${currentAudioIndex + 1}`);
|
1359 |
+
currentAudioIndex++;
|
1360 |
+
if (currentAudioIndex >= totalSlides) {
|
1361 |
+
isPlaying = false;
|
1362 |
+
playIcon.className = 'fas fa-play';
|
1363 |
+
audioElements.forEach(a => a.style.border = 'none');
|
1364 |
+
return;
|
1365 |
+
}
|
1366 |
+
currentSlide = currentAudioIndex;
|
1367 |
+
updateSlide(() => {
|
1368 |
+
playCurrentAudio();
|
1369 |
+
});
|
1370 |
+
}
|
1371 |
+
}, { once: true });
|
1372 |
+
}).catch(e => {
|
1373 |
+
console.error(`Retry failed for slide ${currentAudioIndex + 1}:`, e);
|
1374 |
+
currentAudioIndex++;
|
1375 |
+
if (currentAudioIndex >= totalSlides) {
|
1376 |
+
isPlaying = false;
|
1377 |
+
playIcon.className = 'fas fa-play';
|
1378 |
+
audioElements.forEach(a => a.style.border = 'none');
|
1379 |
+
return;
|
1380 |
+
}
|
1381 |
+
currentSlide = currentAudioIndex;
|
1382 |
+
updateSlide(() => {
|
1383 |
+
playCurrentAudio();
|
1384 |
+
});
|
1385 |
+
});
|
1386 |
+
}
|
1387 |
+
}, 500);
|
1388 |
+
});
|
1389 |
+
} else {
|
1390 |
+
currentAudioIndex++;
|
1391 |
+
if (currentAudioIndex >= totalSlides) {
|
1392 |
isPlaying = false;
|
1393 |
playIcon.className = 'fas fa-play';
|
1394 |
+
audioElements.forEach(a => a.style.border = 'none');
|
|
|
|
|
|
|
1395 |
return;
|
1396 |
}
|
|
|
1397 |
currentSlide = currentAudioIndex;
|
1398 |
updateSlide(() => {
|
1399 |
+
playCurrentAudio();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1400 |
});
|
1401 |
}
|
1402 |
+
}
|
|
|
1403 |
}
|
1404 |
|
1405 |
function toggleFullScreen() {
|
|
|
1442 |
|
1443 |
waitForElement('#reload-btn', (reloadBtn) => {
|
1444 |
reloadBtn.addEventListener('click', () => {
|
1445 |
+
// Reset state
|
1446 |
currentSlide = 0;
|
1447 |
+
currentAudioIndex = 0;
|
1448 |
+
isPlaying = false;
|
1449 |
+
|
1450 |
+
// Reset play button
|
1451 |
+
const playBtn = document.getElementById('play-btn');
|
1452 |
+
if (playBtn) {
|
1453 |
+
const playIcon = playBtn.querySelector('i');
|
1454 |
+
if (playIcon) {
|
1455 |
+
playIcon.className = 'fas fa-play';
|
1456 |
+
}
|
1457 |
+
}
|
1458 |
+
|
1459 |
+
// Reset audio elements
|
1460 |
+
audioElements.forEach(audio => {
|
1461 |
+
if (audio) {
|
1462 |
+
audio.pause();
|
1463 |
+
audio.currentTime = 0;
|
1464 |
+
audio.style.border = 'none';
|
1465 |
+
}
|
1466 |
+
});
|
1467 |
+
|
1468 |
+
// Force reload first slide
|
1469 |
+
updateSlide(() => {
|
1470 |
+
console.log("Reloaded first slide");
|
1471 |
+
});
|
1472 |
});
|
1473 |
console.log("Attached event listener to reload-btn");
|
1474 |
});
|
|
|
2341 |
"audience": audience_val or "University"
|
2342 |
}
|
2343 |
|
2344 |
+
def show_note_content(evt: dict, notes=None):
|
2345 |
+
# Handle case when only event is provided
|
2346 |
+
if notes is None:
|
2347 |
+
return gr.update(value="Click any button above to generate content...")
|
2348 |
+
|
2349 |
# evt['index'] gives the row index
|
2350 |
idx = evt.get('index', 0)
|
2351 |
if 0 <= idx < len(notes):
|