Spaces:
Build error
Build error
artificialguybr
commited on
Commit
•
4fe6158
1
Parent(s):
5fe7517
Update app.py
Browse files
app.py
CHANGED
@@ -71,7 +71,8 @@ def check_for_faces(video_path):
|
|
71 |
if not ret:
|
72 |
break
|
73 |
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
|
74 |
-
|
|
|
75 |
return True
|
76 |
return False
|
77 |
|
@@ -158,18 +159,19 @@ def process_video(radio, video, target_language, has_closeup_face):
|
|
158 |
target_language_code, voice = language_mapping[target_language]
|
159 |
translator = Translator()
|
160 |
translated_text = translator.translate(whisper_text, dest=target_language_code).text
|
161 |
-
print(translated_text)
|
162 |
|
163 |
asyncio.run(text_to_speech(translated_text, voice, f"{run_uuid}_output_synth.wav"))
|
164 |
|
165 |
if has_closeup_face or check_for_faces(video_path):
|
166 |
try:
|
167 |
subprocess.run(f"python Wav2Lip/inference.py --checkpoint_path 'Wav2Lip/checkpoints/wav2lip_gan.pth' --face '{video_path}' --audio '{run_uuid}_output_synth.wav' --pads 0 15 0 0 --resize_factor 1 --nosmooth --outfile '{run_uuid}_output_video.mp4'", shell=True, check=True)
|
168 |
-
except subprocess.CalledProcessError:
|
169 |
-
|
170 |
-
|
|
|
171 |
else:
|
172 |
-
subprocess.run(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", shell=True)
|
173 |
|
174 |
output_video_path = f"{run_uuid}_output_video.mp4"
|
175 |
if not os.path.exists(output_video_path):
|
|
|
71 |
if not ret:
|
72 |
break
|
73 |
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
|
74 |
+
faces = face_cascade.detectMultiScale(gray, 1.1, 4)
|
75 |
+
if len(faces) > 0:
|
76 |
return True
|
77 |
return False
|
78 |
|
|
|
159 |
target_language_code, voice = language_mapping[target_language]
|
160 |
translator = Translator()
|
161 |
translated_text = translator.translate(whisper_text, dest=target_language_code).text
|
162 |
+
print(f"Translated text: {translated_text}")
|
163 |
|
164 |
asyncio.run(text_to_speech(translated_text, voice, f"{run_uuid}_output_synth.wav"))
|
165 |
|
166 |
if has_closeup_face or check_for_faces(video_path):
|
167 |
try:
|
168 |
subprocess.run(f"python Wav2Lip/inference.py --checkpoint_path 'Wav2Lip/checkpoints/wav2lip_gan.pth' --face '{video_path}' --audio '{run_uuid}_output_synth.wav' --pads 0 15 0 0 --resize_factor 1 --nosmooth --outfile '{run_uuid}_output_video.mp4'", shell=True, check=True)
|
169 |
+
except subprocess.CalledProcessError as e:
|
170 |
+
print(f"Wav2Lip error: {str(e)}")
|
171 |
+
gr.Warning("Wav2lip didn't detect a face or encountered an error. Falling back to simple audio replacement.")
|
172 |
+
subprocess.run(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", shell=True, check=True)
|
173 |
else:
|
174 |
+
subprocess.run(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", shell=True, check=True)
|
175 |
|
176 |
output_video_path = f"{run_uuid}_output_video.mp4"
|
177 |
if not os.path.exists(output_video_path):
|