Update app.py
Browse files
app.py
CHANGED
|
@@ -59,6 +59,11 @@ def infer(reference_image, audio_path, kps_sequence_save_path, output_path, reta
|
|
| 59 |
except Exception as e:
|
| 60 |
logging.error(f"Inference failed: {e}")
|
| 61 |
return None, None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
|
| 63 |
def run_demo(reference_image, audio, video, kps_path, output_path, retarget_strategy, reference_attention_weight=0.95, audio_attention_weight=3.0, progress=gr.Progress()):
|
| 64 |
try:
|
|
@@ -71,14 +76,28 @@ def run_demo(reference_image, audio, video, kps_path, output_path, retarget_stra
|
|
| 71 |
progress((25, 100), desc="Extracting keypoints and audio...")
|
| 72 |
logging.info("Extracting keypoints and audio from video")
|
| 73 |
audio_path = video.replace(".mp4", ".mp3")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
extract_kps_sequence_from_video(
|
| 75 |
INFERENCE_ENGINE.app,
|
| 76 |
video,
|
| 77 |
audio_path,
|
| 78 |
kps_sequence_save_path
|
| 79 |
)
|
|
|
|
| 80 |
progress((50, 100), desc="Keypoints and audio extracted successfully.")
|
| 81 |
-
rem_progress = (75, 100)
|
|
|
|
| 82 |
else:
|
| 83 |
rem_progress = (50, 100)
|
| 84 |
audio_path = audio
|
|
@@ -88,6 +107,10 @@ def run_demo(reference_image, audio, video, kps_path, output_path, retarget_stra
|
|
| 88 |
shutil.move(temp_audio_path, audio_path)
|
| 89 |
|
| 90 |
progress(rem_progress, desc="Running inference...")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
output_path, kps_sequence_save_path = infer(
|
| 92 |
reference_image, audio_path, kps_sequence_save_path,
|
| 93 |
output_path,
|
|
|
|
| 59 |
except Exception as e:
|
| 60 |
logging.error(f"Inference failed: {e}")
|
| 61 |
return None, None
|
| 62 |
+
|
| 63 |
+
def process_video(args):
|
| 64 |
+
app, video, audio_path, kps_sequence_save_path = args
|
| 65 |
+
extract_kps_sequence_from_video(app, video, audio_path, kps_sequence_save_path)
|
| 66 |
+
return audio_path, kps_sequence_save_path
|
| 67 |
|
| 68 |
def run_demo(reference_image, audio, video, kps_path, output_path, retarget_strategy, reference_attention_weight=0.95, audio_attention_weight=3.0, progress=gr.Progress()):
|
| 69 |
try:
|
|
|
|
| 76 |
progress((25, 100), desc="Extracting keypoints and audio...")
|
| 77 |
logging.info("Extracting keypoints and audio from video")
|
| 78 |
audio_path = video.replace(".mp4", ".mp3")
|
| 79 |
+
|
| 80 |
+
# Use multiprocessing for video processing
|
| 81 |
+
with Pool(processes=1) as pool:
|
| 82 |
+
audio_path, kps_sequence_save_path = pool.map(process_video, [(INFERENCE_ENGINE.app, video, audio_path, kps_sequence_save_path)])[0]
|
| 83 |
+
|
| 84 |
+
progress((50, 100), desc="Keypoints and audio extracted successfully.")
|
| 85 |
+
rem_progress = (75, 100)
|
| 86 |
+
|
| 87 |
+
"""if video is not None:
|
| 88 |
+
progress((25, 100), desc="Extracting keypoints and audio...")
|
| 89 |
+
logging.info("Extracting keypoints and audio from video")
|
| 90 |
+
audio_path = video.replace(".mp4", ".mp3")
|
| 91 |
extract_kps_sequence_from_video(
|
| 92 |
INFERENCE_ENGINE.app,
|
| 93 |
video,
|
| 94 |
audio_path,
|
| 95 |
kps_sequence_save_path
|
| 96 |
)
|
| 97 |
+
|
| 98 |
progress((50, 100), desc="Keypoints and audio extracted successfully.")
|
| 99 |
+
rem_progress = (75, 100)*/
|
| 100 |
+
"""
|
| 101 |
else:
|
| 102 |
rem_progress = (50, 100)
|
| 103 |
audio_path = audio
|
|
|
|
| 107 |
shutil.move(temp_audio_path, audio_path)
|
| 108 |
|
| 109 |
progress(rem_progress, desc="Running inference...")
|
| 110 |
+
|
| 111 |
+
# Clear CUDA cache before inference
|
| 112 |
+
torch.cuda.empty_cache()
|
| 113 |
+
|
| 114 |
output_path, kps_sequence_save_path = infer(
|
| 115 |
reference_image, audio_path, kps_sequence_save_path,
|
| 116 |
output_path,
|