gauthamk28's picture
Upload app.py with huggingface_hub
19a285e
raw
history blame
1.32 kB
import gradio as gr
import kornia as K
from kornia.core import Tensor
import numpy as np
def rescale_aa(file, height, width):
img: Tensor = K.io.load_image(file.name, K.io.ImageLoadType.RGB32)
img = img[None]
img_rescale: Tensor = K.geometry.rescale(img, (float(height),float(width)),antialias=False)
img_rescale_aa: Tensor = K.geometry.rescale(img, (float(height),float(width)),antialias=True)
img_rescale = K.utils.tensor_to_image(img_rescale)
img_rescale_aa = K.utils.tensor_to_image(img_rescale_aa)
img_out = np.concatenate([img_rescale,img_rescale_aa],axis=1)
# 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
return np.clip(img_out ,0,1)
examples = [
["examples/a.png",1,1],
["examples/iron_man.jpeg",1,1],
]
kornia_resizing_demo = gr.Interface(
rescale_aa,
[
gr.inputs.Image(type="file"),
gr.inputs.Slider(minimum=0.005, maximum=2, step=0.005, default=1, label="Height"),
gr.inputs.Slider(minimum=0.005, maximum=2, step=0.005, default=1, label="Width")
],
"image",
examples=examples,
live=False,
enable_queue = True,
allow_flagging = "never"
)
kornia_resizing_demo.launch()