Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
| # 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] | |
| x_out: Tensor = K.filters.blur_pool2d(img, int(blur_pool2d)) | |
| return K.utils.tensor_to_image(x_out) | |
| def gaussian_blur_fn(file, gaussian_blur2d): | |
| # 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.gaussian_blur2d(img, | |
| (int(gaussian_blur2d), int(gaussian_blur2d)), | |
| (float(gaussian_blur2d), float(gaussian_blur2d))) | |
| 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 | |
| ) | |
| gaussian_blur_fn_demo = gr.Interface( | |
| gaussian_blur_fn, | |
| [ | |
| gr.inputs.Image(type="file"), | |
| gr.inputs.Slider(minimum=1, maximum=21, step=2, default=1, label="Gaussian Blur") | |
| ], | |
| "image", | |
| examples=examples, | |
| # title=title, | |
| # description=description, | |
| # article=article, | |
| live=True | |
| ) | |
| demo = gr.TabbedInterface( | |
| [ | |
| box_blur_fn_demo, | |
| blur_pool2d_fn_demo, | |
| gaussian_blur_fn_demo | |
| ], | |
| [ | |
| "Box Blur", | |
| "Blur Pool" | |
| ] | |
| ) | |
| demo.launch() |