leonelhs commited on
Commit
e49a8d7
1 Parent(s): 7df4aad
Files changed (4) hide show
  1. .gitignore +8 -0
  2. app.py +74 -0
  3. packages.txt +3 -0
  4. requirements.txt +13 -0
.gitignore ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ *.png
2
+ *.jpg
3
+ .idea/
4
+ __pycache__/
5
+ flagged
6
+ gfpgan
7
+ output
8
+
app.py ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+
3
+ import gradio as gr
4
+ import torch
5
+ from basicsr.archs.srvgg_arch import SRVGGNetCompact
6
+ from gfpgan.utils import GFPGANer
7
+ from huggingface_hub import hf_hub_download
8
+ from realesrgan.utils import RealESRGANer
9
+
10
+ REALESRGAN_REPO_ID = 'leonelhs/realesrgan'
11
+ GFPGAN_REPO_ID = 'leonelhs/gfpgan'
12
+
13
+ os.system("pip freeze")
14
+
15
+ # background enhancer with RealESRGAN
16
+ model = SRVGGNetCompact(num_in_ch=3, num_out_ch=3, num_feat=64, num_conv=32, upscale=4, act_type='prelu')
17
+ model_path = hf_hub_download(repo_id=REALESRGAN_REPO_ID, filename='realesr-general-x4v3.pth')
18
+ half = True if torch.cuda.is_available() else False
19
+ upsampler = RealESRGANer(scale=4, model_path=model_path, model=model, tile=0, tile_pad=10, pre_pad=0, half=half)
20
+
21
+
22
+ def download_model(file):
23
+ return hf_hub_download(repo_id=GFPGAN_REPO_ID, filename=file)
24
+
25
+
26
+ def predict(image, version, scale):
27
+ scale = int(scale)
28
+ face_enhancer = None
29
+
30
+ if version == 'v1.2':
31
+ path = download_model('GFPGANv1.2.pth')
32
+ face_enhancer = GFPGANer(
33
+ model_path=path, upscale=scale, arch='clean', channel_multiplier=2, bg_upsampler=upsampler)
34
+ elif version == 'v1.3':
35
+ path = download_model('GFPGANv1.3.pth')
36
+ face_enhancer = GFPGANer(
37
+ model_path=path, upscale=scale, arch='clean', channel_multiplier=2, bg_upsampler=upsampler)
38
+ elif version == 'v1.4':
39
+ path = download_model('GFPGANv1.4.pth')
40
+ face_enhancer = GFPGANer(
41
+ model_path=path, upscale=scale, arch='clean', channel_multiplier=2, bg_upsampler=upsampler)
42
+ elif version == 'RestoreFormer':
43
+ path = download_model('RestoreFormer.pth')
44
+ face_enhancer = GFPGANer(
45
+ model_path=path, upscale=scale, arch='RestoreFormer', channel_multiplier=2, bg_upsampler=upsampler)
46
+
47
+ _, _, output = face_enhancer.enhance(image, has_aligned=False, only_center_face=False, paste_back=True)
48
+
49
+ return output
50
+
51
+
52
+ title = "GFPGAN"
53
+ description = r"""
54
+ <b>Practical Face Restoration Algorithm</b>
55
+ """
56
+ article = r"""
57
+ <center><span>[email protected] or [email protected]</span></center>
58
+ </br>
59
+ <center><a href='https://github.com/TencentARC/GFPGAN' target='_blank'>Github Repo ⭐ </a> are welcome</center>
60
+ """
61
+
62
+ demo = gr.Interface(
63
+ predict, [
64
+ gr.Image(type="numpy", label="Input"),
65
+ gr.Radio(['v1.2', 'v1.3', 'v1.4', 'RestoreFormer'], type="value", value='v1.4', label='version'),
66
+ gr.Dropdown(["1", "2", "3", "4"], value="2", label="Rescaling factor")
67
+ ], [
68
+ gr.Image(type="numpy", label="Output", interactive=False)
69
+ ],
70
+ title=title,
71
+ description=description,
72
+ article=article)
73
+
74
+ demo.queue().launch()
packages.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ ffmpeg
2
+ libsm6
3
+ libxext6
requirements.txt ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ torch>=2.0.1
2
+ basicsr>=1.4.2
3
+ facexlib>=0.3.0
4
+ gfpgan>=1.3.8
5
+ realesrgan>=0.3.0
6
+ numpy
7
+ opencv-python
8
+ torchvision
9
+ scipy
10
+ tqdm
11
+ lmdb
12
+ pyyaml
13
+ yapf