artificialguybr commited on
Commit
349cabe
β€’
1 Parent(s): d0817ad

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -4
app.py CHANGED
@@ -115,9 +115,15 @@ def process_video(radio, video, target_language, has_closeup_face):
115
  else:
116
  has_face = check_for_faces(video_path)
117
 
118
- if has_face:
119
- cmd = f"python Wav2Lip/inference.py --checkpoint_path 'Wav2Lip/checkpoints/wav2lip_gan.pth' --face {shlex.quote(video_path)} --audio '{run_uuid}_output_synth.wav' --pads {pad_top} {pad_bottom} {pad_left} {pad_right} --resize_factor {rescaleFactor} --nosmooth --outfile '{run_uuid}_output_video.mp4'"
120
- subprocess.run(cmd, shell=True)
 
 
 
 
 
 
121
  else:
122
  # Merge audio with the original video without running Wav2Lip
123
  cmd = f"ffmpeg -i {video_path} -i {run_uuid}_output_synth.wav -c:v copy -c:a aac -strict experimental -map 0:v:0 -map 1:a:0 {run_uuid}_output_video.mp4"
@@ -159,7 +165,7 @@ iface = gr.Interface(
159
  video,
160
  gr.Dropdown(choices=["English", "Spanish", "French", "German", "Italian", "Portuguese", "Polish", "Turkish", "Russian", "Dutch", "Czech", "Arabic", "Chinese (Simplified)"], label="Target Language for Dubbing", value="Spanish"),
161
  gr.Checkbox(
162
- label="Video has a close-up face",
163
  value=False,
164
  info="Say if video have close-up face. For Wav2lip. Will not work if checked wrongly.")
165
  ],
 
115
  else:
116
  has_face = check_for_faces(video_path)
117
 
118
+ if has_closeup_face:
119
+ try:
120
+ cmd = f"python Wav2Lip/inference.py --checkpoint_path 'Wav2Lip/checkpoints/wav2lip_gan.pth' --face {shlex.quote(video_path)} --audio '{run_uuid}_output_synth.wav' --pads {pad_top} {pad_bottom} {pad_left} {pad_right} --resize_factor {rescaleFactor} --nosmooth --outfile '{run_uuid}_output_video.mp4'"
121
+ subprocess.run(cmd, shell=True, check=True)
122
+ except subprocess.CalledProcessError as e:
123
+ if "Face not detected! Ensure the video contains a face in all the frames." in str(e.stderr):
124
+ # Fallback to FFmpeg merge
125
+ cmd = f"ffmpeg -i {video_path} -i {run_uuid}_output_synth.wav -c:v copy -c:a aac -strict experimental -map 0:v:0 -map 1:a:0 {run_uuid}_output_video.mp4"
126
+ subprocess.run(cmd, shell=True)
127
  else:
128
  # Merge audio with the original video without running Wav2Lip
129
  cmd = f"ffmpeg -i {video_path} -i {run_uuid}_output_synth.wav -c:v copy -c:a aac -strict experimental -map 0:v:0 -map 1:a:0 {run_uuid}_output_video.mp4"
 
165
  video,
166
  gr.Dropdown(choices=["English", "Spanish", "French", "German", "Italian", "Portuguese", "Polish", "Turkish", "Russian", "Dutch", "Czech", "Arabic", "Chinese (Simplified)"], label="Target Language for Dubbing", value="Spanish"),
167
  gr.Checkbox(
168
+ label="Video has a close-up face. Use Wav2lip.",
169
  value=False,
170
  info="Say if video have close-up face. For Wav2lip. Will not work if checked wrongly.")
171
  ],