KenjieDec commited on
Commit
6ab882a
1 Parent(s): 33e6cd6
Files changed (1) hide show
  1. app.py +6 -4
app.py CHANGED
@@ -23,7 +23,8 @@ def inference(file, mode):
23
  im = cv2.imread(file, cv2.IMREAD_COLOR)
24
  faceenhancer = FaceEnhancement(size=model['size'], model=model['name'], channel_multiplier=2, device='cpu')
25
  img, orig_faces, enhanced_faces = faceenhancer.process(im)
26
- return img
 
27
  else:
28
  model = {'name':'GPEN-1024-Color', 'size':1024}
29
  grayf = cv2.imread(file, cv2.IMREAD_GRAYSCALE)
@@ -32,7 +33,8 @@ def inference(file, mode):
32
  colorf = facecolorizer.process(grayf)
33
 
34
  colorf = cv2.resize(colorf, (grayf.shape[1], grayf.shape[0]))
35
- return colorf
 
36
 
37
  title = "GPEN"
38
  description = "Gradio demo for GAN Prior Embedded Network for Blind Face Restoration in the Wild. This version of gradio demo includes face colorization from GPEN. To use it, simply upload your image, or click one of the examples to load them. Read more at the links below."
@@ -42,8 +44,8 @@ article = "<p style='text-align: center'><a href='https://arxiv.org/abs/2105.060
42
 
43
  gr.Interface(
44
  inference,
45
- [gr.inputs.Image(type="filepath", label="Input"),gr.inputs.Radio(["enhance","colorize"], type="value", default="enhance", label="model type")],
46
- gr.outputs.Image(type="numpy", label="Output"),
47
  title=title,
48
  description=description,
49
  article=article,
 
23
  im = cv2.imread(file, cv2.IMREAD_COLOR)
24
  faceenhancer = FaceEnhancement(size=model['size'], model=model['name'], channel_multiplier=2, device='cpu')
25
  img, orig_faces, enhanced_faces = faceenhancer.process(im)
26
+ cv2.imwrite(os.path.join("output.png"), img)
27
+ return os.path.join("output.png")
28
  else:
29
  model = {'name':'GPEN-1024-Color', 'size':1024}
30
  grayf = cv2.imread(file, cv2.IMREAD_GRAYSCALE)
 
33
  colorf = facecolorizer.process(grayf)
34
 
35
  colorf = cv2.resize(colorf, (grayf.shape[1], grayf.shape[0]))
36
+ cv2.imwrite(os.path.join("output.png"), colorf)
37
+ return os.path.join("output.png")
38
 
39
  title = "GPEN"
40
  description = "Gradio demo for GAN Prior Embedded Network for Blind Face Restoration in the Wild. This version of gradio demo includes face colorization from GPEN. To use it, simply upload your image, or click one of the examples to load them. Read more at the links below."
 
44
 
45
  gr.Interface(
46
  inference,
47
+ [gr.inputs.Image(type="filepath", label="Input"),gr.inputs.Radio(["enhance","colorize"], type="value", default="enhance", label="Type")],
48
+ gr.outputs.Image(type="file", label="Output"),
49
  title=title,
50
  description=description,
51
  article=article,