givkashi's picture
Update app.py
f23c87b
raw
history blame
1.87 kB
import os
# os.system("wget https://github.com/JingyunLiang/SwinIR/releases/download/v0.0/003_realSR_BSRGAN_DFOWMFC_s64w8_SwinIR-L_x4_GAN.pth -P experiments/pretrained_models")
import gradio as gr
from PIL import Image, ImageOps
import numpy as np
os.system("pip install opencv-python")
os.system("pip install torch")
#os.system("pip install requirements.txt")
if not os.path.exists("data"):
os.mkdir("data")
if not os.path.exists("results"):
os.mkdir("results")
# os.rename("003_realSR_BSRGAN_DFOWMFC_s64w8_SwinIR-L_x4_GAN.pth", "experiments/pretrained_models/003_realSR_BSRGAN_DFOWMFC_s64w8_SwinIR-L_x4_GAN.pth")
def infer(img):
#img = ImageOps.contain(img, (700, 700))
width, height = img.size
res=np.ones_like((width, height,3))
print(res.shape)
print(width)
img.save("./data/data.png")
img.save("./results/data.png")
os.system('python main_test_swinir.py')
res=Image.open("./results/data.png")
#return res
return "./results/data.png","./results/data.png"
inputs = [gr.inputs.Image(type='pil', label="Original Image")]
outputs = [gr.outputs.Image(type="file", label="output"), gr.outputs.File(label="download")]
title = "SwinIR: Image Restoration Using Swin Transformer,Super-Resolution part "
description = "Gradio demo for SwinIR: Super-Resolution part. To use it, simply upload your image, or click one of the examples to load them. Read more at the links below."
article = "<p style='text-align: center'><a href='https://arxiv.org/pdf/2108.10257.pdf' target='_blank'>SwinIR: Image Restoration Using Swin Transformer</a> | <a href='https://github.com/JingyunLiang/SwinIR' target='_blank'>Github Repo</a></p>"
examples = [
['butterfly.png']
]
gr.Interface(infer, inputs, outputs, title=title, description=description, article=article, examples=examples).launch(
enable_queue=True, cache_examples=True)