zhiweili
commited on
Commit
•
df75ec5
1
Parent(s):
bc088da
add enhanceface
Browse files- app_makeup.py +4 -2
- enhance_utils.py +18 -5
- segment_utils.py +1 -1
app_makeup.py
CHANGED
@@ -34,6 +34,7 @@ def image_to_image(
|
|
34 |
canny_scale: float,
|
35 |
lineart_detect: float,
|
36 |
canny_detect: float,
|
|
|
37 |
):
|
38 |
w2 = 1.0
|
39 |
run_task_time = 0
|
@@ -57,7 +58,7 @@ def image_to_image(
|
|
57 |
canny_detect,
|
58 |
)
|
59 |
run_task_time, time_cost_str = get_time_cost(run_task_time, time_cost_str)
|
60 |
-
enhanced_image = enhance_image(generated_image,
|
61 |
run_task_time, time_cost_str = get_time_cost(run_task_time, time_cost_str)
|
62 |
|
63 |
return enhanced_image, generated_image, time_cost_str
|
@@ -89,6 +90,7 @@ def create_demo() -> gr.Blocks:
|
|
89 |
generate_size = gr.Number(label="Generate Size", value=1024)
|
90 |
mask_expansion = gr.Number(label="Mask Expansion", value=10, visible=True)
|
91 |
mask_dilation = gr.Slider(minimum=0, maximum=10, value=2, step=1, label="Mask Dilation")
|
|
|
92 |
lineart_scale = gr.Slider(minimum=0, maximum=5, value=0.8, step=0.1, label="Lineart Weights", visible=True)
|
93 |
canny_scale = gr.Slider(minimum=0, maximum=5, value=0.4, step=0.1, label="Canny Weights", visible=True)
|
94 |
lineart_detect = gr.Number(label="Lineart Detect", value=0.375, visible=True)
|
@@ -116,7 +118,7 @@ def create_demo() -> gr.Blocks:
|
|
116 |
outputs=[origin_area_image, croper],
|
117 |
).success(
|
118 |
fn=image_to_image,
|
119 |
-
inputs=[origin_area_image, input_image_prompt, edit_prompt,seed,w1, num_steps, start_step, guidance_scale, generate_size, lineart_scale, canny_scale, lineart_detect, canny_detect],
|
120 |
outputs=[enhanced_image, generated_image, generated_cost],
|
121 |
).success(
|
122 |
fn=restore_result,
|
|
|
34 |
canny_scale: float,
|
35 |
lineart_detect: float,
|
36 |
canny_detect: float,
|
37 |
+
enhance_face: bool = True,
|
38 |
):
|
39 |
w2 = 1.0
|
40 |
run_task_time = 0
|
|
|
58 |
canny_detect,
|
59 |
)
|
60 |
run_task_time, time_cost_str = get_time_cost(run_task_time, time_cost_str)
|
61 |
+
enhanced_image = enhance_image(generated_image, enhance_face)
|
62 |
run_task_time, time_cost_str = get_time_cost(run_task_time, time_cost_str)
|
63 |
|
64 |
return enhanced_image, generated_image, time_cost_str
|
|
|
90 |
generate_size = gr.Number(label="Generate Size", value=1024)
|
91 |
mask_expansion = gr.Number(label="Mask Expansion", value=10, visible=True)
|
92 |
mask_dilation = gr.Slider(minimum=0, maximum=10, value=2, step=1, label="Mask Dilation")
|
93 |
+
enhance_face = gr.Checkbox(label="Enhance Face", value=False)
|
94 |
lineart_scale = gr.Slider(minimum=0, maximum=5, value=0.8, step=0.1, label="Lineart Weights", visible=True)
|
95 |
canny_scale = gr.Slider(minimum=0, maximum=5, value=0.4, step=0.1, label="Canny Weights", visible=True)
|
96 |
lineart_detect = gr.Number(label="Lineart Detect", value=0.375, visible=True)
|
|
|
118 |
outputs=[origin_area_image, croper],
|
119 |
).success(
|
120 |
fn=image_to_image,
|
121 |
+
inputs=[origin_area_image, input_image_prompt, edit_prompt,seed,w1, num_steps, start_step, guidance_scale, generate_size, lineart_scale, canny_scale, lineart_detect, canny_detect, enhance_face],
|
122 |
outputs=[enhanced_image, generated_image, generated_cost],
|
123 |
).success(
|
124 |
fn=restore_result,
|
enhance_utils.py
CHANGED
@@ -2,19 +2,32 @@ import os
|
|
2 |
import torch
|
3 |
import cv2
|
4 |
import numpy as np
|
|
|
5 |
|
6 |
from PIL import Image
|
7 |
from gfpgan.utils import GFPGANer
|
8 |
from basicsr.archs.srvgg_arch import SRVGGNetCompact
|
9 |
from realesrgan.utils import RealESRGANer
|
10 |
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
if not os.path.exists('GFPGANv1.4.pth'):
|
13 |
-
|
14 |
if not os.path.exists('realesr-general-x4v3.pth'):
|
15 |
-
|
16 |
-
|
17 |
-
os.makedirs('output', exist_ok=True)
|
18 |
|
19 |
model = SRVGGNetCompact(num_in_ch=3, num_out_ch=3, num_feat=64, num_conv=32, upscale=4, act_type='prelu')
|
20 |
model_path = 'realesr-general-x4v3.pth'
|
|
|
2 |
import torch
|
3 |
import cv2
|
4 |
import numpy as np
|
5 |
+
import subprocess
|
6 |
|
7 |
from PIL import Image
|
8 |
from gfpgan.utils import GFPGANer
|
9 |
from basicsr.archs.srvgg_arch import SRVGGNetCompact
|
10 |
from realesrgan.utils import RealESRGANer
|
11 |
|
12 |
+
def runcmd(cmd, verbose = False, *args, **kwargs):
|
13 |
+
|
14 |
+
process = subprocess.Popen(
|
15 |
+
cmd,
|
16 |
+
stdout = subprocess.PIPE,
|
17 |
+
stderr = subprocess.PIPE,
|
18 |
+
text = True,
|
19 |
+
shell = True
|
20 |
+
)
|
21 |
+
std_out, std_err = process.communicate()
|
22 |
+
if verbose:
|
23 |
+
print(std_out.strip(), std_err)
|
24 |
+
pass
|
25 |
+
|
26 |
+
runcmd("pip freeze")
|
27 |
if not os.path.exists('GFPGANv1.4.pth'):
|
28 |
+
runcmd("wget https://github.com/TencentARC/GFPGAN/releases/download/v1.3.0/GFPGANv1.4.pth -P .")
|
29 |
if not os.path.exists('realesr-general-x4v3.pth'):
|
30 |
+
runcmd("wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesr-general-x4v3.pth -P .")
|
|
|
|
|
31 |
|
32 |
model = SRVGGNetCompact(num_in_ch=3, num_out_ch=3, num_feat=64, num_conv=32, upscale=4, act_type='prelu')
|
33 |
model_path = 'realesr-general-x4v3.pth'
|
segment_utils.py
CHANGED
@@ -30,7 +30,7 @@ def restore_result(croper, category, generated_image):
|
|
30 |
extension = 'jpg'
|
31 |
|
32 |
path = f"output/{uuid.uuid4()}.{extension}"
|
33 |
-
restored_image.save(path)
|
34 |
|
35 |
return restored_image, path
|
36 |
|
|
|
30 |
extension = 'jpg'
|
31 |
|
32 |
path = f"output/{uuid.uuid4()}.{extension}"
|
33 |
+
restored_image.save(path, quality=100)
|
34 |
|
35 |
return restored_image, path
|
36 |
|