quantumos commited on
Commit
577110d
·
verified ·
1 Parent(s): e79372a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -40
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
- # Step 1: Extract Keypoints from Video
80
- progress((0,100), desc="Starting...")
81
- logging.info("Demo started")
82
-
83
- kps_sequence_save_path = f"{output_dir}/kps.pth"
84
-
85
- if video is not None:
86
- # Run the script to extract keypoints and audio from the video
87
- progress((25,100), desc="Extract keypoints and audio...")
88
- audio_path = video.replace(".mp4", ".mp3")
89
- logging.info("Extracting keypoints and audio from video")
90
- extract_kps_sequence_from_video(
91
- INFERENCE_ENGINE.app,
92
- video,
93
- audio_path,
94
- kps_sequence_save_path
95
- )
96
-
97
- progress((50,100), desc="Keypoints and audio extracted successfully.")
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
- # Step 2: Run Inference with Reference Image and Audio
109
- # Determine the inference script and parameters based on the selected retargeting strategy
110
- progress(rem_progress, desc="Inference...")
 
 
 
 
 
 
 
 
 
 
111
 
112
- output_path, kps_sequence_save_path = infer(
113
- reference_image, audio_path, kps_sequence_save_path,
114
- output_path,
115
- retarget_strategy,
116
- reference_attention_weight, audio_attention_weight
117
- )
118
 
119
- status = f"Video generated successfully. Saved at: {output_path}"
120
- progress((100,100), desc=status)
121
- return output_path, kps_sequence_save_path
 
 
 
 
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 = [