ShahzebKhoso commited on
Commit
74a11a6
1 Parent(s): 462ec74

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -0
app.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoImageProcessor, Swin2SRForImageSuperResolution
3
+ from PIL import Image
4
+ import torch
5
+
6
+ # Load model and processor
7
+ processor = AutoImageProcessor.from_pretrained("caidas/swin2SR-lightweight-x4-64")
8
+ model = Swin2SRForImageSuperResolution.from_pretrained("caidas/swin2SR-lightweight-x4-64")
9
+
10
+ def upscale_image(image):
11
+ # Preprocess the input image
12
+ inputs = processor(images=image, return_tensors="pt")
13
+
14
+ # Perform super-resolution
15
+ with torch.no_grad():
16
+ outputs = model(**inputs)
17
+
18
+ # Post-process the output to get a high-resolution image
19
+ output_image = processor.postprocess(outputs.logits, target_sizes=[(image.size[1]*4, image.size[0]*4)])[0]
20
+ return output_image
21
+
22
+ # Gradio interface
23
+ iface = gr.Interface(
24
+ fn=upscale_image,
25
+ inputs=gr.Image(type="pil"),
26
+ outputs=gr.Image(type="pil"),
27
+ title="Image Super Resolution with Swin2SR",
28
+ description="Upload an image and enhance its resolution using the Swin2SR model (4x resolution)."
29
+ )
30
+
31
+ if __name__ == "__main__":
32
+ iface.launch()