Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -22,18 +22,19 @@ if not os.path.exists('RestoreFormer.pth'):
|
|
22 |
if not os.path.exists('CodeFormer.pth'):
|
23 |
os.system("wget https://github.com/TencentARC/GFPGAN/releases/download/v1.3.4/CodeFormer.pth -P .")
|
24 |
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
|
|
37 |
|
38 |
# background enhancer with RealESRGAN
|
39 |
model = SRVGGNetCompact(num_in_ch=3, num_out_ch=3, num_feat=64, num_conv=32, upscale=4, act_type='prelu')
|
@@ -90,9 +91,13 @@ def inference(img, version, scale, blur_face):
|
|
90 |
# _, _, output = face_enhancer.enhance(img, has_aligned=False, only_center_face=False, paste_back=True, weight=weight)
|
91 |
face_helper = face_enhancer.face_helper
|
92 |
align_warp_face = face_helper.align_warp_face
|
|
|
93 |
def new_align_warp_face(*args, **kwargs):
|
94 |
align_warp_face(*args, **kwargs) # save_cropped_path
|
|
|
95 |
face_helper.cropped_faces = [cv2.GaussianBlur(e, (blur_face, blur_face), 0) for e in face_helper.cropped_faces]
|
|
|
|
|
96 |
face_helper.align_warp_face = new_align_warp_face
|
97 |
_, _, output = face_enhancer.enhance(img, has_aligned=False, only_center_face=False, paste_back=True)
|
98 |
except RuntimeError as error:
|
@@ -113,7 +118,7 @@ def inference(img, version, scale, blur_face):
|
|
113 |
cv2.imwrite(save_path, output)
|
114 |
|
115 |
output = cv2.cvtColor(output, cv2.COLOR_BGR2RGB)
|
116 |
-
return output, save_path
|
117 |
except Exception as error:
|
118 |
print('global exception', error)
|
119 |
return None, None
|
@@ -146,7 +151,8 @@ demo = gr.Interface(
|
|
146 |
# gr.Slider(0, 100, label='Weight, only for CodeFormer. 0 for better quality, 100 for better identity', default=50)
|
147 |
], [
|
148 |
gr.outputs.Image(type="numpy", label="Output (The whole image)"),
|
149 |
-
gr.outputs.File(label="Download the output image")
|
|
|
150 |
],
|
151 |
title=title,
|
152 |
description=description,
|
|
|
22 |
if not os.path.exists('CodeFormer.pth'):
|
23 |
os.system("wget https://github.com/TencentARC/GFPGAN/releases/download/v1.3.4/CodeFormer.pth -P .")
|
24 |
|
25 |
+
if not os.path.exists('HanamichiSakuragi.jpg'):
|
26 |
+
torch.hub.download_url_to_file(
|
27 |
+
'https://haoluobo.com/wp-content/uploads/2023/01/%E6%A8%B1%E6%9C%A8%E8%8A%B1%E9%81%93.jpg',
|
28 |
+
'HanamichiSakuragi.jpg')
|
29 |
+
torch.hub.download_url_to_file(
|
30 |
+
'https://haoluobo.com/wp-content/uploads/2023/01/%E6%9D%8E%E4%B8%96%E6%B0%91.jpg',
|
31 |
+
'LiShiming.jpg')
|
32 |
+
torch.hub.download_url_to_file(
|
33 |
+
'https://haoluobo.com/wp-content/uploads/2023/01/%E4%B9%BE%E9%9A%86.jpg',
|
34 |
+
'QianLong.jpg')
|
35 |
+
torch.hub.download_url_to_file(
|
36 |
+
'https://user-images.githubusercontent.com/17445847/187401133-8a3bf269-5b4d-4432-b2f0-6d26ee1d3307.png',
|
37 |
+
'10045.png')
|
38 |
|
39 |
# background enhancer with RealESRGAN
|
40 |
model = SRVGGNetCompact(num_in_ch=3, num_out_ch=3, num_feat=64, num_conv=32, upscale=4, act_type='prelu')
|
|
|
91 |
# _, _, output = face_enhancer.enhance(img, has_aligned=False, only_center_face=False, paste_back=True, weight=weight)
|
92 |
face_helper = face_enhancer.face_helper
|
93 |
align_warp_face = face_helper.align_warp_face
|
94 |
+
|
95 |
def new_align_warp_face(*args, **kwargs):
|
96 |
align_warp_face(*args, **kwargs) # save_cropped_path
|
97 |
+
face_helper.org_cropped_faces = face_helper.cropped_faces
|
98 |
face_helper.cropped_faces = [cv2.GaussianBlur(e, (blur_face, blur_face), 0) for e in face_helper.cropped_faces]
|
99 |
+
print("find face count:", len(face_helper.cropped_faces))
|
100 |
+
|
101 |
face_helper.align_warp_face = new_align_warp_face
|
102 |
_, _, output = face_enhancer.enhance(img, has_aligned=False, only_center_face=False, paste_back=True)
|
103 |
except RuntimeError as error:
|
|
|
118 |
cv2.imwrite(save_path, output)
|
119 |
|
120 |
output = cv2.cvtColor(output, cv2.COLOR_BGR2RGB)
|
121 |
+
return output, save_path, [cv2.cvtColor(e, cv2.COLOR_BGR2RGB) for e in face_enhancer.face_helper.org_cropped_faces]
|
122 |
except Exception as error:
|
123 |
print('global exception', error)
|
124 |
return None, None
|
|
|
151 |
# gr.Slider(0, 100, label='Weight, only for CodeFormer. 0 for better quality, 100 for better identity', default=50)
|
152 |
], [
|
153 |
gr.outputs.Image(type="numpy", label="Output (The whole image)"),
|
154 |
+
gr.outputs.File(label="Download the output image"),
|
155 |
+
gr.Gallery(label="All face").style(grid=[2], height="auto")
|
156 |
],
|
157 |
title=title,
|
158 |
description=description,
|