Update app.py
Browse files
app.py
CHANGED
|
@@ -76,49 +76,54 @@ def run_demo(
|
|
| 76 |
reference_attention_weight=0.95,
|
| 77 |
audio_attention_weight=3.0,
|
| 78 |
progress=gr.Progress()):
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
#return "Keypoints and audio extracted successfully."
|
| 99 |
-
rem_progress = (75,100)
|
| 100 |
-
else:
|
| 101 |
-
rem_progress = (50,100)
|
| 102 |
-
audio_path = audio
|
| 103 |
-
shutil.copy(kps_path.name, kps_sequence_save_path)
|
| 104 |
-
|
| 105 |
-
subprocess.run(["ffmpeg", "-i", audio_path, "-c:v", "libx264", "-crf", "18", "-preset", "slow", temp_audio_path])
|
| 106 |
-
shutil.move(temp_audio_path, audio_path)
|
| 107 |
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
|
| 123 |
# Create Gradio interface
|
| 124 |
inputs = [
|
|
|
|
| 76 |
reference_attention_weight=0.95,
|
| 77 |
audio_attention_weight=3.0,
|
| 78 |
progress=gr.Progress()):
|
| 79 |
+
try:
|
| 80 |
+
# Step 1: Extract Keypoints from Video
|
| 81 |
+
progress((0,100), desc="Starting...")
|
| 82 |
+
logging.info("Demo started")
|
| 83 |
+
|
| 84 |
+
kps_sequence_save_path = f"{output_dir}/kps.pth"
|
| 85 |
+
|
| 86 |
+
if video is not None:
|
| 87 |
+
# Run the script to extract keypoints and audio from the video
|
| 88 |
+
progress((25,100), desc="Extract keypoints and audio...")
|
| 89 |
+
audio_path = video.replace(".mp4", ".mp3")
|
| 90 |
+
logging.info("Extracting keypoints and audio from video")
|
| 91 |
+
progress((50,100), desc="Keypoints and audio extracted successfully.")
|
| 92 |
+
#return "Keypoints and audio extracted successfully."
|
| 93 |
+
rem_progress = (75,100)
|
| 94 |
+
else:
|
| 95 |
+
rem_progress = (50,100)
|
| 96 |
+
audio_path = audio
|
| 97 |
+
shutil.copy(kps_path.name, kps_sequence_save_path)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
|
| 99 |
+
subprocess.run(["ffmpeg", "-i", audio_path, "-c:v", "libx264", "-crf", "18", "-preset", "slow", temp_audio_path])
|
| 100 |
+
shutil.move(temp_audio_path, audio_path)
|
| 101 |
+
|
| 102 |
+
# Step 2: Run Inference with Reference Image and Audio
|
| 103 |
+
# Determine the inference script and parameters based on the selected retargeting strategy
|
| 104 |
+
progress(rem_progress, desc="Inference...")
|
| 105 |
+
|
| 106 |
+
output_path, kps_sequence_save_path = infer(
|
| 107 |
+
reference_image, audio_path, kps_sequence_save_path,
|
| 108 |
+
output_path,
|
| 109 |
+
retarget_strategy,
|
| 110 |
+
reference_attention_weight, audio_attention_weight
|
| 111 |
+
)
|
| 112 |
|
| 113 |
+
if output_path and kps_sequence_save_path:
|
| 114 |
+
status = f"Video generated successfully. Saved at: {output_path}"
|
| 115 |
+
logging.info(status)
|
| 116 |
+
else:
|
| 117 |
+
status = "Failed to generate video."
|
| 118 |
+
logging.error(status)
|
| 119 |
|
| 120 |
+
status = f"Video generated successfully. Saved at: {output_path}"
|
| 121 |
+
progress((100,100), desc=status)
|
| 122 |
+
return output_path, kps_sequence_save_path
|
| 123 |
+
except Exception as e:
|
| 124 |
+
logging.error(f"Demo failed: {e}")
|
| 125 |
+
progress((100, 100), desc="Error occurred")
|
| 126 |
+
return None, None
|
| 127 |
|
| 128 |
# Create Gradio interface
|
| 129 |
inputs = [
|