lappemic commited on
Commit
e3c3f88
1 Parent(s): c06cbee

Change to tab app

Browse files
Files changed (1) hide show
  1. app.py +33 -9
app.py CHANGED
@@ -6,14 +6,14 @@ import kornia as K
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, (int(box_blur), int(box_blur)))
16
  x_out = K.filters.blur_pool2d(x_out, int(blur_pool2d))
 
17
  x_out = K.filters.gaussian_blur2d(x_out,
18
  (int(gaussian_blur2d), int(gaussian_blur2d)),
19
  (float(gaussian_blur2d), float(gaussian_blur2d)))
@@ -28,16 +28,29 @@ examples = [
28
  ["examples/pikachu.jpg", 1, 1, 1, 1, 1],
29
  ]
30
 
31
- title = "Kornia Image Filters"
32
- 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>"
33
- 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>"
34
-
35
- iface = gr.Interface(
36
  filters,
37
  [
38
  gr.inputs.Image(type="file"),
39
  gr.inputs.Slider(minimum=1, maximum=10, step=1, default=1, label="Box Blur"),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
  gr.inputs.Slider(minimum=1, maximum=10, step=1, default=1, label="Blur Pool"),
 
41
  gr.inputs.Slider(minimum=1, maximum=21, step=2, default=1, label="Gaussian Blur"),
42
  gr.inputs.Slider(minimum=1, maximum=20, step=1, default=1, label="Max Pool"),
43
  gr.inputs.Slider(minimum=1, maximum=5, step=2, default=1, label="Median Blur"),
@@ -45,9 +58,20 @@ iface = gr.Interface(
45
  "image",
46
  examples=examples,
47
  # title=title,
48
- # description=description,
49
  # article=article,
50
  live=True
51
  )
52
 
53
- iface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
6
  from kornia.core import Tensor
7
 
8
 
9
+ def filters(file, blur_pool2d, box_blur, 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 = K.filters.blur_pool2d(x_out, int(blur_pool2d))
16
+ x_out: Tensor = K.filters.box_blur(img, (int(box_blur), int(box_blur)))
17
  x_out = K.filters.gaussian_blur2d(x_out,
18
  (int(gaussian_blur2d), int(gaussian_blur2d)),
19
  (float(gaussian_blur2d), float(gaussian_blur2d)))
 
28
  ["examples/pikachu.jpg", 1, 1, 1, 1, 1],
29
  ]
30
 
31
+ without_downsampling_demo = gr.Interface(
 
 
 
 
32
  filters,
33
  [
34
  gr.inputs.Image(type="file"),
35
  gr.inputs.Slider(minimum=1, maximum=10, step=1, default=1, label="Box Blur"),
36
+ gr.inputs.Slider(minimum=1, maximum=21, step=2, default=1, label="Gaussian Blur"),
37
+ gr.inputs.Slider(minimum=1, maximum=20, step=1, default=1, label="Max Pool"),
38
+ gr.inputs.Slider(minimum=1, maximum=5, step=2, default=1, label="Median Blur"),
39
+ ],
40
+ "image",
41
+ examples=examples,
42
+ # title=title,
43
+ description= 'If you want to use the filters with downsampled image, use tab "With image downsampling"',
44
+ # article=article,
45
+ live=True
46
+ )
47
+
48
+ with_downsampling_demo = gr.Interface(
49
+ filters,
50
+ [
51
+ gr.inputs.Image(type="file"),
52
  gr.inputs.Slider(minimum=1, maximum=10, step=1, default=1, label="Blur Pool"),
53
+ gr.inputs.Slider(minimum=1, maximum=10, step=1, default=1, label="Box Blur"),
54
  gr.inputs.Slider(minimum=1, maximum=21, step=2, default=1, label="Gaussian Blur"),
55
  gr.inputs.Slider(minimum=1, maximum=20, step=1, default=1, label="Max Pool"),
56
  gr.inputs.Slider(minimum=1, maximum=5, step=2, default=1, label="Median Blur"),
 
58
  "image",
59
  examples=examples,
60
  # title=title,
61
+ description = 'Blur Pooling downsamples the image in the default setting!',
62
  # article=article,
63
  live=True
64
  )
65
 
66
+ demo = gr.TabbedInterface(
67
+ [
68
+ without_downsampling_demo,
69
+ with_downsampling_demo
70
+ ],
71
+ [
72
+ "Without image downsampling",
73
+ "With image downsampling"
74
+ ]
75
+ )
76
+
77
+ demo.launch()