Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import requests
|
3 |
+
from PIL import Image
|
4 |
+
import os
|
5 |
+
import torch
|
6 |
+
from transformers import AutoImageProcessor, Swin2SRForImageSuperResolution
|
7 |
+
|
8 |
+
processor = AutoImageProcessor.from_pretrained("caidas/swin2SR-classical-sr-x2-64")
|
9 |
+
model = Swin2SRForImageSuperResolution.from_pretrained("caidas/swin2SR-classical-sr-x2-64")
|
10 |
+
|
11 |
+
def enhance(image):
|
12 |
+
# prepare image for the model
|
13 |
+
inputs = processor(image, return_tensors="pt")
|
14 |
+
|
15 |
+
# forward pass
|
16 |
+
with torch.no_grad():
|
17 |
+
outputs = model(**inputs)
|
18 |
+
|
19 |
+
# postprocess
|
20 |
+
output = outputs.reconstruction.data.squeeze().float().cpu().clamp_(0, 1).numpy()
|
21 |
+
output = np.moveaxis(output, source=0, destination=-1)
|
22 |
+
output = (output * 255.0).round().astype(np.uint8) # float32 to uint8
|
23 |
+
|
24 |
+
return Image.fromarray(output)
|
25 |
+
|
26 |
+
title = "Swin2SR demo for Image Super-Resolution πππ₯"
|
27 |
+
description = '''
|
28 |
+
|
29 |
+
**This Demo expects low-quality and low-resolution JPEG compressed images, in the near future we will support any kind of input**
|
30 |
+
|
31 |
+
**We are looking for collaborators! Collaboratorλ₯Ό μ°Ύκ³ μμ΅λλ€!** π¬π§ πͺπΈ π°π· π«π· π·π΄ π©πͺ π¨π³
|
32 |
+
|
33 |
+
**Please check our github project: https://github.com/mv-lab/swin2sr or paper: https://arxiv.org/abs/2209.11345 feel free to contact us**
|
34 |
+
|
35 |
+
**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/)**
|
36 |
+
</br>
|
37 |
+
'''
|
38 |
+
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>"
|
39 |
+
|
40 |
+
gr.Interface(
|
41 |
+
enhance,
|
42 |
+
gr.inputs.Image(type="pil", label="Input").style(height=260),
|
43 |
+
gr.inputs.Image(type="pil", label="Ouput").style(height=240),
|
44 |
+
title=title,
|
45 |
+
description=description,
|
46 |
+
article=article,
|
47 |
+
).launch(enable_queue=True)
|