leonelhs commited on
Commit
9a0839a
1 Parent(s): de7a048
Files changed (3) hide show
  1. .gitignore +8 -0
  2. app.py +4 -16
  3. examples.py +25 -0
.gitignore ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ *.png
2
+ *.jpg
3
+ .idea/
4
+ __pycache__/
5
+ flagged
6
+ gfpgan
7
+ output
8
+
app.py CHANGED
@@ -7,24 +7,14 @@ from basicsr.archs.srvgg_arch import SRVGGNetCompact
7
  from gfpgan.utils import GFPGANer
8
  from huggingface_hub import snapshot_download, hf_hub_download
9
  from realesrgan.utils import RealESRGANer
 
10
 
11
  REALESRGAN_REPO_ID = 'leonelhs/realesrgan'
12
  GFPGAN_REPO_ID = 'leonelhs/gfpgan'
13
 
14
  os.system("pip freeze")
15
 
16
- torch.hub.download_url_to_file(
17
- 'https://upload.wikimedia.org/wikipedia/commons/thumb/a/ab/Abraham_Lincoln_O-77_matte_collodion_print.jpg/1024px-Abraham_Lincoln_O-77_matte_collodion_print.jpg',
18
- 'lincoln.jpg')
19
- torch.hub.download_url_to_file(
20
- 'https://user-images.githubusercontent.com/17445847/187400315-87a90ac9-d231-45d6-b377-38702bd1838f.jpg',
21
- 'AI-generate.jpg')
22
- torch.hub.download_url_to_file(
23
- 'https://user-images.githubusercontent.com/17445847/187400981-8a58f7a4-ef61-42d9-af80-bc6234cef860.jpg',
24
- 'Blake_Lively.jpg')
25
- torch.hub.download_url_to_file(
26
- 'https://user-images.githubusercontent.com/17445847/187401133-8a3bf269-5b4d-4432-b2f0-6d26ee1d3307.png',
27
- '10045.png')
28
 
29
  # background enhancer with RealESRGAN
30
  model = SRVGGNetCompact(num_in_ch=3, num_out_ch=3, num_feat=64, num_conv=32, upscale=4, act_type='prelu')
@@ -36,7 +26,7 @@ os.makedirs('output', exist_ok=True)
36
 
37
 
38
  # def inference(img, version, scale, weight):
39
- def inference(img, version, scale):
40
  # weight /= 100
41
  print(img, version, scale)
42
  if scale > 4:
@@ -125,12 +115,10 @@ If you have any question, please email 📧 `xintao.wang@outlook.com` or `xintao
125
  <center><img src='https://visitor-badge.glitch.me/badge?page_id=Gradio_Xintao_GFPGAN' alt='visitor badge'></center>
126
  """
127
  demo = gr.Interface(
128
- inference, [
129
  gr.Image(type="filepath", label="Input"),
130
- # gr.Radio(['v1.2', 'v1.3', 'v1.4', 'RestoreFormer', 'CodeFormer'], type="value", value='v1.4', label='version'),
131
  gr.Radio(['v1.2', 'v1.3', 'v1.4', 'RestoreFormer'], type="value", value='v1.4', label='version'),
132
  gr.Number(label="Rescaling factor", value=2),
133
- # gr.Slider(0, 100, label='Weight, only for CodeFormer. 0 for better quality, 100 for better identity', value=50)
134
  ], [
135
  gr.Image(type="numpy", label="Output (The whole image)"),
136
  gr.File(label="Download the output image")
 
7
  from gfpgan.utils import GFPGANer
8
  from huggingface_hub import snapshot_download, hf_hub_download
9
  from realesrgan.utils import RealESRGANer
10
+ import examples
11
 
12
  REALESRGAN_REPO_ID = 'leonelhs/realesrgan'
13
  GFPGAN_REPO_ID = 'leonelhs/gfpgan'
14
 
15
  os.system("pip freeze")
16
 
17
+ examples.download()
 
 
 
 
 
 
 
 
 
 
 
18
 
19
  # background enhancer with RealESRGAN
20
  model = SRVGGNetCompact(num_in_ch=3, num_out_ch=3, num_feat=64, num_conv=32, upscale=4, act_type='prelu')
 
26
 
27
 
28
  # def inference(img, version, scale, weight):
29
+ def predict(img, version, scale):
30
  # weight /= 100
31
  print(img, version, scale)
32
  if scale > 4:
 
115
  <center><img src='https://visitor-badge.glitch.me/badge?page_id=Gradio_Xintao_GFPGAN' alt='visitor badge'></center>
116
  """
117
  demo = gr.Interface(
118
+ predict, [
119
  gr.Image(type="filepath", label="Input"),
 
120
  gr.Radio(['v1.2', 'v1.3', 'v1.4', 'RestoreFormer'], type="value", value='v1.4', label='version'),
121
  gr.Number(label="Rescaling factor", value=2),
 
122
  ], [
123
  gr.Image(type="numpy", label="Output (The whole image)"),
124
  gr.File(label="Download the output image")
examples.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+
3
+ examples = [
4
+ {
5
+ 'name': 'lincoln.jpg',
6
+ 'url': 'https://upload.wikimedia.org/wikipedia/commons/thumb/a/ab/Abraham_Lincoln_O-77_matte_collodion_print.jpg/1024px-Abraham_Lincoln_O-77_matte_collodion_print.jpg'
7
+ },
8
+ {
9
+ 'name': 'AI-generate.jpg',
10
+ 'url': 'https://user-images.githubusercontent.com/17445847/187400315-87a90ac9-d231-45d6-b377-38702bd1838f.jpg'
11
+ },
12
+ {
13
+ 'name': 'Blake_Lively.jpg',
14
+ 'url': 'https://user-images.githubusercontent.com/17445847/187400981-8a58f7a4-ef61-42d9-af80-bc6234cef860.jpg'
15
+ },
16
+ {
17
+ 'name': '10045.png',
18
+ 'url': 'https://user-images.githubusercontent.com/17445847/187401133-8a3bf269-5b4d-4432-b2f0-6d26ee1d3307.png'
19
+ }
20
+ ]
21
+
22
+
23
+ def download():
24
+ for example in examples:
25
+ torch.hub.download_url_to_file(example['url'], example['name'])