Spanicin commited on
Commit
4ff6d23
·
verified ·
1 Parent(s): 9f5e724

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +92 -70
app.py CHANGED
@@ -115,89 +115,111 @@ def main(args):
115
  mapping_checkpoint = os.path.join(current_root_path, args.checkpoint_dir, 'mapping_00229-model.pth.tar')
116
  facerender_yaml_path = os.path.join(current_root_path, 'src', 'config', 'facerender.yaml')
117
 
118
- # preprocess_model = CropAndExtract(sadtalker_paths, device)
119
- #init model
120
- print(path_of_net_recon_model)
121
- preprocess_model = CropAndExtract(path_of_lm_croper, path_of_net_recon_model, dir_of_BFM_fitting, device)
122
-
123
- # audio_to_coeff = Audio2Coeff(sadtalker_paths, device)
124
- audio_to_coeff = Audio2Coeff(audio2pose_checkpoint, audio2pose_yaml_path,
125
- audio2exp_checkpoint, audio2exp_yaml_path,
126
- wav2lip_checkpoint, device)
127
- # animate_from_coeff = AnimateFromCoeff(sadtalker_paths, device)
128
- animate_from_coeff = AnimateFromCoeff(free_view_checkpoint, mapping_checkpoint,
129
- facerender_yaml_path, device)
130
-
131
- first_frame_dir = os.path.join(save_dir, 'first_frame_dir')
132
- os.makedirs(first_frame_dir, exist_ok=True)
133
- # first_coeff_path, crop_pic_path, crop_info = preprocess_model.generate(pic_path, first_frame_dir, args.preprocess,\
134
- # source_image_flag=True, pic_size=args.size)
 
 
 
 
135
 
136
-
137
- first_coeff_path, crop_pic_path, crop_info = preprocess_model.generate(pic_path, first_frame_dir, args.preprocess, source_image_flag=True)
138
- print('first_coeff_path ',first_coeff_path)
139
- print('crop_pic_path ',crop_pic_path)
140
-
141
- if first_coeff_path is None:
142
- print("Can't get the coeffs of the input")
143
- return
144
-
145
- if ref_eyeblink is not None:
146
- ref_eyeblink_videoname = os.path.splitext(os.path.split(ref_eyeblink)[-1])[0]
147
- ref_eyeblink_frame_dir = os.path.join(save_dir, ref_eyeblink_videoname)
148
- os.makedirs(ref_eyeblink_frame_dir, exist_ok=True)
149
- # ref_eyeblink_coeff_path, _, _ = preprocess_model.generate(ref_eyeblink, ref_eyeblink_frame_dir, args.preprocess, source_image_flag=False)
150
- ref_eyeblink_coeff_path, _, _ = preprocess_model.generate(ref_eyeblink, ref_eyeblink_frame_dir)
151
- else:
152
- ref_eyeblink_coeff_path=None
153
- print('ref_eyeblink_coeff_path',ref_eyeblink_coeff_path)
154
-
155
- if ref_pose is not None:
156
- if ref_pose == ref_eyeblink:
157
- ref_pose_coeff_path = ref_eyeblink_coeff_path
158
- else:
159
- ref_pose_videoname = os.path.splitext(os.path.split(ref_pose)[-1])[0]
160
- ref_pose_frame_dir = os.path.join(save_dir, ref_pose_videoname)
161
- os.makedirs(ref_pose_frame_dir, exist_ok=True)
162
- # ref_pose_coeff_path, _, _ = preprocess_model.generate(ref_pose, ref_pose_frame_dir, args.preprocess, source_image_flag=False)
163
- ref_pose_coeff_path, _, _ = preprocess_model.generate(ref_pose, ref_pose_frame_dir)
164
- else:
165
- ref_pose_coeff_path=None
166
- print('ref_eyeblink_coeff_path',ref_pose_coeff_path)
167
 
168
- batch = get_data(first_coeff_path, audio_path, device, ref_eyeblink_coeff_path, still=args.still)
169
- coeff_path = audio_to_coeff.generate(batch, save_dir, pose_style, ref_pose_coeff_path)
 
 
 
 
 
170
 
 
 
 
 
171
 
172
- if args.face3dvis:
173
- from src.face3d.visualize import gen_composed_video
174
- gen_composed_video(args, device, first_coeff_path, coeff_path, audio_path, os.path.join(save_dir, '3dface.mp4'))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
175
 
