import os os.system('wget "https://public-vigen-video.oss-cn-shanghai.aliyuncs.com/robin/models/RetinaFace-R50.pth?OSSAccessKeyId=LTAI4G6bfnyW4TA4wFUXTYBe&Expires=1961116085&Signature=GlUNW6%2B8FxvxWmE9jKIZYOOciKQ%3D" -O weights/RetinaFace-R50.pth') os.system('wget "https://public-vigen-video.oss-cn-shanghai.aliyuncs.com/robin/models/GPEN-BFR-512.pth?OSSAccessKeyId=LTAI4G6bfnyW4TA4wFUXTYBe&Expires=1961116208&Signature=hBgvVvKVSNGeXqT8glG%2Bd2t2OKc%3D" -O weights/GPEN-512.pth') os.system('wget "https://public-vigen-video.oss-cn-shanghai.aliyuncs.com/robin/models/GPEN-Colorization-1024.pth?OSSAccessKeyId=LTAI4G6bfnyW4TA4wFUXTYBe&Expires=1961116315&Signature=9tPavW2h%2F1LhIKiXj73sTQoWqcc%3D" -O weights/GPEN-1024-Color.pth ') import gradio as gr ''' @paper: GAN Prior Embedded Network for Blind Face Restoration in the Wild (CVPR2021) @author: yangxy (yangtao9009@gmail.com) ''' import os import cv2 from face_enhancement import FaceEnhancement from face_colorization import FaceColorization def inference(file, mode): if mode == "enhance": model = {'name':'GPEN-512', 'size':512} im = cv2.imread(file, cv2.IMREAD_COLOR) faceenhancer = FaceEnhancement(size=model['size'], model=model['name'], channel_multiplier=2) img, orig_faces, enhanced_faces = faceenhancer.process(im) return enhanced_faces[0][:,:,::-1] else: model = {'name':'GPEN-1024-Color', 'size':1024} grayf = cv2.imread(file, cv2.IMREAD_GRAYSCALE) grayf = cv2.cvtColor(grayf, cv2.COLOR_GRAY2BGR) # channel: 1->3 facecolorizer = FaceColorization(size=model['size'], model=model['name']) colorf = facecolorizer.process(grayf) colorf = cv2.resize(colorf, (grayf.shape[1], grayf.shape[0])) return colorf title = "GPEN" 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." article = "

GAN Prior Embedded Network for Blind Face Restoration in the Wild | Github Repo

visitor badge
" gr.Interface( inference, [gr.inputs.Image(type="filepath", label="Input"),gr.inputs.Radio(["enhance","colorize"], type="value", default="enhance", label="model type")], gr.outputs.Image(type="numpy", label="Output"), title=title, description=description, article=article, examples=[ ['sample.png'] ], enable_queue=True ).launch()