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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -20
app.py CHANGED
@@ -70,19 +70,12 @@ def infer(reference_image, audio_path, kps_sequence_save_path, output_path, reta
70
  return None, None
71
 
72
  # Function to run V-Express demo
73
- def run_demo(
74
- reference_image, audio, video,
75
- kps_path, output_path, retarget_strategy,
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...")
@@ -94,33 +87,26 @@ def run_demo(
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
 
70
  return None, None
71
 
72
  # Function to run V-Express demo
73
+ 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()):
 
 
 
 
 
74
  try:
75
  # Step 1: Extract Keypoints from Video
76
  progress((0,100), desc="Starting...")
77
+ logging.info("Demo started")
78
+ kps_sequence_save_path = f"{output_dir}/kps.pth"
 
 
79
  if video is not None:
80
  # Run the script to extract keypoints and audio from the video
81
  progress((25,100), desc="Extract keypoints and audio...")
 
87
  else:
88
  rem_progress = (50,100)
89
  audio_path = audio
90
+ shutil.copy(kps_path.name, kps_sequence_save_path)
 
91
  subprocess.run(["ffmpeg", "-i", audio_path, "-c:v", "libx264", "-crf", "18", "-preset", "slow", temp_audio_path])
92
  shutil.move(temp_audio_path, audio_path)
93
+ progress(rem_progress, desc="Inference...")
 
 
 
 
94
  output_path, kps_sequence_save_path = infer(
95
  reference_image, audio_path, kps_sequence_save_path,
96
  output_path,
97
  retarget_strategy,
98
  reference_attention_weight, audio_attention_weight
99
  )
 
100
  if output_path and kps_sequence_save_path:
101
  status = f"Video generated successfully. Saved at: {output_path}"
102
  logging.info(status)
103
  else:
104
  status = "Failed to generate video."
105
  logging.error(status)
 
106
  status = f"Video generated successfully. Saved at: {output_path}"
107
  progress((100,100), desc=status)
108
  return output_path, kps_sequence_save_path
109
+ except Exception as e:
110
  logging.error(f"Demo failed: {e}")
111
  progress((100, 100), desc="Error occurred")
112
  return None, None