Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,20 +1,19 @@
|
|
| 1 |
import os
|
| 2 |
-
os.system("pip install gradio==2.9b23")
|
| 3 |
import random
|
|
|
|
| 4 |
import gradio as gr
|
| 5 |
from PIL import Image
|
| 6 |
import torch
|
| 7 |
-
from random import randint
|
| 8 |
-
import sys
|
| 9 |
from subprocess import call
|
| 10 |
-
import psutil
|
| 11 |
-
|
| 12 |
-
|
| 13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
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')
|
| 16 |
-
|
| 17 |
-
|
| 18 |
def run_cmd(command):
|
| 19 |
try:
|
| 20 |
print(command)
|
|
@@ -22,47 +21,121 @@ def run_cmd(command):
|
|
| 22 |
except KeyboardInterrupt:
|
| 23 |
print("Process interrupted")
|
| 24 |
sys.exit(1)
|
| 25 |
-
run_cmd("wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth -P .")
|
| 26 |
-
run_cmd("pip install basicsr")
|
| 27 |
-
run_cmd("pip freeze")
|
| 28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
os.system("wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.4/RealESRGAN_x4plus_anime_6B.pth -P .")
|
| 30 |
|
|
|
|
| 31 |
|
| 32 |
-
def
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
INPUT_DIR = "/tmp/input_image" + str(_id) + "/"
|
| 35 |
OUTPUT_DIR = "/tmp/output_image" + str(_id) + "/"
|
| 36 |
run_cmd("rm -rf " + INPUT_DIR)
|
| 37 |
run_cmd("rm -rf " + OUTPUT_DIR)
|
| 38 |
run_cmd("mkdir " + INPUT_DIR)
|
| 39 |
run_cmd("mkdir " + OUTPUT_DIR)
|
|
|
|
| 40 |
basewidth = 256
|
| 41 |
-
wpercent = (basewidth/float(img.size[0]))
|
| 42 |
-
hsize = int((float(img.size[1])*float(wpercent)))
|
| 43 |
-
img = img.resize((basewidth,hsize), Image.LANCZOS)
|
| 44 |
img.save(INPUT_DIR + "1.jpg", "JPEG")
|
|
|
|
| 45 |
if mode == "base":
|
| 46 |
-
run_cmd("python inference_realesrgan.py -n RealESRGAN_x4plus -i "+ INPUT_DIR + " -o " + OUTPUT_DIR)
|
| 47 |
else:
|
| 48 |
-
|
|
|
|
| 49 |
return os.path.join(OUTPUT_DIR, "1_out.jpg")
|
| 50 |
|
| 51 |
-
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
[gr.inputs.Image(type="pil", label="Input"),gr.inputs.Radio(["base","anime"], type="value", default="base", label="model type")],
|
| 61 |
-
gr.outputs.Image(type="file", label="Output"),
|
| 62 |
-
title=title,
|
| 63 |
-
description=description,
|
| 64 |
-
article=article,
|
| 65 |
-
examples=[
|
| 66 |
-
['bear.jpg','base'],
|
| 67 |
-
['anime.png','anime']
|
| 68 |
-
]).launch()
|
|
|
|
| 1 |
import os
|
|
|
|
| 2 |
import random
|
| 3 |
+
os.system("pip install gradio==2.9b23")
|
| 4 |
import gradio as gr
|
| 5 |
from PIL import Image
|
| 6 |
import torch
|
|
|
|
|
|
|
| 7 |
from subprocess import call
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
+
# Install necessary packages
|
| 10 |
+
os.system("pip install gradio==2.9b23")
|
| 11 |
+
os.system("pip install basicsr")
|
| 12 |
+
os.system("wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth -P .")
|
| 13 |
+
os.system("wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.4/RealESRGAN_x4plus_anime_6B.pth -P .")
|
| 14 |
|
| 15 |
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')
|
| 16 |
+
|
|
|
|
| 17 |
def run_cmd(command):
|
| 18 |
try:
|
| 19 |
print(command)
|
|
|
|
| 21 |
except KeyboardInterrupt:
|
| 22 |
print("Process interrupted")
|
| 23 |
sys.exit(1)
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
+
def inference(img, mode):
|
| 26 |
+
_id = random.randint(1, 10000)
|
| 27 |
+
INPUT_DIR = "/tmp/input_image" + str(_id) + "/"
|
| 28 |
+
OUTPUT_DIR = "/tmp/output_image" + str(_id) + "/"
|
| 29 |
+
run_cmd("rm -rf " + INPUT_DIR)
|
| 30 |
+
run_cmd("rm -rf " + OUTPUT_DIR)
|
| 31 |
+
run_cmd("mkdir " + INPUT_DIR)
|
| 32 |
+
run_cmd("mkdir " + OUTPUT_DIR)
|
| 33 |
+
|
| 34 |
+
basewidth = 256
|
| 35 |
+
wpercent = (basewidth / float(img.size[0]))
|
| 36 |
+
hsize = int((float(img.size[1]) * float(wpercent)))
|
| 37 |
+
img = img.resize((basewidth, hsize), Image.LANCZOS)
|
| 38 |
+
img.save(INPUT_DIR + "1.jpg", "JPEG")
|
| 39 |
+
|
| 40 |
+
if mode == "base":
|
| 41 |
+
run_cmd("python inference_realesrgan.py -n RealESRGAN_x4plus -i " + INPUT_DIR + " -o " + OUTPUT_DIR)
|
| 42 |
+
else:
|
| 43 |
+
run_cmd("python inference_realesrgan.py -n RealESRGAN_x4plus_anime_6B -i " + INPUT_DIR + " -o " + OUTPUT_DIR)
|
| 44 |
+
|
| 45 |
+
return os.path.join(OUTPUT_DIR, "1_out.jpg")
|
| 46 |
+
|
| 47 |
+
def main():
|
| 48 |
+
with gr.Blocks() as demo:
|
| 49 |
+
gr.Markdown("# Real-ESRGAN")
|
| 50 |
+
gr.Markdown(
|
| 51 |
+
"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."
|
| 52 |
+
"\n\n"
|
| 53 |
+
"<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>"
|
| 54 |
+
)
|
| 55 |
+
|
| 56 |
+
with gr.Row():
|
| 57 |
+
with gr.Column():
|
| 58 |
+
input_image = gr.Image(type="pil", label="Input")
|
| 59 |
+
model_type = gr.Radio(["base", "anime"], type="value", default="base", label="Model type")
|
| 60 |
+
examples = gr.Examples(examples=[['bear.jpg', 'base'], ['anime.png', 'anime']], inputs=[input_image, model_type])
|
| 61 |
+
submit_btn = gr.Button("Submit")
|
| 62 |
+
|
| 63 |
+
with gr.Column():
|
| 64 |
+
output_image = gr.Image(type="file", label="Output")
|
| 65 |
+
|
| 66 |
+
submit_btn.click(fn=inference, inputs=[input_image, model_type], outputs=output_image)
|
| 67 |
+
|
| 68 |
+
demo.launch()
|
| 69 |
+
|
| 70 |
+
if __name__ == "__main__":
|
| 71 |
+
main()
|
| 72 |
+
import os
|
| 73 |
+
import random
|
| 74 |
+
import gradio as gr
|
| 75 |
+
from PIL import Image
|
| 76 |
+
import torch
|
| 77 |
+
from subprocess import call
|
| 78 |
+
|
| 79 |
+
# Install necessary packages
|
| 80 |
+
|
| 81 |
+
os.system("pip install basicsr")
|
| 82 |
+
os.system("wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth -P .")
|
| 83 |
os.system("wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.4/RealESRGAN_x4plus_anime_6B.pth -P .")
|
| 84 |
|
| 85 |
+
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')
|
| 86 |
|
| 87 |
+
def run_cmd(command):
|
| 88 |
+
try:
|
| 89 |
+
print(command)
|
| 90 |
+
call(command, shell=True)
|
| 91 |
+
except KeyboardInterrupt:
|
| 92 |
+
print("Process interrupted")
|
| 93 |
+
sys.exit(1)
|
| 94 |
+
|
| 95 |
+
def inference(img, mode):
|
| 96 |
+
_id = random.randint(1, 10000)
|
| 97 |
INPUT_DIR = "/tmp/input_image" + str(_id) + "/"
|
| 98 |
OUTPUT_DIR = "/tmp/output_image" + str(_id) + "/"
|
| 99 |
run_cmd("rm -rf " + INPUT_DIR)
|
| 100 |
run_cmd("rm -rf " + OUTPUT_DIR)
|
| 101 |
run_cmd("mkdir " + INPUT_DIR)
|
| 102 |
run_cmd("mkdir " + OUTPUT_DIR)
|
| 103 |
+
|
| 104 |
basewidth = 256
|
| 105 |
+
wpercent = (basewidth / float(img.size[0]))
|
| 106 |
+
hsize = int((float(img.size[1]) * float(wpercent)))
|
| 107 |
+
img = img.resize((basewidth, hsize), Image.LANCZOS)
|
| 108 |
img.save(INPUT_DIR + "1.jpg", "JPEG")
|
| 109 |
+
|
| 110 |
if mode == "base":
|
| 111 |
+
run_cmd("python inference_realesrgan.py -n RealESRGAN_x4plus -i " + INPUT_DIR + " -o " + OUTPUT_DIR)
|
| 112 |
else:
|
| 113 |
+
run_cmd("python inference_realesrgan.py -n RealESRGAN_x4plus_anime_6B -i " + INPUT_DIR + " -o " + OUTPUT_DIR)
|
| 114 |
+
|
| 115 |
return os.path.join(OUTPUT_DIR, "1_out.jpg")
|
| 116 |
|
| 117 |
+
def main():
|
| 118 |
+
with gr.Blocks() as demo:
|
| 119 |
+
gr.Markdown("# Real-ESRGAN")
|
| 120 |
+
gr.Markdown(
|
| 121 |
+
"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."
|
| 122 |
+
"\n\n"
|
| 123 |
+
"<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>"
|
| 124 |
+
)
|
| 125 |
|
| 126 |
+
with gr.Row():
|
| 127 |
+
with gr.Column():
|
| 128 |
+
input_image = gr.Image(type="pil", label="Input")
|
| 129 |
+
model_type = gr.Radio(["base", "anime"], type="value", default="base", label="Model type")
|
| 130 |
+
examples = gr.Examples(examples=[['bear.jpg', 'base'], ['anime.png', 'anime']], inputs=[input_image, model_type])
|
| 131 |
+
submit_btn = gr.Button("Submit")
|
| 132 |
+
|
| 133 |
+
with gr.Column():
|
| 134 |
+
output_image = gr.Image(type="file", label="Output")
|
| 135 |
+
|
| 136 |
+
submit_btn.click(fn=inference, inputs=[input_image, model_type], outputs=output_image)
|
| 137 |
+
|
| 138 |
+
demo.launch()
|
| 139 |
|
| 140 |
+
if __name__ == "__main__":
|
| 141 |
+
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|