176
- # data = get_facerender_data(coeff_path, crop_pic_path, first_coeff_path, audio_path,
177
- # batch_size, input_yaw_list, input_pitch_list, input_roll_list,
178
- # expression_scale=args.expression_scale, still_mode=args.still, preprocess=args.preprocess, size=args.size)
179
 
180
 
181
- data = get_facerender_data(coeff_path, crop_pic_path, first_coeff_path, audio_path,
182
- batch_size, input_yaw_list, input_pitch_list, input_roll_list,
183
- expression_scale=args.expression_scale, still_mode=args.still, preprocess=args.preprocess)
184
 
185
- # result, base64_video,temp_file_path= animate_from_coeff.generate(data, save_dir, pic_path, crop_info, \
186
- # enhancer=args.enhancer, background_enhancer=args.background_enhancer, preprocess=args.preprocess, img_size=args.size)
187
 
188
 
189
- result, base64_video,temp_file_path = animate_from_coeff.generate(data, save_dir, pic_path, crop_info, \
190
- enhancer=args.enhancer, background_enhancer=args.background_enhancer, preprocess=args.preprocess)
191
 
192
- print('The video is generated')
193
 
194
- video_clip = mp.VideoFileClip(temp_file_path)
195
- duration = video_clip.duration
196
 
197
- app.config['temp_response'] = base64_video
198
- app.config['final_video_path'] = temp_file_path
199
- app.config['final_video_duration'] = duration
200
- return base64_video, temp_file_path, duration
201
 
202
  # shutil.move(result, save_dir+'.mp4')
203
 
 
115
  mapping_checkpoint = os.path.join(current_root_path, args.checkpoint_dir, 'mapping_00229-model.pth.tar')
116
  facerender_yaml_path = os.path.join(current_root_path, 'src', 'config', 'facerender.yaml')
117
 
118
+ face_path = "/home/user/app/images/download_1.mp4" # Replace with the path to your face image or video
119
+ audio_path = "/home/user/app/images/audio_1.mp3" # Replace with the path to your audio file
120
+ temp_file = tempfile.NamedTemporaryFile(delete=False, suffix='.mp4') # You can change suffix based on your file type
121
+ temp_file_path = temp_file.name
122
+ output_path = temp_file_path
123
+
124
+ # Call the function
125
+ inference_function.video_lipsync_correctness(
126
+ face=face_path,
127
+ audio_path=audio_path,
128
+ outfile=output_path,
129
+ tmp_dir="temp",
130
+ crop=[0, -1, 0, -1],
131
+ re_preprocess=True, # Set to True if you want to reprocess; False otherwise
132
+ exp_img="neutral", # Can be 'smile', 'neutral', or path to an expression image
133
+ face3d_net_path="checkpoints/face3d_pretrain_epoch_20.pth",
134
+ one_shot=False,
135
+ up_face="original", # Options: 'original', 'sad', 'angry', 'surprise'
136
+ LNet_batch_size=16,
137
+ without_rl1=False
138
+ )
139
 
140
+ # # preprocess_model = CropAndExtract(sadtalker_paths, device)
141
+ # #init model
142
+ # print(path_of_net_recon_model)
143
+ # preprocess_model = CropAndExtract(path_of_lm_croper, path_of_net_recon_model, dir_of_BFM_fitting, device)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
144
 
145
+ # # audio_to_coeff = Audio2Coeff(sadtalker_paths, device)
146
+ # audio_to_coeff = Audio2Coeff(audio2pose_checkpoint, audio2pose_yaml_path,
147
+ # audio2exp_checkpoint, audio2exp_yaml_path,
148
+ # wav2lip_checkpoint, device)
149
+ # # animate_from_coeff = AnimateFromCoeff(sadtalker_paths, device)
150
+ # animate_from_coeff = AnimateFromCoeff(free_view_checkpoint, mapping_checkpoint,
151
+ # facerender_yaml_path, device)
152
 
153
+ # first_frame_dir = os.path.join(save_dir, 'first_frame_dir')
154
+ # os.makedirs(first_frame_dir, exist_ok=True)
155
+ # # first_coeff_path, crop_pic_path, crop_info = preprocess_model.generate(pic_path, first_frame_dir, args.preprocess,\
156
+ # # source_image_flag=True, pic_size=args.size)
157
 
