lappemic
try tab approach
2a39662
raw
history blame
1.74 kB
# created with great guidance from https://github.com/NimaBoscarino
import gradio as gr
import kornia as K
from kornia.core import Tensor
def box_blur_fn(file, box_blur):
# load the image using the rust backend
img: Tensor = K.io.load_image(file.name, K.io.ImageLoadType.RGB32)
img = img[None] # 1xCxHxW / fp32 / [0, 1]
x_out: Tensor = K.filters.box_blur(img, (int(box_blur), int(box_blur)))
return K.utils.tensor_to_image(x_out)
def blur_pool2d_fn(file, blur_pool2d):
# load the image using the rust backend
img: Tensor = K.io.load_image(file.name, K.io.ImageLoadType.RGB32)
img = img[None] # 1xCxHxW / fp32 / [0, 1]
# apply tensor image enhancement
x_out: Tensor = K.filters.blur_pool2d(x_out, int(blur_pool2d))
return K.utils.tensor_to_image(x_out)
examples = [
["examples/monkey.jpg", 1, 1, 1, 1, 1],
["examples/pikachu.jpg", 1, 1, 1, 1, 1],
]
box_blur_fn_demo = gr.Interface(
box_blur_fn,
[
gr.inputs.Image(type="file"),
gr.inputs.Slider(minimum=1, maximum=10, step=1, default=1, label="Box Blur"),
],
"image",
examples=examples,
# title=title,
# description=description,
# article=article,
live=True
)
blur_pool2d_fn_demo = gr.Interface(
blur_pool2d_fn,
[
gr.inputs.Image(type="file"),
gr.inputs.Slider(minimum=1, maximum=10, step=1, default=1, label="Blur Pool"),
],
"image",
examples=examples,
# title=title,
# description=description,
# article=article,
live=True
)
demo = gr.TabbedInterface(
[
box_blur_fn_demo,
blur_pool2d_fn_demo
],
[
"Box Blur",
"Blur Pool"
]
)
demo.launch()