Spaces:
Running
on
Zero
Running
on
Zero
add gfpgan
Browse files- src/facerender/animate.py +16 -15
- src/facerender/pirender_animate.py +16 -15
- src/utils/face_enhancer.py +1 -1
src/facerender/animate.py
CHANGED
@@ -20,6 +20,7 @@ from src.facerender.modules.generator import OcclusionAwareGenerator, OcclusionA
|
|
20 |
from src.facerender.modules.make_animation import make_animation
|
21 |
|
22 |
from pydub import AudioSegment
|
|
|
23 |
from src.utils.paste_pic import paste_pic
|
24 |
from src.utils.videoio import save_video_with_watermark
|
25 |
|
@@ -232,22 +233,22 @@ class AnimateFromCoeff():
|
|
232 |
full_video_path = av_path
|
233 |
|
234 |
#### paste back then enhancers
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
|
252 |
os.remove(path)
|
253 |
os.remove(new_audio_path)
|
|
|
20 |
from src.facerender.modules.make_animation import make_animation
|
21 |
|
22 |
from pydub import AudioSegment
|
23 |
+
from src.utils.face_enhancer import enhancer_generator_with_len, enhancer_list
|
24 |
from src.utils.paste_pic import paste_pic
|
25 |
from src.utils.videoio import save_video_with_watermark
|
26 |
|
|
|
233 |
full_video_path = av_path
|
234 |
|
235 |
#### paste back then enhancers
|
236 |
+
if enhancer:
|
237 |
+
video_name_enhancer = x['video_name'] + '_enhanced.mp4'
|
238 |
+
enhanced_path = os.path.join(video_save_dir, 'temp_'+video_name_enhancer)
|
239 |
+
av_path_enhancer = os.path.join(video_save_dir, video_name_enhancer)
|
240 |
+
return_path = av_path_enhancer
|
241 |
+
|
242 |
+
try:
|
243 |
+
enhanced_images_gen_with_len = enhancer_generator_with_len(full_video_path, method=enhancer, bg_upsampler=background_enhancer)
|
244 |
+
imageio.mimsave(enhanced_path, enhanced_images_gen_with_len, fps=float(25))
|
245 |
+
except:
|
246 |
+
enhanced_images_gen_with_len = enhancer_list(full_video_path, method=enhancer, bg_upsampler=background_enhancer)
|
247 |
+
imageio.mimsave(enhanced_path, enhanced_images_gen_with_len, fps=float(25))
|
248 |
|
249 |
+
save_video_with_watermark(enhanced_path, new_audio_path, av_path_enhancer, watermark= False)
|
250 |
+
print(f'The generated video is named {video_save_dir}/{video_name_enhancer}')
|
251 |
+
os.remove(enhanced_path)
|
252 |
|
253 |
os.remove(path)
|
254 |
os.remove(new_audio_path)
|
src/facerender/pirender_animate.py
CHANGED
@@ -17,6 +17,7 @@ from src.facerender.pirender.config import Config
|
|
17 |
from src.facerender.pirender.face_model import FaceGenerator
|
18 |
|
19 |
from pydub import AudioSegment
|
|
|
20 |
from src.utils.paste_pic import paste_pic
|
21 |
from src.utils.videoio import save_video_with_watermark
|
22 |
|
@@ -105,22 +106,22 @@ class AnimateFromCoeff_PIRender():
|
|
105 |
full_video_path = av_path
|
106 |
|
107 |
#### paste back then enhancers
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
|
125 |
os.remove(path)
|
126 |
os.remove(new_audio_path)
|
|
|
17 |
from src.facerender.pirender.face_model import FaceGenerator
|
18 |
|
19 |
from pydub import AudioSegment
|
20 |
+
from src.utils.face_enhancer import enhancer_generator_with_len, enhancer_list
|
21 |
from src.utils.paste_pic import paste_pic
|
22 |
from src.utils.videoio import save_video_with_watermark
|
23 |
|
|
|
106 |
full_video_path = av_path
|
107 |
|
108 |
#### paste back then enhancers
|
109 |
+
if enhancer:
|
110 |
+
video_name_enhancer = x['video_name'] + '_enhanced.mp4'
|
111 |
+
enhanced_path = os.path.join(video_save_dir, 'temp_'+video_name_enhancer)
|
112 |
+
av_path_enhancer = os.path.join(video_save_dir, video_name_enhancer)
|
113 |
+
return_path = av_path_enhancer
|
114 |
+
|
115 |
+
try:
|
116 |
+
enhanced_images_gen_with_len = enhancer_generator_with_len(full_video_path, method=enhancer, bg_upsampler=background_enhancer)
|
117 |
+
imageio.mimsave(enhanced_path, enhanced_images_gen_with_len, fps=float(25))
|
118 |
+
except:
|
119 |
+
enhanced_images_gen_with_len = enhancer_list(full_video_path, method=enhancer, bg_upsampler=background_enhancer)
|
120 |
+
imageio.mimsave(enhanced_path, enhanced_images_gen_with_len, fps=float(25))
|
121 |
|
122 |
+
save_video_with_watermark(enhanced_path, new_audio_path, av_path_enhancer, watermark= False)
|
123 |
+
print(f'The generated video is named {video_save_dir}/{video_name_enhancer}')
|
124 |
+
os.remove(enhanced_path)
|
125 |
|
126 |
os.remove(path)
|
127 |
os.remove(new_audio_path)
|
src/utils/face_enhancer.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
import os
|
2 |
import torch
|
3 |
|
4 |
-
from gfpgan import GFPGANer
|
5 |
|
6 |
from tqdm import tqdm
|
7 |
|
|
|
1 |
import os
|
2 |
import torch
|
3 |
|
4 |
+
from gfpgan.utils import GFPGANer
|
5 |
|
6 |
from tqdm import tqdm
|
7 |
|