Spaces:
Running
on
Zero
Running
on
Zero
Update src/gradio_pipeline.py
Browse files- src/gradio_pipeline.py +23 -0
src/gradio_pipeline.py
CHANGED
@@ -110,3 +110,26 @@ class GradioPipeline(LivePortraitPipeline):
|
|
110 |
else:
|
111 |
# when press the clear button, go here
|
112 |
raise gr.Error("Please upload a source portrait as the retargeting input 🤗🤗🤗", duration=5)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
110 |
else:
|
111 |
# when press the clear button, go here
|
112 |
raise gr.Error("Please upload a source portrait as the retargeting input 🤗🤗🤗", duration=5)
|
113 |
+
|
114 |
+
def init_retargeting_image(self, retargeting_source_scale: float, source_eye_ratio: float, source_lip_ratio:float, input_image = None):
|
115 |
+
""" initialize the retargeting slider
|
116 |
+
"""
|
117 |
+
if input_image != None:
|
118 |
+
args_user = {'scale': retargeting_source_scale}
|
119 |
+
self.args = update_args(self.args, args_user)
|
120 |
+
self.cropper.update_config(self.args.__dict__)
|
121 |
+
# inference_cfg = self.live_portrait_wrapper.inference_cfg
|
122 |
+
######## process source portrait ########
|
123 |
+
img_rgb = load_img_online(input_image, mode='rgb', max_dim=1280, n=16)
|
124 |
+
log(f"Load source image from {input_image}.")
|
125 |
+
crop_info = self.cropper.crop_source_image(img_rgb, self.cropper.crop_cfg)
|
126 |
+
if crop_info is None:
|
127 |
+
raise gr.Error("Source portrait NO face detected", duration=2)
|
128 |
+
source_eye_ratio = calc_eye_close_ratio(crop_info['lmk_crop'][None])
|
129 |
+
source_lip_ratio = calc_lip_close_ratio(crop_info['lmk_crop'][None])
|
130 |
+
self.source_eye_ratio = round(float(source_eye_ratio.mean()), 2)
|
131 |
+
self.source_lip_ratio = round(float(source_lip_ratio[0][0]), 2)
|
132 |
+
log("Calculating eyes-open and lip-open ratios successfully!")
|
133 |
+
return self.source_eye_ratio, self.source_lip_ratio
|
134 |
+
else:
|
135 |
+
return source_eye_ratio, source_lip_ratio
|