Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -549,7 +549,7 @@ def run_production_pipeline(job: TranslationJob, gemini_key: str, elevenlabs_key
|
|
| 549 |
print(f"[{video_id}] Exception deleting voice: {del_err}")
|
| 550 |
|
| 551 |
# 5. Merge synthesized audio back with the original video (or run Lip-Sync if selected)
|
| 552 |
-
lipsync_output_path
|
| 553 |
|
| 554 |
if job.has_lip_sync:
|
| 555 |
print(f"[{video_id}] Setting up Wav2Lip model checkpoint files...")
|
|
@@ -568,12 +568,29 @@ def run_production_pipeline(job: TranslationJob, gemini_key: str, elevenlabs_key
|
|
| 568 |
|
| 569 |
# Execute in the Wav2Lip directory to resolve relative imports
|
| 570 |
result = subprocess.run(cmd_lipsync, cwd="Wav2Lip", capture_output=True, text=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 571 |
if result.returncode != 0:
|
| 572 |
-
|
| 573 |
-
|
| 574 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 575 |
|
| 576 |
-
print(f"[{video_id}] Wav2Lip alignment completed
|
| 577 |
video_src_for_subtitles = lipsync_output_path
|
| 578 |
else:
|
| 579 |
video_src_for_subtitles = input_video_path
|
|
|
|
| 549 |
print(f"[{video_id}] Exception deleting voice: {del_err}")
|
| 550 |
|
| 551 |
# 5. Merge synthesized audio back with the original video (or run Lip-Sync if selected)
|
| 552 |
+
# NOTE: lipsync_output_path is already defined above using /tmp absolute path — do NOT redefine here.
|
| 553 |
|
| 554 |
if job.has_lip_sync:
|
| 555 |
print(f"[{video_id}] Setting up Wav2Lip model checkpoint files...")
|
|
|
|
| 568 |
|
| 569 |
# Execute in the Wav2Lip directory to resolve relative imports
|
| 570 |
result = subprocess.run(cmd_lipsync, cwd="Wav2Lip", capture_output=True, text=True)
|
| 571 |
+
# Always log stdout/stderr for debugging
|
| 572 |
+
if result.stdout:
|
| 573 |
+
print(f"[{video_id}] Wav2Lip stdout: {result.stdout[-2000:]}")
|
| 574 |
+
if result.stderr:
|
| 575 |
+
print(f"[{video_id}] Wav2Lip stderr: {result.stderr[-2000:]}")
|
| 576 |
if result.returncode != 0:
|
| 577 |
+
raise Exception(f"Wav2Lip inference failed with exit code {result.returncode}: {result.stderr[-500:]}")
|
| 578 |
+
|
| 579 |
+
# Verify Wav2Lip actually wrote the output file (it sometimes exits 0 without writing)
|
| 580 |
+
if not os.path.exists(lipsync_output_path) or os.path.getsize(lipsync_output_path) == 0:
|
| 581 |
+
# Search in Wav2Lip directory in case --outfile was treated as relative
|
| 582 |
+
wav2lip_relative_output = os.path.join("Wav2Lip", f"temp_{video_id}_lipsync.mp4")
|
| 583 |
+
results_default = os.path.join("Wav2Lip", "results", "result_voice.mp4")
|
| 584 |
+
if os.path.exists(wav2lip_relative_output) and os.path.getsize(wav2lip_relative_output) > 0:
|
| 585 |
+
print(f"[{video_id}] WARNING: Wav2Lip wrote to relative path. Moving to expected location.")
|
| 586 |
+
shutil.move(wav2lip_relative_output, lipsync_output_path)
|
| 587 |
+
elif os.path.exists(results_default) and os.path.getsize(results_default) > 0:
|
| 588 |
+
print(f"[{video_id}] WARNING: Wav2Lip wrote to default results path. Copying to expected location.")
|
| 589 |
+
shutil.copy2(results_default, lipsync_output_path)
|
| 590 |
+
else:
|
| 591 |
+
raise Exception(f"Wav2Lip completed (exit 0) but output file not found at: {lipsync_output_path}")
|
| 592 |
|
| 593 |
+
print(f"[{video_id}] Wav2Lip alignment completed. Output size: {os.path.getsize(lipsync_output_path)} bytes")
|
| 594 |
video_src_for_subtitles = lipsync_output_path
|
| 595 |
else:
|
| 596 |
video_src_for_subtitles = input_video_path
|