Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -67,75 +67,3 @@ def main():
|
|
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()
|
|
|
67 |
|
68 |
demo.launch()
|
69 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|