158
+
159
+ # first_coeff_path, crop_pic_path, crop_info = preprocess_model.generate(pic_path, first_frame_dir, args.preprocess, source_image_flag=True)
160
+ # print('first_coeff_path ',first_coeff_path)
161
+ # print('crop_pic_path ',crop_pic_path)
162
+
163
+ # if first_coeff_path is None:
164
+ # print("Can't get the coeffs of the input")
165
+ # return
166
+
167
+ # if ref_eyeblink is not None:
168
+ # ref_eyeblink_videoname = os.path.splitext(os.path.split(ref_eyeblink)[-1])[0]
169
+ # ref_eyeblink_frame_dir = os.path.join(save_dir, ref_eyeblink_videoname)
170
+ # os.makedirs(ref_eyeblink_frame_dir, exist_ok=True)
171
+ # # ref_eyeblink_coeff_path, _, _ = preprocess_model.generate(ref_eyeblink, ref_eyeblink_frame_dir, args.preprocess, source_image_flag=False)
172
+ # ref_eyeblink_coeff_path, _, _ = preprocess_model.generate(ref_eyeblink, ref_eyeblink_frame_dir)
173
+ # else:
174
+ # ref_eyeblink_coeff_path=None
175
+ # print('ref_eyeblink_coeff_path',ref_eyeblink_coeff_path)
176
+
177
+ # if ref_pose is not None:
178
+ # if ref_pose == ref_eyeblink:
179
+ # ref_pose_coeff_path = ref_eyeblink_coeff_path
180
+ # else:
181
+ # ref_pose_videoname = os.path.splitext(os.path.split(ref_pose)[-1])[0]
182
+ # ref_pose_frame_dir = os.path.join(save_dir, ref_pose_videoname)
183
+ # os.makedirs(ref_pose_frame_dir, exist_ok=True)
184
+ # # ref_pose_coeff_path, _, _ = preprocess_model.generate(ref_pose, ref_pose_frame_dir, args.preprocess, source_image_flag=False)
185
+ # ref_pose_coeff_path, _, _ = preprocess_model.generate(ref_pose, ref_pose_frame_dir)
186
+ # else:
187
+ # ref_pose_coeff_path=None
188
+ # print('ref_eyeblink_coeff_path',ref_pose_coeff_path)
189
+
190
+ # batch = get_data(first_coeff_path, audio_path, device, ref_eyeblink_coeff_path, still=args.still)
191
+ # coeff_path = audio_to_coeff.generate(batch, save_dir, pose_style, ref_pose_coeff_path)
192
+
193
+
194
+ # if args.face3dvis:
195
+ # from src.face3d.visualize import gen_composed_video
196
+ # gen_composed_video(args, device, first_coeff_path, coeff_path, audio_path, os.path.join(save_dir, '3dface.mp4'))
197
 
198
+ # # data = get_facerender_data(coeff_path, crop_pic_path, first_coeff_path, audio_path,
199
+ # # batch_size, input_yaw_list, input_pitch_list, input_roll_list,
200
+ # # expression_scale=args.expression_scale, still_mode=args.still, preprocess=args.preprocess, size=args.size)
201
 
202
 
203
+ # data = get_facerender_data(coeff_path, crop_pic_path, first_coeff_path, audio_path,
204
+ # batch_size, input_yaw_list, input_pitch_list, input_roll_list,
205
+ # expression_scale=args.expression_scale, still_mode=args.still, preprocess=args.preprocess)
206
 
207
+ # # result, base64_video,temp_file_path= animate_from_coeff.generate(data, save_dir, pic_path, crop_info, \
208
+ # # enhancer=args.enhancer, background_enhancer=args.background_enhancer, preprocess=args.preprocess, img_size=args.size)
209
 
210
 
211
+ # result, base64_video,temp_file_path = animate_from_coeff.generate(data, save_dir, pic_path, crop_info, \
212
+ # enhancer=args.enhancer, background_enhancer=args.background_enhancer, preprocess=args.preprocess)
213
 
214
+ # print('The video is generated')
215
 
216
+ # video_clip = mp.VideoFileClip(temp_file_path)
217
+ # duration = video_clip.duration
218
 
219
+ # app.config['temp_response'] = base64_video
220
+ # app.config['final_video_path'] = temp_file_path
221
+ # app.config['final_video_duration'] = duration
222
+ # return base64_video, temp_file_path, duration
223
 
224
  # shutil.move(result, save_dir+'.mp4')
225