File size: 1,743 Bytes
5825d5b
 
 
 
 
 
 
 
2a39662
5825d5b
 
 
 
e3c3f88
2a39662
5825d5b
 
2a39662
3caf593
 
 
 
 
 
2a39662
3caf593
 
5825d5b
 
cfa42c2
 
5825d5b
 
2a39662
 
5825d5b
 
 
e3c3f88
 
 
 
2a39662
e3c3f88
 
 
 
2a39662
 
e3c3f88
 
5825d5b
 
 
 
 
2a39662
5825d5b
 
 
 
e3c3f88
 
2a39662
 
e3c3f88
 
2a39662
 
e3c3f88
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# 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()