nightfury commited on
Commit
379bb4d
1 Parent(s): b896792

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -14
app.py CHANGED
@@ -23,17 +23,17 @@ 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://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',
27
- 'lincoln.jpg')
28
  torch.hub.download_url_to_file(
29
- 'https://user-images.githubusercontent.com/17445847/187400315-87a90ac9-d231-45d6-b377-38702bd1838f.jpg',
30
- 'AI-generate.jpg')
31
  torch.hub.download_url_to_file(
32
- 'https://user-images.githubusercontent.com/17445847/187400981-8a58f7a4-ef61-42d9-af80-bc6234cef860.jpg',
33
- 'Blake_Lively.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')
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')
@@ -75,9 +75,12 @@ def inference(img, version, scale):
75
  elif version == 'RestoreFormer':
76
  face_enhancer = GFPGANer(
77
  model_path='RestoreFormer.pth', upscale=2, arch='RestoreFormer', channel_multiplier=2, bg_upsampler=upsampler)
78
- # elif version == 'CodeFormer':
79
- # face_enhancer = GFPGANer(
80
- # model_path='CodeFormer.pth', upscale=2, arch='CodeFormer', channel_multiplier=2, bg_upsampler=upsampler)
 
 
 
81
 
82
  try:
83
  # _, _, output = face_enhancer.enhance(img, has_aligned=False, only_center_face=False, paste_back=True, weight=weight)
@@ -121,7 +124,7 @@ demo = gr.Interface(
121
  inference, [
122
  gr.inputs.Image(type="filepath", label="Input"),
123
  # gr.inputs.Radio(['v1.2', 'v1.3', 'v1.4', 'RestoreFormer', 'CodeFormer'], type="value", default='v1.4', label='version'),
124
- gr.inputs.Radio(['v1.2', 'v1.3', 'v1.4', 'RestoreFormer'], type="value", default='v1.4', label='version'),
125
  gr.inputs.Number(label="Rescaling factor", default=2),
126
  # gr.Slider(0, 100, label='Weight, only for CodeFormer. 0 for better quality, 100 for better identity', default=50)
127
  ], [
@@ -133,7 +136,7 @@ demo = gr.Interface(
133
  article=article,
134
  # examples=[['AI-generate.jpg', 'v1.4', 2, 50], ['lincoln.jpg', 'v1.4', 2, 50], ['Blake_Lively.jpg', 'v1.4', 2, 50],
135
  # ['10045.png', 'v1.4', 2, 50]]).launch()
136
- examples=[['AI-generate.jpg', 'v1.4', 2], ['lincoln.jpg', 'v1.4', 2], ['Blake_Lively.jpg', 'v1.4', 2],
137
- ['10045.png', 'v1.4', 2]])
138
  demo.queue(concurrency_count=4)
139
  demo.launch()
 
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://static.toiimg.com/photo/msid-71531342/71531342.jpg',
27
+ 'a1.jpg')
28
  torch.hub.download_url_to_file(
29
+ 'https://www.deccanherald.com/sites/dh/files/styles/gallery_thumbnails/public/gallery_images/2021/09/17/PM%20Modi%20Rare%20Photos%20%284%29.jpg',
30
+ 'a2.jpg')
31
  torch.hub.download_url_to_file(
32
+ 'https://resize.indiatvnews.com/en/resize/newbucket/715_-/2018/01/dssd-1514798177.jpg',
33
+ 'a3.jpg')
34
  torch.hub.download_url_to_file(
35
+ 'https://resize.indiatvnews.com/en/resize/newbucket/715_-/2018/01/capture-1514798177.jpg',
36
+ 'a4.jpg')
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')
 
75
  elif version == 'RestoreFormer':
76
  face_enhancer = GFPGANer(
77
  model_path='RestoreFormer.pth', upscale=2, arch='RestoreFormer', channel_multiplier=2, bg_upsampler=upsampler)
78
+ elif version == 'CodeFormer':
79
+ face_enhancer = GFPGANer(
80
+ model_path='CodeFormer.pth', upscale=2, arch='CodeFormer', channel_multiplier=2, bg_upsampler=upsampler)
81
+ elif version == 'RealESR-General-x4v3':
82
+ face_enhancer = GFPGANer(
83
+ model_path='realesr-general-x4v3.pth', upscale=2, arch='realesr-general', channel_multiplier=2, bg_upsampler=upsampler)
84
 
85
  try:
86
  # _, _, output = face_enhancer.enhance(img, has_aligned=False, only_center_face=False, paste_back=True, weight=weight)
 
124
  inference, [
125
  gr.inputs.Image(type="filepath", label="Input"),
126
  # gr.inputs.Radio(['v1.2', 'v1.3', 'v1.4', 'RestoreFormer', 'CodeFormer'], type="value", default='v1.4', label='version'),
127
+ gr.inputs.Radio(['v1.2', 'v1.3', 'v1.4', 'RestoreFormer','CodeFormer','RealESR-General-x4v3'], type="value", default='v1.4', label='version'),
128
  gr.inputs.Number(label="Rescaling factor", default=2),
129
  # gr.Slider(0, 100, label='Weight, only for CodeFormer. 0 for better quality, 100 for better identity', default=50)
130
  ], [
 
136
  article=article,
137
  # examples=[['AI-generate.jpg', 'v1.4', 2, 50], ['lincoln.jpg', 'v1.4', 2, 50], ['Blake_Lively.jpg', 'v1.4', 2, 50],
138
  # ['10045.png', 'v1.4', 2, 50]]).launch()
139
+ examples=[['a1.jpg', 'v1.4', 2], ['a2.jpg', 'v1.4', 2], ['a3.jpg', 'v1.4', 2],['a4.jpg', 'v1.4', 2]])
140
+
141
  demo.queue(concurrency_count=4)
142
  demo.launch()