Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -23,14 +23,14 @@ 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 |
torch.hub.download_url_to_file(
|
26 |
-
'https://
|
27 |
-
'
|
28 |
torch.hub.download_url_to_file(
|
29 |
-
'https://
|
30 |
-
'
|
31 |
torch.hub.download_url_to_file(
|
32 |
-
'https://
|
33 |
-
'
|
34 |
torch.hub.download_url_to_file(
|
35 |
'https://user-images.githubusercontent.com/17445847/187401133-8a3bf269-5b4d-4432-b2f0-6d26ee1d3307.png',
|
36 |
'10045.png')
|
@@ -45,7 +45,12 @@ os.makedirs('output', exist_ok=True)
|
|
45 |
|
46 |
|
47 |
# def inference(img, version, scale, weight):
|
48 |
-
def inference(img, version, scale):
|
|
|
|
|
|
|
|
|
|
|
49 |
# weight /= 100
|
50 |
print(img, version, scale)
|
51 |
if scale > 4:
|
@@ -83,6 +88,12 @@ def inference(img, version, scale):
|
|
83 |
|
84 |
try:
|
85 |
# _, _, output = face_enhancer.enhance(img, has_aligned=False, only_center_face=False, paste_back=True, weight=weight)
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
_, _, output = face_enhancer.enhance(img, has_aligned=False, only_center_face=False, paste_back=True)
|
87 |
except RuntimeError as error:
|
88 |
print('Error', error)
|
@@ -131,6 +142,7 @@ demo = gr.Interface(
|
|
131 |
# gr.inputs.Radio(['v1.2', 'v1.3', 'v1.4', 'RestoreFormer', 'CodeFormer'], type="value", default='v1.4', label='version'),
|
132 |
gr.inputs.Radio(['v1.2', 'v1.3', 'v1.4', 'RestoreFormer'], type="value", default='v1.4', label='version'),
|
133 |
gr.inputs.Number(label="Rescaling factor", default=2),
|
|
|
134 |
# gr.Slider(0, 100, label='Weight, only for CodeFormer. 0 for better quality, 100 for better identity', default=50)
|
135 |
], [
|
136 |
gr.outputs.Image(type="numpy", label="Output (The whole image)"),
|
|
|
23 |
os.system("wget https://github.com/TencentARC/GFPGAN/releases/download/v1.3.4/CodeFormer.pth -P .")
|
24 |
|
25 |
torch.hub.download_url_to_file(
|
26 |
+
'https://haoluobo.com/wp-content/uploads/2023/01/%E6%A8%B1%E6%9C%A8%E8%8A%B1%E9%81%93.jpg',
|
27 |
+
'HanamichiSakuragi.jpg')
|
28 |
torch.hub.download_url_to_file(
|
29 |
+
'https://haoluobo.com/wp-content/uploads/2023/01/%E6%9D%8E%E4%B8%96%E6%B0%91.jpg',
|
30 |
+
'LiShiming.jpg')
|
31 |
torch.hub.download_url_to_file(
|
32 |
+
'https://haoluobo.com/wp-content/uploads/2023/01/%E4%B9%BE%E9%9A%86.jpg',
|
33 |
+
'QianLong.jpg')
|
34 |
torch.hub.download_url_to_file(
|
35 |
'https://user-images.githubusercontent.com/17445847/187401133-8a3bf269-5b4d-4432-b2f0-6d26ee1d3307.png',
|
36 |
'10045.png')
|
|
|
45 |
|
46 |
|
47 |
# def inference(img, version, scale, weight):
|
48 |
+
def inference(img, version, scale, blur_face):
|
49 |
+
blur_face = int(blur_face)
|
50 |
+
if blur_face < 3:
|
51 |
+
blur_face = 3
|
52 |
+
if blur_face % 2 != 1:
|
53 |
+
blur_face += 1
|
54 |
# weight /= 100
|
55 |
print(img, version, scale)
|
56 |
if scale > 4:
|
|
|
88 |
|
89 |
try:
|
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:
|
99 |
print('Error', error)
|
|
|
142 |
# gr.inputs.Radio(['v1.2', 'v1.3', 'v1.4', 'RestoreFormer', 'CodeFormer'], type="value", default='v1.4', label='version'),
|
143 |
gr.inputs.Radio(['v1.2', 'v1.3', 'v1.4', 'RestoreFormer'], type="value", default='v1.4', label='version'),
|
144 |
gr.inputs.Number(label="Rescaling factor", default=2),
|
145 |
+
gr.inputs.Number(label="Blur face", default=25),
|
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)"),
|