Spaces:
Runtime error
Runtime error
lappemic
commited on
Commit
·
530752c
1
Parent(s):
01dfff4
update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,4 @@
|
|
1 |
-
#
|
2 |
-
# as first try
|
3 |
|
4 |
import gradio as gr
|
5 |
|
@@ -7,17 +6,17 @@ import kornia as K
|
|
7 |
from kornia.core import Tensor
|
8 |
|
9 |
|
10 |
-
def
|
11 |
# load the image using the rust backend
|
12 |
img: Tensor = K.io.load_image(file.name, K.io.ImageLoadType.RGB32)
|
13 |
img = img[None] # 1xCxHxW / fp32 / [0, 1]
|
14 |
|
15 |
# apply tensor image enhancement
|
16 |
-
x_out: Tensor = K.
|
17 |
-
x_out = K.
|
18 |
-
x_out = K.
|
19 |
-
x_out = K.
|
20 |
-
x_out = K.
|
21 |
|
22 |
return K.utils.tensor_to_image(x_out)
|
23 |
|
@@ -27,19 +26,19 @@ examples = [
|
|
27 |
["examples/kitty.jpg", 0, 1, 1, 1, 0],
|
28 |
]
|
29 |
|
30 |
-
title = "Kornia Image
|
31 |
-
description = "<p style='text-align: center'>This is a Gradio demo for Kornia's Image
|
32 |
article = "<p style='text-align: center'><a href='https://kornia.readthedocs.io/en/latest/' target='_blank'>Kornia Docs</a> | <a href='https://github.com/kornia/kornia' target='_blank'>Kornia Github Repo</a> | <a href='https://kornia-tutorials.readthedocs.io/en/latest/image_enhancement.html' target='_blank'>Kornia Enhancements Tutorial</a></p>"
|
33 |
|
34 |
iface = gr.Interface(
|
35 |
enhance,
|
36 |
[
|
37 |
gr.inputs.Image(type="file"),
|
38 |
-
gr.inputs.Slider(minimum=0, maximum=1, step=0.1, default=0, label="
|
39 |
-
gr.inputs.Slider(minimum=0, maximum=4, step=0.1, default=1, label="
|
40 |
-
gr.inputs.Slider(minimum=0, maximum=4, step=0.1, default=1, label="
|
41 |
-
gr.inputs.Slider(minimum=0, maximum=1, step=0.1, default=1, label="
|
42 |
-
gr.inputs.Slider(minimum=0, maximum=4, step=0.1, default=0, label="
|
43 |
],
|
44 |
"image",
|
45 |
examples=examples,
|
|
|
1 |
+
# created with great guidance from https://github.com/NimaBoscarino
|
|
|
2 |
|
3 |
import gradio as gr
|
4 |
|
|
|
6 |
from kornia.core import Tensor
|
7 |
|
8 |
|
9 |
+
def filters(file, box_blur, blur_pool2d, gaussian_blur2d, max_blur_pool2d, median_blur):
|
10 |
# load the image using the rust backend
|
11 |
img: Tensor = K.io.load_image(file.name, K.io.ImageLoadType.RGB32)
|
12 |
img = img[None] # 1xCxHxW / fp32 / [0, 1]
|
13 |
|
14 |
# apply tensor image enhancement
|
15 |
+
x_out: Tensor = K.filters.box_blur(img, float(box_blur))
|
16 |
+
x_out = K.filters.blur_pool2d(x_out, float(blur_pool2d))
|
17 |
+
x_out = K.filters.gaussian_blur2d(x_out, float(gaussian_blur2d))
|
18 |
+
x_out = K.filters.max_blur_pool2d(x_out, float(max_blur_pool2d))
|
19 |
+
x_out = K.filters.median_blur(x_out, float(median_blur))
|
20 |
|
21 |
return K.utils.tensor_to_image(x_out)
|
22 |
|
|
|
26 |
["examples/kitty.jpg", 0, 1, 1, 1, 0],
|
27 |
]
|
28 |
|
29 |
+
title = "Kornia Image Filters"
|
30 |
+
description = "<p style='text-align: center'>This is a Gradio demo for Kornia's Image Filters.</p><p style='text-align: center'>To use it, simply upload your image, or click one of the examples to load them, and use the sliders to enhance! Read more at the links at the bottom.</p>"
|
31 |
article = "<p style='text-align: center'><a href='https://kornia.readthedocs.io/en/latest/' target='_blank'>Kornia Docs</a> | <a href='https://github.com/kornia/kornia' target='_blank'>Kornia Github Repo</a> | <a href='https://kornia-tutorials.readthedocs.io/en/latest/image_enhancement.html' target='_blank'>Kornia Enhancements Tutorial</a></p>"
|
32 |
|
33 |
iface = gr.Interface(
|
34 |
enhance,
|
35 |
[
|
36 |
gr.inputs.Image(type="file"),
|
37 |
+
gr.inputs.Slider(minimum=0, maximum=1, step=0.1, default=0, label="Box Blur"),
|
38 |
+
gr.inputs.Slider(minimum=0, maximum=4, step=0.1, default=1, label="Blur Pool"),
|
39 |
+
gr.inputs.Slider(minimum=0, maximum=4, step=0.1, default=1, label="Gaussian Blur"),
|
40 |
+
gr.inputs.Slider(minimum=0, maximum=1, step=0.1, default=1, label="Max Pool"),
|
41 |
+
gr.inputs.Slider(minimum=0, maximum=4, step=0.1, default=0, label="Median Blur"),
|
42 |
],
|
43 |
"image",
|
44 |
examples=examples,
|