Spaces:
Runtime error
Runtime error
osanseviero
commited on
Commit
•
2fddd2e
1
Parent(s):
247253a
Update app.py
Browse files
app.py
CHANGED
@@ -1,37 +1,53 @@
|
|
1 |
import gradio as gr
|
2 |
|
3 |
-
import
|
4 |
-
|
5 |
-
from matplotlib import pyplot as plt
|
6 |
|
7 |
|
8 |
-
def blur(file):
|
9 |
-
img = cv.imread('opencv-logo-white.png')
|
10 |
-
avg_blur = cv.blur(img,(5,5))
|
11 |
-
gaus_blur = cv.GaussianBlur(img,(5,5),0)
|
12 |
-
med_blur = cv.medianBlur(img,5)
|
13 |
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
|
17 |
examples = [
|
18 |
-
["
|
|
|
19 |
]
|
20 |
|
21 |
-
title = "
|
|
|
|
|
22 |
|
23 |
iface = gr.Interface(
|
24 |
enhance,
|
25 |
[
|
26 |
-
gr.Image(type="file"),
|
|
|
|
|
|
|
|
|
|
|
27 |
],
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
examples=examples,
|
|
|
|
|
|
|
34 |
live=True
|
35 |
)
|
36 |
-
|
37 |
-
iface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
|
3 |
+
import kornia as K
|
4 |
+
from kornia.core import Tensor
|
|
|
5 |
|
6 |
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
+
def enhance(file, brightness, contrast, saturation, gamma, hue):
|
9 |
+
# load the image using the rust backend
|
10 |
+
img: Tensor = K.io.load_image(file.name, K.io.ImageLoadType.RGB32)
|
11 |
+
img = img[None] # 1xCxHxW / fp32 / [0, 1]
|
12 |
+
|
13 |
+
|
14 |
+
# apply tensor image enhancement
|
15 |
+
x_out: Tensor = K.enhance.adjust_brightness(img, float(brightness))
|
16 |
+
x_out = K.enhance.adjust_contrast(x_out, float(contrast))
|
17 |
+
x_out = K.enhance.adjust_saturation(x_out, float(saturation))
|
18 |
+
x_out = K.enhance.adjust_gamma(x_out, float(gamma))
|
19 |
+
x_out = K.enhance.adjust_hue(x_out, float(hue))
|
20 |
+
|
21 |
+
return K.utils.tensor_to_image(x_out)
|
22 |
|
23 |
|
24 |
examples = [
|
25 |
+
["examples/ninja_turtles.jpg", 0, 1, 1, 1, 0],
|
26 |
+
["examples/kitty.jpg", 0, 1, 1, 1, 0],
|
27 |
]
|
28 |
|
29 |
+
title = "Kornia Image Enhancements"
|
30 |
+
description = "<p style='text-align: center'>This is a Gradio demo for Kornia's Image Enhancements.</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="Brightness"),
|
38 |
+
gr.inputs.Slider(minimum=0, maximum=4, step=0.1, default=1, label="Contrast"),
|
39 |
+
gr.inputs.Slider(minimum=0, maximum=4, step=0.1, default=1, label="Saturation"),
|
40 |
+
gr.inputs.Slider(minimum=0, maximum=1, step=0.1, default=1, label="Gamma"),
|
41 |
+
gr.inputs.Slider(minimum=0, maximum=4, step=0.1, default=0, label="Hue"),
|
42 |
],
|
43 |
+
"image",
|
44 |
+
|
45 |
+
|
46 |
+
|
47 |
+
|
48 |
examples=examples,
|
49 |
+
# title=title,
|
50 |
+
# description=description,
|
51 |
+
# article=article,
|
52 |
live=True
|
53 |
)
|
|
|
|