Spaces:
Runtime error
Runtime error
added upscaler
Browse files- app.py +41 -0
- requirements.txt +5 -0
app.py
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
from PIL import Image
|
4 |
+
import torch
|
5 |
+
|
6 |
+
|
7 |
+
model_id = "caidas/swin2SR-classical-sr-x2-64"
|
8 |
+
upscaler = pipeline("image-to-image", model=model_id)
|
9 |
+
|
10 |
+
|
11 |
+
|
12 |
+
def upscale(input_img):
|
13 |
+
low_res_img = resize_on_scale(input_img)
|
14 |
+
upscaled_img = upscaler(low_res_img)
|
15 |
+
print("Low resolution image size = ", low_res_img.size)
|
16 |
+
print("Upscaled image size = ", upscaled_img.size)
|
17 |
+
return upscaled_img
|
18 |
+
|
19 |
+
|
20 |
+
def resize_on_scale(input_img):
|
21 |
+
low_res_img = input_img.convert("RGB")
|
22 |
+
wsize = 300
|
23 |
+
wpercent = (wsize / float(input_img.size[0]))
|
24 |
+
hsize = int((float(input_img.size[1]) * float(wpercent)))
|
25 |
+
low_res_img = low_res_img.resize((wsize, hsize))
|
26 |
+
return low_res_img
|
27 |
+
|
28 |
+
|
29 |
+
gradio_app = gr.Interface(
|
30 |
+
upscale,
|
31 |
+
inputs=gr.Image(label="Select a blurry image", sources=['upload', 'webcam', 'clipboard'], type="pil"),
|
32 |
+
outputs=gr.Image(label="Processed Image"),
|
33 |
+
title="Image Upscaler",
|
34 |
+
)
|
35 |
+
|
36 |
+
if __name__ == "__main__":
|
37 |
+
gradio_app.launch()
|
38 |
+
|
39 |
+
|
40 |
+
|
41 |
+
|
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gradio==4.19.2
|
2 |
+
Pillow==9.4.0
|
3 |
+
Pillow==10.2.0
|
4 |
+
torch==2.2.1+cu118
|
5 |
+
transformers==4.38.1
|