Spaces:
Build error
Build error
Update
Browse files- RealESRGAN_x4plus.pth +3 -0
- RealESRGAN_x4plus_anime_6B.pth +3 -0
- app.py +59 -49
- bear.jpg +0 -0
RealESRGAN_x4plus.pth
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:4fa0d38905f75ac06eb49a7951b426670021be3018265fd191d2125df9d682f1
|
| 3 |
+
size 67040989
|
RealESRGAN_x4plus_anime_6B.pth
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:f872d837d3c90ed2e05227bed711af5671a6fd1c9f7d7e91c911a61f155e99da
|
| 3 |
+
size 17938799
|
app.py
CHANGED
|
@@ -1,68 +1,78 @@
|
|
| 1 |
-
import os
|
| 2 |
-
os.system("pip install gradio==2.9b23")
|
| 3 |
-
import random
|
| 4 |
import gradio as gr
|
| 5 |
-
|
| 6 |
-
import
|
| 7 |
-
from
|
| 8 |
-
import
|
| 9 |
-
from
|
| 10 |
-
import
|
|
|
|
| 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)
|
| 21 |
-
call(command, shell=True)
|
| 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 inference(
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
if mode == "base":
|
| 46 |
-
run_cmd("python inference_realesrgan.py -n RealESRGAN_x4plus -i "+ INPUT_DIR + " -o " + OUTPUT_DIR)
|
| 47 |
else:
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
|
| 53 |
-
|
| 54 |
title = "Real-ESRGAN"
|
| 55 |
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"
|
| 56 |
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>"
|
| 57 |
|
| 58 |
gr.Interface(
|
| 59 |
-
inference,
|
| 60 |
-
[
|
| 61 |
-
|
|
|
|
|
|
|
|
|
|
| 62 |
title=title,
|
| 63 |
description=description,
|
| 64 |
article=article,
|
| 65 |
-
examples=[
|
| 66 |
-
|
| 67 |
-
['anime.png','anime']
|
| 68 |
-
]).launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import imageio
|
| 3 |
+
import numpy as np
|
| 4 |
+
from PIL import Image, ImageSequence
|
| 5 |
+
from tempfile import TemporaryFile
|
| 6 |
+
from pathlib import Path
|
| 7 |
+
from basicsr.archs.rrdbnet_arch import RRDBNet
|
| 8 |
+
from realesrgan import RealESRGANer
|
| 9 |
|
| 10 |
+
upsampler = RealESRGANer(
|
| 11 |
+
scale=4,
|
| 12 |
+
model_path=str(Path(__file__).parent.joinpath("RealESRGAN_x4plus_anime_6B.pth")),
|
| 13 |
+
model=RRDBNet(
|
| 14 |
+
num_in_ch=3,
|
| 15 |
+
num_out_ch=3,
|
| 16 |
+
num_feat=64,
|
| 17 |
+
num_block=6,
|
| 18 |
+
num_grow_ch=32,
|
| 19 |
+
scale=4,
|
| 20 |
+
),
|
| 21 |
+
tile=100,
|
| 22 |
+
tile_pad=10,
|
| 23 |
+
pre_pad=0,
|
| 24 |
+
half=False,
|
| 25 |
+
)
|
| 26 |
|
| 27 |
|
| 28 |
+
# torch.hub.download_url_to_file('https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth', 'RealESRGAN_x4plus.pth')
|
| 29 |
|
| 30 |
+
# 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')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
|
|
|
| 32 |
|
| 33 |
|
| 34 |
+
def inference(image, mode):
|
| 35 |
+
image = Image.open(image)
|
| 36 |
+
print(image.format)
|
| 37 |
+
outputs = []
|
| 38 |
+
fd = TemporaryFile(delete=False)
|
| 39 |
+
print(fd.name)
|
| 40 |
+
is_gif = getattr(image, "is_animated", False)
|
| 41 |
+
print(is_gif)
|
| 42 |
+
if is_gif:
|
| 43 |
+
for i in ImageSequence.Iterator(image):
|
| 44 |
+
image_array: np.ndarray = np.array(i)
|
| 45 |
+
output, _ = upsampler.enhance(image_array, 4)
|
| 46 |
+
outputs.append(output)
|
|
|
|
|
|
|
| 47 |
else:
|
| 48 |
+
image_array: np.ndarray = np.array(image)
|
| 49 |
+
output, _ = upsampler.enhance(image_array, 4)
|
| 50 |
+
if is_gif:
|
| 51 |
+
imageio.mimsave(
|
| 52 |
+
fd,
|
| 53 |
+
outputs[1:],
|
| 54 |
+
format="gif",
|
| 55 |
+
duration=image.info["duration"] / 1000,
|
| 56 |
+
)
|
| 57 |
+
else:
|
| 58 |
+
img = Image.fromarray(output)
|
| 59 |
+
img.save(fd, format="PNG") # format: PNG / JPEG
|
| 60 |
+
return fd.name
|
| 61 |
|
| 62 |
|
|
|
|
| 63 |
title = "Real-ESRGAN"
|
| 64 |
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"
|
| 65 |
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>"
|
| 66 |
|
| 67 |
gr.Interface(
|
| 68 |
+
inference,
|
| 69 |
+
[
|
| 70 |
+
gr.Image(type="filepath", label="Input"),
|
| 71 |
+
gr.Radio(["base", "anime"], type="value", label="model type"),
|
| 72 |
+
],
|
| 73 |
+
gr.Image(type="file", label="Output"),
|
| 74 |
title=title,
|
| 75 |
description=description,
|
| 76 |
article=article,
|
| 77 |
+
examples=[["bear.jpg", "base"], ["anime.png", "anime"]],
|
| 78 |
+
).launch(share=True)
|
|
|
|
|
|
bear.jpg
ADDED
|