Spaces:
Running
Running
Attempt to revert partially
Browse files
app.py
CHANGED
|
@@ -6,12 +6,14 @@ import torch
|
|
| 6 |
from random import randint
|
| 7 |
import sys
|
| 8 |
from subprocess import call
|
|
|
|
|
|
|
| 9 |
|
| 10 |
-
# Updating Gradio to a more current version
|
| 11 |
-
# os.system("pip install gradio")
|
| 12 |
|
| 13 |
-
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')
|
| 14 |
|
|
|
|
|
|
|
|
|
|
| 15 |
def run_cmd(command):
|
| 16 |
try:
|
| 17 |
print(command)
|
|
@@ -19,33 +21,35 @@ def run_cmd(command):
|
|
| 19 |
except KeyboardInterrupt:
|
| 20 |
print("Process interrupted")
|
| 21 |
sys.exit(1)
|
| 22 |
-
|
| 23 |
run_cmd("wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth -P .")
|
| 24 |
run_cmd("pip install basicsr")
|
| 25 |
run_cmd("pip freeze")
|
| 26 |
|
| 27 |
os.system("wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.4/RealESRGAN_x4plus_anime_6B.pth -P .")
|
| 28 |
|
| 29 |
-
|
|
|
|
| 30 |
_id = randint(1, 10000)
|
| 31 |
-
INPUT_DIR =
|
| 32 |
-
OUTPUT_DIR =
|
| 33 |
-
|
| 34 |
-
run_cmd(
|
| 35 |
-
run_cmd(
|
| 36 |
-
run_cmd(
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
img.
|
| 40 |
-
|
| 41 |
-
|
| 42 |
if mode == "base":
|
| 43 |
-
run_cmd(
|
| 44 |
else:
|
| 45 |
-
os.system(
|
| 46 |
-
|
| 47 |
return os.path.join(OUTPUT_DIR, "1_out.png")
|
| 48 |
|
|
|
|
|
|
|
|
|
|
| 49 |
title = "Real-ESRGAN"
|
| 50 |
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"
|
| 51 |
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>"
|
|
|
|
| 6 |
from random import randint
|
| 7 |
import sys
|
| 8 |
from subprocess import call
|
| 9 |
+
import psutil
|
| 10 |
+
|
| 11 |
|
|
|
|
|
|
|
| 12 |
|
|
|
|
| 13 |
|
| 14 |
+
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')
|
| 15 |
+
|
| 16 |
+
|
| 17 |
def run_cmd(command):
|
| 18 |
try:
|
| 19 |
print(command)
|
|
|
|
| 21 |
except KeyboardInterrupt:
|
| 22 |
print("Process interrupted")
|
| 23 |
sys.exit(1)
|
|
|
|
| 24 |
run_cmd("wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth -P .")
|
| 25 |
run_cmd("pip install basicsr")
|
| 26 |
run_cmd("pip freeze")
|
| 27 |
|
| 28 |
os.system("wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.4/RealESRGAN_x4plus_anime_6B.pth -P .")
|
| 29 |
|
| 30 |
+
|
| 31 |
+
def inference(img,mode):
|
| 32 |
_id = randint(1, 10000)
|
| 33 |
+
INPUT_DIR = "./tmp/input_image" + str(_id) + "/"
|
| 34 |
+
OUTPUT_DIR = "./tmp/output_image" + str(_id) + "/"
|
| 35 |
+
run_cmd("rm -rf " + INPUT_DIR)
|
| 36 |
+
run_cmd("rm -rf " + OUTPUT_DIR)
|
| 37 |
+
run_cmd("mkdir -p " + INPUT_DIR)
|
| 38 |
+
run_cmd("mkdir -p " + OUTPUT_DIR)
|
| 39 |
+
basewidth = 256
|
| 40 |
+
wpercent = (basewidth/float(img.size[0]))
|
| 41 |
+
hsize = int((float(img.size[1])*float(wpercent)))
|
| 42 |
+
#img = img.resize((basewidth,hsize), Image.LANCZOS)
|
| 43 |
+
img.save(INPUT_DIR + "1.png", "PNG")
|
| 44 |
if mode == "base":
|
| 45 |
+
run_cmd("python inference_realesrgan.py -n RealESRGAN_x4plus -i "+ INPUT_DIR + " -o " + OUTPUT_DIR)
|
| 46 |
else:
|
| 47 |
+
os.system("python inference_realesrgan.py -n RealESRGAN_x4plus_anime_6B -i "+ INPUT_DIR + " -o " + OUTPUT_DIR)
|
|
|
|
| 48 |
return os.path.join(OUTPUT_DIR, "1_out.png")
|
| 49 |
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
|
| 53 |
title = "Real-ESRGAN"
|
| 54 |
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"
|
| 55 |
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>"
|