Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -41,30 +41,6 @@ if not os.path.exists('CodeFormer/weights/facelib/parsing_parsenet.pth'):
|
|
41 |
if not os.path.exists('CodeFormer/weights/realesrgan/RealESRGAN_x2plus.pth'):
|
42 |
load_file_from_url(url=pretrain_model_url['realesrgan'], model_dir='CodeFormer/weights/realesrgan', progress=True, file_name=None)
|
43 |
|
44 |
-
# download images
|
45 |
-
torch.hub.download_url_to_file(
|
46 |
-
'https://replicate.com/api/models/sczhou/codeformer/files/fa3fe3d1-76b0-4ca8-ac0d-0a925cb0ff54/06.png',
|
47 |
-
'01.png')
|
48 |
-
torch.hub.download_url_to_file(
|
49 |
-
'https://replicate.com/api/models/sczhou/codeformer/files/a1daba8e-af14-4b00-86a4-69cec9619b53/04.jpg',
|
50 |
-
'02.jpg')
|
51 |
-
torch.hub.download_url_to_file(
|
52 |
-
'https://replicate.com/api/models/sczhou/codeformer/files/542d64f9-1712-4de7-85f7-3863009a7c3d/03.jpg',
|
53 |
-
'03.jpg')
|
54 |
-
torch.hub.download_url_to_file(
|
55 |
-
'https://replicate.com/api/models/sczhou/codeformer/files/a11098b0-a18a-4c02-a19a-9a7045d68426/010.jpg',
|
56 |
-
'04.jpg')
|
57 |
-
torch.hub.download_url_to_file(
|
58 |
-
'https://replicate.com/api/models/sczhou/codeformer/files/7cf19c2c-e0cf-4712-9af8-cf5bdbb8d0ee/012.jpg',
|
59 |
-
'05.jpg')
|
60 |
-
torch.hub.download_url_to_file(
|
61 |
-
'https://raw.githubusercontent.com/sczhou/CodeFormer/master/inputs/cropped_faces/0729.png',
|
62 |
-
'06.png')
|
63 |
-
|
64 |
-
def imread(img_path):
|
65 |
-
img = cv2.imread(img_path)
|
66 |
-
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
|
67 |
-
return img
|
68 |
|
69 |
# set enhancer with RealESRGAN
|
70 |
def set_realesrgan():
|
@@ -121,8 +97,6 @@ def inference(image, face_align, background_enhance, face_upsample, upscale, cod
|
|
121 |
has_aligned = not face_align
|
122 |
upscale = 1 if has_aligned else upscale
|
123 |
|
124 |
-
img = cv2.imread(str(image), cv2.IMREAD_COLOR)
|
125 |
-
print('\timage size:', img.shape)
|
126 |
|
127 |
upscale = int(upscale) # convert type to int
|
128 |
if upscale > 4: # avoid memory exceeded due to too large upscale
|
@@ -229,53 +203,6 @@ description = r"""<center><img src='https://user-images.githubusercontent.com/14
|
|
229 |
"""
|
230 |
|
231 |
article = r"""
|
232 |
-
If CodeFormer is helpful, please help to ⭐ the <a href='https://github.com/sczhou/CodeFormer' target='_blank'>Github Repo</a>. Thanks!
|
233 |
-
[](https://github.com/sczhou/CodeFormer)
|
234 |
-
|
235 |
-
---
|
236 |
-
|
237 |
-
📝 **Citation**
|
238 |
-
|
239 |
-
If our work is useful for your research, please consider citing:
|
240 |
-
```bibtex
|
241 |
-
@inproceedings{zhou2022codeformer,
|
242 |
-
author = {Zhou, Shangchen and Chan, Kelvin C.K. and Li, Chongyi and Loy, Chen Change},
|
243 |
-
title = {Towards Robust Blind Face Restoration with Codebook Lookup TransFormer},
|
244 |
-
booktitle = {NeurIPS},
|
245 |
-
year = {2022}
|
246 |
-
}
|
247 |
-
```
|
248 |
-
|
249 |
-
📋 **License**
|
250 |
-
|
251 |
-
This project is licensed under <a rel="license" href="https://github.com/sczhou/CodeFormer/blob/master/LICENSE">S-Lab License 1.0</a>.
|
252 |
-
Redistribution and use for non-commercial purposes should follow this license.
|
253 |
-
|
254 |
-
📧 **Contact**
|
255 |
-
|
256 |
-
If you have any questions, please feel free to reach me out at <b>[email protected]</b>.
|
257 |
-
|
258 |
-
🤗 **Find Me:**
|
259 |
-
<style type="text/css">
|
260 |
-
td {
|
261 |
-
padding-right: 0px !important;
|
262 |
-
}
|
263 |
-
|
264 |
-
.gradio-container-4-37-2 .prose table, .gradio-container-4-37-2 .prose tr, .gradio-container-4-37-2 .prose td, .gradio-container-4-37-2 .prose th {
|
265 |
-
border: 0px solid #ffffff;
|
266 |
-
border-bottom: 0px solid #ffffff;
|
267 |
-
}
|
268 |
-
|
269 |
-
</style>
|
270 |
-
|
271 |
-
<table>
|
272 |
-
<tr>
|
273 |
-
<td><a href="https://github.com/sczhou"><img style="margin:-0.8em 0 2em 0" src="https://img.shields.io/github/followers/sczhou?style=social" alt="Github Follow"></a></td>
|
274 |
-
<td><a href="https://twitter.com/ShangchenZhou"><img style="margin:-0.8em 0 2em 0" src="https://img.shields.io/twitter/follow/ShangchenZhou?label=%40ShangchenZhou&style=social" alt="Twitter Follow"></a></td>
|
275 |
-
</tr>
|
276 |
-
</table>
|
277 |
-
|
278 |
-
<center><img src='https://api.infinitescript.com/badgen/count?name=sczhou/CodeFormer<ext=Visitors&color=6dc9aa' alt='visitors'></center>
|
279 |
"""
|
280 |
|
281 |
demo = gr.Interface(
|
@@ -293,12 +220,6 @@ demo = gr.Interface(
|
|
293 |
description=description,
|
294 |
article=article,
|
295 |
examples=[
|
296 |
-
['01.png', True, True, True, 2, 0.7],
|
297 |
-
['02.jpg', True, True, True, 2, 0.7],
|
298 |
-
['03.jpg', True, True, True, 2, 0.7],
|
299 |
-
['04.jpg', True, True, True, 2, 0.1],
|
300 |
-
['05.jpg', True, True, True, 2, 0.1],
|
301 |
-
['06.png', False, True, True, 1, 0.5]
|
302 |
],
|
303 |
concurrency_limit=2
|
304 |
)
|
|
|
41 |
if not os.path.exists('CodeFormer/weights/realesrgan/RealESRGAN_x2plus.pth'):
|
42 |
load_file_from_url(url=pretrain_model_url['realesrgan'], model_dir='CodeFormer/weights/realesrgan', progress=True, file_name=None)
|
43 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
|
45 |
# set enhancer with RealESRGAN
|
46 |
def set_realesrgan():
|
|
|
97 |
has_aligned = not face_align
|
98 |
upscale = 1 if has_aligned else upscale
|
99 |
|
|
|
|
|
100 |
|
101 |
upscale = int(upscale) # convert type to int
|
102 |
if upscale > 4: # avoid memory exceeded due to too large upscale
|
|
|
203 |
"""
|
204 |
|
205 |
article = r"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
206 |
"""
|
207 |
|
208 |
demo = gr.Interface(
|
|
|
220 |
description=description,
|
221 |
article=article,
|
222 |
examples=[
|
|
|
|
|
|
|
|
|
|
|
|
|
223 |
],
|
224 |
concurrency_limit=2
|
225 |
)
|