wzhouxiff commited on
Commit
29f94bf
1 Parent(s): b3cfa0c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -6
app.py CHANGED
@@ -7,7 +7,8 @@ from basicsr.archs.srvgg_arch import SRVGGNetCompact
7
  from realesrgan.utils import RealESRGANer
8
  from glob import glob
9
 
10
- from RestoreFormer import RestoreFormer
 
11
 
12
  if not os.path.exists('experiments/pretrained_models'):
13
  os.makedirs('experiments/pretrained_models')
@@ -36,7 +37,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:
@@ -69,7 +70,12 @@ def inference(img, version, scale):
69
 
70
  try:
71
  # _, _, output = face_enhancer.enhance(img, has_aligned=False, only_center_face=False, paste_back=True, weight=weight)
72
- _, _, output = face_enhancer.enhance(img, has_aligned=False, only_center_face=False, paste_back=True)
 
 
 
 
 
73
  except RuntimeError as error:
74
  print('Error', error)
75
 
@@ -182,6 +188,7 @@ demo = gr.Interface(
182
  inference, [
183
  gr.Image(type="filepath", label="Input"),
184
  gr.Radio(['RestoreFormer', 'RestoreFormer++'], type="value", value='RestoreFormer++', label='version'),
 
185
  gr.Number(label="Rescaling factor", value=2),
186
  ], [
187
  gr.Image(type="numpy", label="Output (The whole image)"),
@@ -190,6 +197,4 @@ demo = gr.Interface(
190
  title=title,
191
  description=description,
192
  article=article,
193
- )
194
-
195
- demo.queue().launch()
 
7
  from realesrgan.utils import RealESRGANer
8
  from glob import glob
9
 
10
+ sys.path.insert(1, os.path.join(sys.path[0], '..'))
11
+ from gradio_demo.RestoreFormer import RestoreFormer
12
 
13
  if not os.path.exists('experiments/pretrained_models'):
14
  os.makedirs('experiments/pretrained_models')
 
37
 
38
 
39
  # def inference(img, version, scale, weight):
40
+ def inference(img, version, aligned, scale):
41
  # weight /= 100
42
  print(img, version, scale)
43
  if scale > 4:
 
70
 
71
  try:
72
  # _, _, output = face_enhancer.enhance(img, has_aligned=False, only_center_face=False, paste_back=True, weight=weight)
73
+ has_aligned = True if aligned == 'aligned' else False
74
+ _, restored_aligned, restored_img = face_enhancer.enhance(img, has_aligned=has_aligned, only_center_face=False, paste_back=True)
75
+ if has_aligned:
76
+ output = restored_aligned[0]
77
+ else:
78
+ output = restored_img
79
  except RuntimeError as error:
80
  print('Error', error)
81
 
 
188
  inference, [
189
  gr.Image(type="filepath", label="Input"),
190
  gr.Radio(['RestoreFormer', 'RestoreFormer++'], type="value", value='RestoreFormer++', label='version'),
191
+ gr.Radio(['aligned', 'unaligned'], type="value", value='unaligned', label='Image Alignment'),
192
  gr.Number(label="Rescaling factor", value=2),
193
  ], [
194
  gr.Image(type="numpy", label="Output (The whole image)"),
 
197
  title=title,
198
  description=description,
199
  article=article,
200
+ )