Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -321,19 +321,19 @@ async def generate_story_audios(story: StoryCreationDTO, base_output: str, max_c
|
|
| 321 |
story_dir = Path(base_output) / story.storyId
|
| 322 |
story_dir.mkdir(parents=True, exist_ok=True)
|
| 323 |
|
| 324 |
-
print(f"[INFO] Generating story '{story.storyId}' in {story_dir}")
|
| 325 |
|
| 326 |
# Semaphore ensures we don't overload GPU
|
| 327 |
gpu_semaphore = asyncio.Semaphore(max_concurrent_gpu)
|
| 328 |
|
| 329 |
async def process_sentence(chapter_dir: Path, scene: SceneDto, sentence: SentenceDto):
|
| 330 |
-
print(f"[INFO] Starting sentence '{sentence.sentenceId}' in scene '{scene.sceneId}'")
|
| 331 |
async with gpu_semaphore:
|
| 332 |
-
print(f"[GPU] Acquired GPU for sentence '{sentence.sentenceId}'")
|
| 333 |
# Get prosody file from cache
|
| 334 |
prosody_file = download_cache.get(sentence.prosodyReference)
|
| 335 |
if not prosody_file:
|
| 336 |
-
print(f"[WARN] Prosody file for '{sentence.sentenceId}' not found in cache")
|
| 337 |
return None
|
| 338 |
|
| 339 |
sentence_save_path = chapter_dir / scene.sceneId / f"{sentence.sentenceId}.wav"
|
|
@@ -354,7 +354,7 @@ async def generate_story_audios(story: StoryCreationDTO, base_output: str, max_c
|
|
| 354 |
prosody_file,
|
| 355 |
str(sentence_save_path)
|
| 356 |
)
|
| 357 |
-
print(f"[DONE] Generated audio for sentence '{sentence.sentenceId}' -> {generated_path}")
|
| 358 |
return generated_path
|
| 359 |
|
| 360 |
# Prepare tasks for chapters
|
|
@@ -374,7 +374,7 @@ async def generate_story_audios(story: StoryCreationDTO, base_output: str, max_c
|
|
| 374 |
chapter.title.intensity
|
| 375 |
)
|
| 376 |
|
| 377 |
-
print(f"[GPU] Generating title audio for chapter '{chapter.chapterId}'")
|
| 378 |
loop = asyncio.get_event_loop()
|
| 379 |
await loop.run_in_executor(
|
| 380 |
None,
|
|
@@ -383,29 +383,29 @@ async def generate_story_audios(story: StoryCreationDTO, base_output: str, max_c
|
|
| 383 |
title_prosody,
|
| 384 |
str(title_save_path)
|
| 385 |
)
|
| 386 |
-
print(f"[DONE] Generated title audio for chapter '{chapter.chapterId}' -> {title_save_path}")
|
| 387 |
|
| 388 |
# --- Scenes ---
|
| 389 |
scene_tasks = []
|
| 390 |
for scene in chapter.scenes:
|
| 391 |
-
print(f"[INFO] Downloading files for scene '{scene.sceneId}'")
|
| 392 |
await download_scene_files(scene)
|
| 393 |
|
| 394 |
for sentence in scene.sentences:
|
| 395 |
scene_tasks.append(process_sentence(chapter_dir, scene, sentence))
|
| 396 |
|
| 397 |
if scene_tasks:
|
| 398 |
-
print(f"[INFO] Running {len(scene_tasks)} sentences for chapter '{chapter.chapterId}' concurrently")
|
| 399 |
chapter_tasks.append(asyncio.gather(*scene_tasks))
|
| 400 |
else:
|
| 401 |
-
print(f"[WARN] No sentences found in chapter '{chapter.chapterId}'")
|
| 402 |
|
| 403 |
# Wait for all chapters to complete
|
| 404 |
if chapter_tasks:
|
| 405 |
await asyncio.gather(*chapter_tasks)
|
| 406 |
-
print(f"[INFO] Completed generating all chapters for story '{story.storyId}'")
|
| 407 |
else:
|
| 408 |
-
print(f"[WARN] No chapters/tasks to process for story '{story.storyId}'")
|
| 409 |
|
| 410 |
#_______________ Concatenating the generated audios to make the final story (post-processing)_______________________
|
| 411 |
|
|
|
|
| 321 |
story_dir = Path(base_output) / story.storyId
|
| 322 |
story_dir.mkdir(parents=True, exist_ok=True)
|
| 323 |
|
| 324 |
+
#print(f"[INFO] Generating story '{story.storyId}' in {story_dir}")
|
| 325 |
|
| 326 |
# Semaphore ensures we don't overload GPU
|
| 327 |
gpu_semaphore = asyncio.Semaphore(max_concurrent_gpu)
|
| 328 |
|
| 329 |
async def process_sentence(chapter_dir: Path, scene: SceneDto, sentence: SentenceDto):
|
| 330 |
+
#print(f"[INFO] Starting sentence '{sentence.sentenceId}' in scene '{scene.sceneId}'")
|
| 331 |
async with gpu_semaphore:
|
| 332 |
+
#print(f"[GPU] Acquired GPU for sentence '{sentence.sentenceId}'")
|
| 333 |
# Get prosody file from cache
|
| 334 |
prosody_file = download_cache.get(sentence.prosodyReference)
|
| 335 |
if not prosody_file:
|
| 336 |
+
#print(f"[WARN] Prosody file for '{sentence.sentenceId}' not found in cache")
|
| 337 |
return None
|
| 338 |
|
| 339 |
sentence_save_path = chapter_dir / scene.sceneId / f"{sentence.sentenceId}.wav"
|
|
|
|
| 354 |
prosody_file,
|
| 355 |
str(sentence_save_path)
|
| 356 |
)
|
| 357 |
+
#print(f"[DONE] Generated audio for sentence '{sentence.sentenceId}' -> {generated_path}")
|
| 358 |
return generated_path
|
| 359 |
|
| 360 |
# Prepare tasks for chapters
|
|
|
|
| 374 |
chapter.title.intensity
|
| 375 |
)
|
| 376 |
|
| 377 |
+
#print(f"[GPU] Generating title audio for chapter '{chapter.chapterId}'")
|
| 378 |
loop = asyncio.get_event_loop()
|
| 379 |
await loop.run_in_executor(
|
| 380 |
None,
|
|
|
|
| 383 |
title_prosody,
|
| 384 |
str(title_save_path)
|
| 385 |
)
|
| 386 |
+
#print(f"[DONE] Generated title audio for chapter '{chapter.chapterId}' -> {title_save_path}")
|
| 387 |
|
| 388 |
# --- Scenes ---
|
| 389 |
scene_tasks = []
|
| 390 |
for scene in chapter.scenes:
|
| 391 |
+
#print(f"[INFO] Downloading files for scene '{scene.sceneId}'")
|
| 392 |
await download_scene_files(scene)
|
| 393 |
|
| 394 |
for sentence in scene.sentences:
|
| 395 |
scene_tasks.append(process_sentence(chapter_dir, scene, sentence))
|
| 396 |
|
| 397 |
if scene_tasks:
|
| 398 |
+
#print(f"[INFO] Running {len(scene_tasks)} sentences for chapter '{chapter.chapterId}' concurrently")
|
| 399 |
chapter_tasks.append(asyncio.gather(*scene_tasks))
|
| 400 |
else:
|
| 401 |
+
#print(f"[WARN] No sentences found in chapter '{chapter.chapterId}'")
|
| 402 |
|
| 403 |
# Wait for all chapters to complete
|
| 404 |
if chapter_tasks:
|
| 405 |
await asyncio.gather(*chapter_tasks)
|
| 406 |
+
#print(f"[INFO] Completed generating all chapters for story '{story.storyId}'")
|
| 407 |
else:
|
| 408 |
+
#print(f"[WARN] No chapters/tasks to process for story '{story.storyId}'")
|
| 409 |
|
| 410 |
#_______________ Concatenating the generated audios to make the final story (post-processing)_______________________
|
| 411 |
|