MuazAshraf23 commited on
Commit
137f774
1 Parent(s): 2f5b20b

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -0
app.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import requests
3
+ from PIL import Image
4
+ import os
5
+ import torch
6
+ import numpy as np
7
+ from transformers import AutoImageProcessor, Swin2SRForImageSuperResolution
8
+
9
+
10
+ processor = AutoImageProcessor.from_pretrained("caidas/swin2SR-classical-sr-x2-64")
11
+ model = Swin2SRForImageSuperResolution.from_pretrained("caidas/swin2SR-classical-sr-x2-64")
12
+
13
+ def enhance(image):
14
+ # prepare image for the model
15
+ inputs = processor(image, return_tensors="pt")
16
+
17
+ # forward pass
18
+ with torch.no_grad():
19
+ outputs = model(**inputs)
20
+
21
+ # postprocess
22
+ output = outputs.reconstruction.data.squeeze().float().cpu().clamp_(0, 1).numpy()
23
+ output = np.moveaxis(output, source=0, destination=-1)
24
+ output = (output * 255.0).round().astype(np.uint8) # float32 to uint8
25
+
26
+ return Image.fromarray(output)
27
+
28
+ title = "Demo: Swin2SR for Image Super-Resolution 🚀🚀🔥"
29
+ description = '''
30
+ **This demo expects low-quality and low-resolution JPEG compressed images.**
31
+ **Demo notebook can be found [here](https://github.com/NielsRogge/Transformers-Tutorials/blob/master/Swin2SR/Perform_image_super_resolution_with_Swin2SR.ipynb).
32
+ '''
33
+ 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://huggingface.co/docs/transformers/main/model_doc/swin2sr' target='_blank'>HuggingFace docs</a></p>"
34
+
35
+ examples = [['00003.jpg'], ['0855.jpg'], ['ali_eye.jpg'], ['butterfly.jpg'], ['chain-eye.jpg'], ['gojou-eyes.jpg'], ['shanghai.jpg'], ['vagabond.jpg']]
36
+
37
+ gr.Interface(
38
+ enhance,
39
+ gr.inputs.Image(type="pil", label="Input").style(height=260),
40
+ gr.inputs.Image(type="pil", label="Ouput").style(height=240),
41
+ title=title,
42
+ description=description,
43
+ article=article,
44
+ examples=examples,
45
+ ).launch(enable_queue=True, share= True)