Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Commit
·
19a285e
1
Parent(s):
a29aebb
Upload app.py with huggingface_hub
Browse files
app.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
|
| 3 |
+
import kornia as K
|
| 4 |
+
from kornia.core import Tensor
|
| 5 |
+
|
| 6 |
+
import numpy as np
|
| 7 |
+
|
| 8 |
+
def rescale_aa(file, height, width):
|
| 9 |
+
|
| 10 |
+
img: Tensor = K.io.load_image(file.name, K.io.ImageLoadType.RGB32)
|
| 11 |
+
img = img[None]
|
| 12 |
+
|
| 13 |
+
img_rescale: Tensor = K.geometry.rescale(img, (float(height),float(width)),antialias=False)
|
| 14 |
+
img_rescale_aa: Tensor = K.geometry.rescale(img, (float(height),float(width)),antialias=True)
|
| 15 |
+
img_rescale = K.utils.tensor_to_image(img_rescale)
|
| 16 |
+
img_rescale_aa = K.utils.tensor_to_image(img_rescale_aa)
|
| 17 |
+
img_out = np.concatenate([img_rescale,img_rescale_aa],axis=1)
|
| 18 |
+
|
| 19 |
+
# when antialiasing , some values are going greater than 1 i.e 1.00001 which is giving error while displaying the output image,so clipping the output values from 0 to 1
|
| 20 |
+
return np.clip(img_out ,0,1)
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
examples = [
|
| 24 |
+
["examples/a.png",1,1],
|
| 25 |
+
["examples/iron_man.jpeg",1,1],
|
| 26 |
+
]
|
| 27 |
+
|
| 28 |
+
kornia_resizing_demo = gr.Interface(
|
| 29 |
+
rescale_aa,
|
| 30 |
+
[
|
| 31 |
+
gr.inputs.Image(type="file"),
|
| 32 |
+
gr.inputs.Slider(minimum=0.005, maximum=2, step=0.005, default=1, label="Height"),
|
| 33 |
+
gr.inputs.Slider(minimum=0.005, maximum=2, step=0.005, default=1, label="Width")
|
| 34 |
+
],
|
| 35 |
+
"image",
|
| 36 |
+
examples=examples,
|
| 37 |
+
live=False,
|
| 38 |
+
enable_queue = True,
|
| 39 |
+
allow_flagging = "never"
|
| 40 |
+
)
|
| 41 |
+
|
| 42 |
+
kornia_resizing_demo.launch()
|