Ahsen Khaliq
commited on
Commit
·
ff27b25
1
Parent(s):
7f8b5d7
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
os.system('pip install gradio --upgrade')
|
3 |
+
os.system('pip freeze')
|
4 |
+
import random
|
5 |
+
import gradio as gr
|
6 |
+
from PIL import Image
|
7 |
+
import torch
|
8 |
+
from random import randint
|
9 |
+
import sys
|
10 |
+
from subprocess import call
|
11 |
+
import psutil
|
12 |
+
torch.hub.download_url_to_file('http://people.csail.mit.edu/billf/project%20pages/sresCode/Markov%20Random%20Fields%20for%20Super-Resolution_files/100075_lowres.jpg', 'bear.jpg')
|
13 |
+
|
14 |
+
|
15 |
+
def run_cmd(command):
|
16 |
+
try:
|
17 |
+
print(command)
|
18 |
+
call(command, shell=True)
|
19 |
+
except KeyboardInterrupt:
|
20 |
+
print("Process interrupted")
|
21 |
+
sys.exit(1)
|
22 |
+
run_cmd("wget https://github.com/TencentARC/GFPGAN/releases/download/v0.2.0/GFPGANCleanv1-NoCE-C2.pth -P .")
|
23 |
+
|
24 |
+
run_cmd("pip install basicsr")
|
25 |
+
run_cmd("pip freeze")
|
26 |
+
#run_cmd("python setup.py develop")
|
27 |
+
def inference(img):
|
28 |
+
_id = randint(1, 10000)
|
29 |
+
INPUT_DIR = "/tmp/input_image" + str(_id) + "/"
|
30 |
+
OUTPUT_DIR = "/tmp/output_image" + str(_id) + "/"
|
31 |
+
run_cmd("rm -rf " + INPUT_DIR)
|
32 |
+
run_cmd("rm -rf " + OUTPUT_DIR)
|
33 |
+
run_cmd("mkdir " + INPUT_DIR)
|
34 |
+
run_cmd("mkdir " + OUTPUT_DIR)
|
35 |
+
basewidth = 256
|
36 |
+
wpercent = (basewidth/float(img.size[0]))
|
37 |
+
hsize = int((float(img.size[1])*float(wpercent)))
|
38 |
+
img = img.resize((basewidth,hsize), Image.ANTIALIAS)
|
39 |
+
img.save(INPUT_DIR + "1.jpg", "JPEG")
|
40 |
+
run_cmd("python inference_gfpgan.py --upscale 2 --test_path "+ INPUT_DIR + " --save_root " + OUTPUT_DIR)
|
41 |
+
return os.path.join(OUTPUT_DIR, "1_out.jpg")
|
42 |
+
|
43 |
+
title = "Real-ESRGAN"
|
44 |
+
description = "Gradio demo for Real-ESRGAN. 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"
|
45 |
+
article = "<p style='text-align: center'><a href='https://arxiv.org/abs/2107.10833'>Real-ESRGAN: Training Real-World Blind Super-Resolution with Pure Synthetic Data</a> | <a href='https://github.com/xinntao/Real-ESRGAN'>Github Repo</a></p>"
|
46 |
+
gr.Interface(
|
47 |
+
inference,
|
48 |
+
[gr.inputs.Image(type="pil", label="Input")],
|
49 |
+
gr.outputs.Image(type="file", label="Output"),
|
50 |
+
title=title,
|
51 |
+
description=description,
|
52 |
+
article=article,
|
53 |
+
examples=[
|
54 |
+
['bear.jpg']
|
55 |
+
],
|
56 |
+
enable_queue=True
|
57 |
+
).launch(debug=True)
|