|
import os |
|
import sys |
|
import gradio as gr |
|
from PIL import Image |
|
|
|
|
|
os.system("git clone https://github.com/codeslake/RefVSR.git") |
|
os.chdir("RefVSR") |
|
os.system("./install/install_cudnn113.sh") |
|
|
|
|
|
os.mkdir("ckpt") |
|
os.system("wget https://huggingface.co/spaces/codeslake/RefVSR/resolve/main/RefVSR_small_MFID_8K.pytorch -O ckpt/RefVSR_small_MFID_8K.pytorch") |
|
os.system("wget https://huggingface.co/spaces/codeslake/RefVSR/resolve/main/RefVSR_MFID_8K.pytorch -O ckpt/RefVSR_MFID_8K.pytorch") |
|
os.system("wget https://huggingface.co/spaces/codeslake/RefVSR/resolve/main/RefVSR_MFID.pytorch -O ckpt/RefVSR_MFID.pytorch") |
|
|
|
os.system("wget https://huggingface.co/spaces/codeslake/RefVSR/resolve/main/SPyNet.pytorch -O ckpt/SPyNet.pytorch") |
|
|
|
sys.path.append("RefVSR") |
|
|
|
|
|
|
|
|
|
|
|
LR_path = "test/RealMCVSR/test/LRx4/UW/0000" |
|
Ref_path = "test/RealMCVSR/test/LRx4/W/0000" |
|
Ref_path_T = "test/RealMCVSR/test/LRx4/T/0000" |
|
os.makedirs(LR_path) |
|
os.makedirs(Ref_path) |
|
os.makedirs(Ref_path_T) |
|
os.makedirs('result') |
|
|
|
|
|
|
|
os.system("wget https://www.dropbox.com/s/vqekqdz80d85gi4/UW.png -O LR.png") |
|
os.system("wget https://www.dropbox.com/s/lsopmquhpm87v83/W.png -O Ref.png") |
|
|
|
|
|
def resize(img): |
|
max_side = 512 |
|
w = img.size[0] |
|
h = img.size[1] |
|
if max(h, w) > max_side: |
|
scale_ratio = max_side / max(h, w) |
|
wsize=int(w*scale_ratio) |
|
hsize=int(h*scale_ratio) |
|
img = img.resize((wsize,hsize), Image.ANTIALIAS) |
|
return img |
|
|
|
def inference(LR, Ref): |
|
|
|
|
|
|
|
LR.save(os.path.join(LR_path, '0000.png')) |
|
Ref.save(os.path.join(Ref_path, '0000.png')) |
|
Ref.save(os.path.join(Ref_path_T, '0000.png')) |
|
|
|
os.system("python -B run.py \ |
|
--mode RefVSR_MFID \ |
|
--config config_RefVSR_MFID \ |
|
--data RealMCVSR \ |
|
--ckpt_abs_name ckpt/RefVSR_MFID.pytorch \ |
|
--data_offset ./test \ |
|
--output_offset ./result \ |
|
--qualitative_only \ |
|
--cpu \ |
|
--is_gradio") |
|
|
|
return "result/0000.png" |
|
|
|
title="RefVSR (under construction)" |
|
description="Demo application for Reference-based Video Super-Resolution (RefVSR). Upload a low-resolution frame and a reference frame to 'LR' and 'Ref' input windows, respectively." |
|
|
|
article = "<p style='text-align: center'><b>To check the full capability of the module, we recommend to clone Github repository and run RefVSR models on videos using GPUs.</b></p><p style='text-align: center'>This demo runs on CPUs and only supports RefVSR for a single LR and Ref frame due to computational complexity. Hence, the model will not take advantage of temporal LR and Ref frames.</p><p style='text-align: center'>The model is trained proposed two-stage training strategy, and the sample frames are in 430x270 resolution and saved in the PNG format. </p><p style='text-align: center'><a href='https://junyonglee.me/projects/RefVSR' target='_blank'>Project</a> | <a href='https://arxiv.org/abs/2203.14537' target='_blank'>arXiv</a> | <a href='https://github.com/codeslake/RefVSR' target='_blank'>Github</a></p>" |
|
|
|
|
|
|
|
|
|
examples=[['LR.png', 'Ref.png']] |
|
|
|
gr.Interface(inference,[gr.inputs.Image(type="pil"), gr.inputs.Image(type="pil")],gr.outputs.Image(type="file"),title=title,description=description,article=article,theme ="peach",examples=examples).launch(enable_queue=True) |
|
|