Spaces:
Running
Running
Ahsen Khaliq
commited on
Commit
·
c0f3a3b
1
Parent(s):
2782137
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
os.system("wget https://public-vigen-video.oss-cn-shanghai.aliyuncs.com/robin/models/RetinaFace-R50.pth -P .")
|
3 |
+
os.system("wget https://public-vigen-video.oss-cn-shanghai.aliyuncs.com/robin/models/GPEN-BFR-512.pth -P .")
|
4 |
+
os.system("wget https://public-vigen-video.oss-cn-shanghai.aliyuncs.com/robin/models/ParseNet-latest.pth -P .")
|
5 |
+
os.system("wget https://public-vigen-video.oss-cn-shanghai.aliyuncs.com/robin/models/rrdb_realesrnet_psnr.pth -P .")
|
6 |
+
|
7 |
+
import random
|
8 |
+
import gradio as gr
|
9 |
+
from PIL import Image
|
10 |
+
import torch
|
11 |
+
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')
|
12 |
+
torch.hub.download_url_to_file('https://upload.wikimedia.org/wikipedia/commons/5/50/Albert_Einstein_%28Nobel%29.png', 'einstein.png')
|
13 |
+
import cv2
|
14 |
+
import glob
|
15 |
+
import numpy as np
|
16 |
+
|
17 |
+
|
18 |
+
def inference(img):
|
19 |
+
os.system("python face_enhancement.py --model GPEN-BFR-512 --size 512 --channel_multiplier 2 --narrow 1 --use_sr --indir examples/imgs --outdir examples/outs-BFR2")
|
20 |
+
return "examples/outs-BFR2/"
|
21 |
+
|
22 |
+
title = "GFP-GAN"
|
23 |
+
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"
|
24 |
+
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><center><img src='https://visitor-badge.glitch.me/badge?page_id=akhaliq_GFPGAN' alt='visitor badge'></center>"
|
25 |
+
gr.Interface(
|
26 |
+
inference,
|
27 |
+
[gr.inputs.Image(type="filepath", label="Input")],
|
28 |
+
gr.outputs.Image(type="pil", label="Output"),
|
29 |
+
title=title,
|
30 |
+
description=description,
|
31 |
+
article=article,
|
32 |
+
examples=[
|
33 |
+
['lincoln.jpg'],
|
34 |
+
['einstein.png']
|
35 |
+
],
|
36 |
+
enable_queue=True
|
37 |
+
).launch(debug=True)
|