Files changed (1) hide show
  1. app.py +0 -69
app.py CHANGED
@@ -1,69 +0,0 @@
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)
20
- call(command, shell=True)
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
-