Spaces:
Runtime error
Runtime error
File size: 1,034 Bytes
c806357 ab2dd65 c806357 ab2dd65 c806357 ab2dd65 c806357 cd486cf c806357 cd486cf c806357 ce7854c c806357 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
from base64 import b64encode, b64decode
from io import BytesIO
from pathlib import Path
import numpy as np
from basicsr.archs.rrdbnet_arch import RRDBNet
from PIL import Image
from realesrgan import RealESRGANer
from huggingface_hub import hf_hub_download
import gradio as gr
import torch
device = "cuda" if torch.cuda.is_available() else "cpu"
half = True if device == "cuda" else False
model = RRDBNet(num_in_ch=3, num_out_ch=3)
upsampler = RealESRGANer(
scale=4,
model_path=hf_hub_download('nateraw/real-esrgan', 'RealESRGAN_x4plus.pth'),
model=model,
tile=0,
pre_pad=0,
half=half,
)
def upsample(image, outscale=4):
# image = np.array(image)
image = image[:, :, ::-1] # RGB -> BGR
image, _ = upsampler.enhance(image, outscale=outscale)
image = image[:, :, ::-1] # BGR -> RGB
image = Image.fromarray(image)
return image
interface = gr.Interface(
upsample,
inputs=["image", gr.Dropdown([4, 2])],
outputs=["image"]
)
if __name__ == '__main__':
interface.launch() |