Tzktz commited on
Commit
4cf15a4
1 Parent(s): 2906037

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -0
app.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ os.system("pip install gfpgan")
3
+ import gradio as gr
4
+ from PIL import Image
5
+ import torch
6
+ import cv2
7
+ import glob
8
+ import numpy as np
9
+ from basicsr.utils import imwrite
10
+ from gfpgan import GFPGANer
11
+
12
+ bg_upsampler = None
13
+
14
+ # set up GFPGAN restorer
15
+ restorer = GFPGANer(
16
+ model_path='GFPGANCleanv1-NoCE-C2.pth',
17
+ upscale=2,
18
+ arch='clean',
19
+ channel_multiplier=2,
20
+ bg_upsampler=bg_upsampler)
21
+
22
+
23
+ def inference(img):
24
+ input_img = cv2.imread(img, cv2.IMREAD_COLOR)
25
+ cropped_faces, restored_faces, restored_img = restorer.enhance(
26
+ input_img, has_aligned=False, only_center_face=False, paste_back=True)
27
+
28
+ return Image.fromarray(restored_faces[0][:, :, ::-1])
29
+
30
+
31
+ title = "GFP-GAN FACE ENHANCE MODEL"
32
+ gr.Interface(
33
+ inference,
34
+ [gr.inputs.Image(type="filepath", label="Input")],
35
+ gr.outputs.Image(type="pil", label="Output"),
36
+ title=title
37
+ ).launch(enable_queue=True)