Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -99,10 +99,10 @@ audio2exp_yaml_path = os.path.join(current_root_path, 'src', 'config', 'auido2ex
|
|
99 |
free_view_checkpoint = os.path.join(current_root_path, 'checkpoints', 'facevid2vid_00189-model.pth.tar')
|
100 |
|
101 |
# Function for running the actual task (using preprocessed data)
|
102 |
-
def process_chunk(audio_chunk, args):
|
103 |
print("Entered Process Chunk Function")
|
104 |
global audio2pose_checkpoint, audio2pose_yaml_path, audio2exp_checkpoint, audio2exp_yaml_path, wav2lip_checkpoint
|
105 |
-
global path_of_lm_croper, path_of_net_recon_model, dir_of_BFM_fitting
|
106 |
global free_view_checkpoint
|
107 |
if args.preprocess == 'full':
|
108 |
mapping_checkpoint = os.path.join(current_root_path, 'checkpoints', 'mapping_00109-model.pth.tar')
|
@@ -111,16 +111,16 @@ def process_chunk(audio_chunk, args):
|
|
111 |
mapping_checkpoint = os.path.join(current_root_path, 'checkpoints', 'mapping_00229-model.pth.tar')
|
112 |
facerender_yaml_path = os.path.join(current_root_path, 'src', 'config', 'facerender.yaml')
|
113 |
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
|
120 |
-
first_frame_dir = os.path.join(args.result_dir, 'first_frame_dir')
|
121 |
-
os.makedirs(first_frame_dir, exist_ok=True)
|
122 |
-
preprocess_model = CropAndExtract(path_of_lm_croper, path_of_net_recon_model, dir_of_BFM_fitting, args.device)
|
123 |
-
first_coeff_path, crop_pic_path, crop_info = preprocess_model.generate(args.source_image, first_frame_dir, args.preprocess, source_image_flag=True)
|
124 |
|
125 |
print(f"Loaded existing preprocessed data")
|
126 |
print("first_coeff_path",first_coeff_path)
|
@@ -228,10 +228,10 @@ def generate_audio(voice_cloning, voice_gender, text_prompt):
|
|
228 |
elif voice_cloning == 'yes':
|
229 |
set_api_key('92e149985ea2732b4359c74346c3daee')
|
230 |
user_voice_path = '/home/user/app/images/AUDIO-2024-10-04-09-51-34.m4a'
|
231 |
-
voice = clone(name = "User Cloned Voice",
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
|
236 |
audio = generate(text = text_prompt, voice = voice, model = "eleven_multilingual_v2",stream=True, latency=4)
|
237 |
with tempfile.NamedTemporaryFile(suffix=".mp3", prefix="cloned_audio_",dir=TEMP_DIR.name, delete=False) as temp_file:
|
@@ -271,7 +271,7 @@ def generate_video():
|
|
271 |
try:
|
272 |
if request.method == 'POST':
|
273 |
# source_image = request.files['source_image']
|
274 |
-
image_path = '/home/user/app/images/
|
275 |
source_image = Image.open(image_path)
|
276 |
text_prompt = request.form['text_prompt']
|
277 |
|
@@ -336,8 +336,8 @@ def generate_video():
|
|
336 |
|
337 |
|
338 |
try:
|
339 |
-
|
340 |
-
base64_video, temp_file_path = process_chunk(driven_audio_path, args)
|
341 |
final_video_path = app.config['final_video_path']
|
342 |
print('final_video_path',final_video_path)
|
343 |
|
|
|
99 |
free_view_checkpoint = os.path.join(current_root_path, 'checkpoints', 'facevid2vid_00189-model.pth.tar')
|
100 |
|
101 |
# Function for running the actual task (using preprocessed data)
|
102 |
+
def process_chunk(audio_chunk, args, preprocessed_data):
|
103 |
print("Entered Process Chunk Function")
|
104 |
global audio2pose_checkpoint, audio2pose_yaml_path, audio2exp_checkpoint, audio2exp_yaml_path, wav2lip_checkpoint
|
105 |
+
# global path_of_lm_croper, path_of_net_recon_model, dir_of_BFM_fitting
|
106 |
global free_view_checkpoint
|
107 |
if args.preprocess == 'full':
|
108 |
mapping_checkpoint = os.path.join(current_root_path, 'checkpoints', 'mapping_00109-model.pth.tar')
|
|
|
111 |
mapping_checkpoint = os.path.join(current_root_path, 'checkpoints', 'mapping_00229-model.pth.tar')
|
112 |
facerender_yaml_path = os.path.join(current_root_path, 'src', 'config', 'facerender.yaml')
|
113 |
|
114 |
+
first_coeff_path = preprocessed_data["first_coeff_path"]
|
115 |
+
crop_pic_path = preprocessed_data["crop_pic_path"]
|
116 |
+
crop_info_path = "/home/user/app/preprocess_data/crop_info.json"
|
117 |
+
with open(crop_info_path , "rb") as f:
|
118 |
+
crop_info = json.load(f)
|
119 |
|
120 |
+
# first_frame_dir = os.path.join(args.result_dir, 'first_frame_dir')
|
121 |
+
# os.makedirs(first_frame_dir, exist_ok=True)
|
122 |
+
# preprocess_model = CropAndExtract(path_of_lm_croper, path_of_net_recon_model, dir_of_BFM_fitting, args.device)
|
123 |
+
# first_coeff_path, crop_pic_path, crop_info = preprocess_model.generate(args.source_image, first_frame_dir, args.preprocess, source_image_flag=True)
|
124 |
|
125 |
print(f"Loaded existing preprocessed data")
|
126 |
print("first_coeff_path",first_coeff_path)
|
|
|
228 |
elif voice_cloning == 'yes':
|
229 |
set_api_key('92e149985ea2732b4359c74346c3daee')
|
230 |
user_voice_path = '/home/user/app/images/AUDIO-2024-10-04-09-51-34.m4a'
|
231 |
+
# voice = clone(name = "User Cloned Voice",
|
232 |
+
# files = [user_voice_path] )
|
233 |
+
voice = Voice(voice_id="DeZH4ash9IU9gUcNjVXh",name="Marc",settings=VoiceSettings(
|
234 |
+
stability=0.71, similarity_boost=0.5, style=0.0, use_speaker_boost=True),)
|
235 |
|
236 |
audio = generate(text = text_prompt, voice = voice, model = "eleven_multilingual_v2",stream=True, latency=4)
|
237 |
with tempfile.NamedTemporaryFile(suffix=".mp3", prefix="cloned_audio_",dir=TEMP_DIR.name, delete=False) as temp_file:
|
|
|
271 |
try:
|
272 |
if request.method == 'POST':
|
273 |
# source_image = request.files['source_image']
|
274 |
+
image_path = '/home/user/app/images/marc_smile_enhanced.jpg'
|
275 |
source_image = Image.open(image_path)
|
276 |
text_prompt = request.form['text_prompt']
|
277 |
|
|
|
336 |
|
337 |
|
338 |
try:
|
339 |
+
preprocessed_data = run_preprocessing(args)
|
340 |
+
base64_video, temp_file_path = process_chunk(driven_audio_path, args, preprocessed_data)
|
341 |
final_video_path = app.config['final_video_path']
|
342 |
print('final_video_path',final_video_path)
|
343 |
|