Spanicin commited on
Commit
18c0bae
·
verified ·
1 Parent(s): dd6f240

Update app_parallel.py

Browse files
Files changed (1) hide show
  1. app_parallel.py +18 -15
app_parallel.py CHANGED
@@ -109,7 +109,7 @@ def process_chunk(audio_chunk, preprocessed_data, args):
109
 
110
  first_coeff_path = preprocessed_data["first_coeff_path"]
111
  crop_pic_path = preprocessed_data["crop_pic_path"]
112
- crop_info_path = preprocessed_data["crop_info"]
113
  with open(crop_info_path , "rb") as f:
114
  crop_info = pickle.load(f)
115
 
@@ -220,39 +220,42 @@ def generate_audio(voice_cloning, voice_gender, text_prompt):
220
 
221
  return driven_audio_path
222
 
223
- # Preprocessing step that runs only once
224
  def run_preprocessing(args):
225
  global path_of_lm_croper, path_of_net_recon_model, dir_of_BFM_fitting
226
- first_frame_dir = os.path.join(args.result_dir, 'first_frame_dir')
227
- os.makedirs(first_frame_dir, exist_ok=True)
228
-
229
- # Check if preprocessed data already exists
230
- fixed_temp_dir = "C:/Users/fd01076/Downloads/preprocess_data"
231
  os.makedirs(fixed_temp_dir, exist_ok=True)
232
  preprocessed_data_path = os.path.join(fixed_temp_dir, "preprocessed_data.pkl")
233
 
234
  if os.path.exists(preprocessed_data_path) and args.image_hardcoded == "yes":
 
235
  with open(preprocessed_data_path, "rb") as f:
236
  preprocessed_data = pickle.load(f)
237
  print("Loaded existing preprocessed data from:", preprocessed_data_path)
238
  else:
 
239
  preprocess_model = CropAndExtract(path_of_lm_croper, path_of_net_recon_model, dir_of_BFM_fitting, args.device)
240
  first_coeff_path, crop_pic_path, crop_info = preprocess_model.generate(args.source_image, first_frame_dir, args.preprocess, source_image_flag=True)
 
 
 
 
 
 
 
 
 
 
 
 
241
 
242
- if not first_coeff_path:
243
- raise Exception("Failed to get coefficients")
244
 
245
- # Save the preprocessed data
246
- preprocessed_data = {
247
- "first_coeff_path": first_coeff_path,
248
- "crop_pic_path": crop_pic_path,
249
- "crop_info": crop_info
250
- }
251
  with open(preprocessed_data_path, "wb") as f:
252
  pickle.dump(preprocessed_data, f)
 
253
 
254
  return preprocessed_data
255
 
 
256
  client = OpenAI(api_key="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")
257
 
258
  def openai_chat_avatar(text_prompt):
 
109
 
110
  first_coeff_path = preprocessed_data["first_coeff_path"]
111
  crop_pic_path = preprocessed_data["crop_pic_path"]
112
+ crop_info_path = preprocessed_data["crop_info_path"]
113
  with open(crop_info_path , "rb") as f:
114
  crop_info = pickle.load(f)
115
 
 
220
 
221
  return driven_audio_path
222
 
 
223
  def run_preprocessing(args):
224
  global path_of_lm_croper, path_of_net_recon_model, dir_of_BFM_fitting
225
+ fixed_temp_dir = "/tmp/preprocess_data"
 
 
 
 
226
  os.makedirs(fixed_temp_dir, exist_ok=True)
227
  preprocessed_data_path = os.path.join(fixed_temp_dir, "preprocessed_data.pkl")
228
 
229
  if os.path.exists(preprocessed_data_path) and args.image_hardcoded == "yes":
230
+ print("Loading preprocessed data...")
231
  with open(preprocessed_data_path, "rb") as f:
232
  preprocessed_data = pickle.load(f)
233
  print("Loaded existing preprocessed data from:", preprocessed_data_path)
234
  else:
235
+ print("Running preprocessing...")
236
  preprocess_model = CropAndExtract(path_of_lm_croper, path_of_net_recon_model, dir_of_BFM_fitting, args.device)
237
  first_coeff_path, crop_pic_path, crop_info = preprocess_model.generate(args.source_image, first_frame_dir, args.preprocess, source_image_flag=True)
238
+ first_coeff_new_path = os.path.join(fixed_temp_dir, os.path.basename(first_coeff_path))
239
+ crop_pic_new_path = os.path.join(fixed_temp_dir, os.path.basename(crop_pic_path))
240
+ crop_info_new_path = os.path.join(fixed_temp_dir, "crop_info.pkl")
241
+ shutil.move(first_coeff_path, first_coeff_new_path)
242
+ shutil.move(crop_pic_path, crop_pic_new_path)
243
+
244
+ with open(crop_info_new_path, "wb") as f:
245
+ pickle.dump(crop_info, f)
246
+
247
+ preprocessed_data = {"first_coeff_path": first_coeff_new_path,
248
+ "crop_pic_path": crop_pic_new_path,
249
+ "crop_info_path": crop_info_new_path}
250
 
 
 
251
 
 
 
 
 
 
 
252
  with open(preprocessed_data_path, "wb") as f:
253
  pickle.dump(preprocessed_data, f)
254
+ print(f"Preprocessed data saved to: {preprocessed_data_path}")
255
 
256
  return preprocessed_data
257
 
258
+
259
  client = OpenAI(api_key="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")
260
 
261
  def openai_chat_avatar(text_prompt):