GFPGAN / app.py
Ahsen Khaliq
Update app.py
2b533d9
raw
history blame
2.33 kB
import os
os.system('pip install gradio --upgrade')
os.system('pip freeze')
import random
import gradio as gr
from PIL import Image
import torch
from random import randint
import sys
from subprocess import call
import psutil
torch.hub.download_url_to_file('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', 'lincoln.jpg')
def run_cmd(command):
try:
print(command)
call(command, shell=True)
except KeyboardInterrupt:
print("Process interrupted")
sys.exit(1)
run_cmd("wget https://github.com/TencentARC/GFPGAN/releases/download/v0.2.0/GFPGANCleanv1-NoCE-C2.pth -P .")
run_cmd("pip install basicsr")
run_cmd("pip install facexlib")
run_cmd("pip freeze")
#run_cmd("python setup.py develop")
def inference(img):
_id = randint(1, 10000)
INPUT_DIR = "/tmp/input_image" + str(_id) + "/"
OUTPUT_DIR = "/tmp/output_image" + str(_id) + "/"
run_cmd("rm -rf " + INPUT_DIR)
run_cmd("rm -rf " + OUTPUT_DIR)
run_cmd("mkdir " + INPUT_DIR)
run_cmd("mkdir " + OUTPUT_DIR)
basewidth = 256
wpercent = (basewidth/float(img.size[0]))
hsize = int((float(img.size[1])*float(wpercent)))
img = img.resize((basewidth,hsize), Image.ANTIALIAS)
img.save(INPUT_DIR + "1.jpg", "JPEG")
run_cmd("python inference_gfpgan.py --upscale 2 --test_path "+ INPUT_DIR + " --save_root " + OUTPUT_DIR + " --paste_back")
return os.path.join(OUTPUT_DIR, "1_00.png")
title = "GFP-GAN"
description = "Gradio demo for GFP-GAN: Towards Real-World Blind Face Restoration with Generative Facial Prior. To use it, simply upload your image, or click one of the examples to load them. Read more at the links below. Please click submit only once"
article = "<p style='text-align: center'><a href='https://arxiv.org/abs/2101.04061'>Towards Real-World Blind Face Restoration with Generative Facial Prior</a> | <a href='https://github.com/TencentARC/GFPGAN'>Github Repo</a></p>"
gr.Interface(
inference,
[gr.inputs.Image(type="pil", label="Input")],
gr.outputs.Image(type="file", label="Output"),
title=title,
description=description,
article=article,
examples=[
['lincoln.jpg']
],
enable_queue=True
).launch(debug=True)