Spaces:
Runtime error
Runtime error
import gradio as gr | |
import requests | |
from PIL import Image | |
import os | |
import torch | |
from transformers import AutoImageProcessor, Swin2SRForImageSuperResolution | |
processor = AutoImageProcessor.from_pretrained("caidas/swin2SR-classical-sr-x2-64") | |
model = Swin2SRForImageSuperResolution.from_pretrained("caidas/swin2SR-classical-sr-x2-64") | |
def enhance(image): | |
# prepare image for the model | |
inputs = processor(image, return_tensors="pt") | |
# forward pass | |
with torch.no_grad(): | |
outputs = model(**inputs) | |
# postprocess | |
output = outputs.reconstruction.data.squeeze().float().cpu().clamp_(0, 1).numpy() | |
output = np.moveaxis(output, source=0, destination=-1) | |
output = (output * 255.0).round().astype(np.uint8) # float32 to uint8 | |
return Image.fromarray(output) | |
title = "Swin2SR demo for Image Super-Resolution πππ₯" | |
description = ''' | |
**This Demo expects low-quality and low-resolution JPEG compressed images, in the near future we will support any kind of input** | |
**We are looking for collaborators! Collaboratorλ₯Ό μ°Ύκ³ μμ΅λλ€!** π¬π§ πͺπΈ π°π· π«π· π·π΄ π©πͺ π¨π³ | |
**Please check our github project: https://github.com/mv-lab/swin2sr or paper: https://arxiv.org/abs/2209.11345 feel free to contact us** | |
**Demos also available at [google colab](https://colab.research.google.com/drive/1paPrt62ydwLv2U2eZqfcFsePI4X4WRR1?usp=sharing) and [Kaggle](https://www.kaggle.com/code/jesucristo/super-resolution-demo-swin2sr-official/)** | |
</br> | |
''' | |
article = "<p style='text-align: center'><a href='https://arxiv.org/abs/2209.11345' target='_blank'>Swin2SR: SwinV2 Transformer for Compressed Image Super-Resolution and Restoration</a> | <a href='https://github.com/mv-lab/swin2sr' target='_blank'>Github Repo</a></p>" | |
gr.Interface( | |
enhance, | |
gr.inputs.Image(type="pil", label="Input").style(height=260), | |
gr.inputs.Image(type="pil", label="Ouput").style(height=240), | |
title=title, | |
description=description, | |
article=article, | |
).launch(enable_queue=True) |