Spaces:
Runtime error
Runtime error
fix: update app.py to work with new gradio sdk
Browse files
app.py
CHANGED
@@ -1,23 +1,26 @@
|
|
1 |
import gradio as gr
|
2 |
-
|
3 |
import kornia as K
|
4 |
from kornia.core import Tensor
|
5 |
-
|
6 |
-
|
7 |
-
def enhance(
|
8 |
-
#
|
9 |
-
|
10 |
-
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
12 |
# apply tensor image enhancement
|
13 |
-
x_out: Tensor = K.enhance.adjust_brightness(img,
|
14 |
-
x_out = K.enhance.adjust_contrast(x_out,
|
15 |
-
x_out = K.enhance.adjust_saturation(x_out,
|
16 |
-
x_out = K.enhance.adjust_gamma(x_out,
|
17 |
-
x_out = K.enhance.adjust_hue(x_out,
|
18 |
-
|
19 |
-
return K.utils.tensor_to_image(x_out)
|
20 |
-
|
21 |
|
22 |
examples = [
|
23 |
["examples/ninja_turtles.jpg", 0, 1, 1, 1, 0],
|
@@ -31,18 +34,18 @@ article = "<p style='text-align: center'><a href='https://kornia.readthedocs.io/
|
|
31 |
iface = gr.Interface(
|
32 |
enhance,
|
33 |
[
|
34 |
-
gr.
|
35 |
-
gr.
|
36 |
-
gr.
|
37 |
-
gr.
|
38 |
-
gr.
|
39 |
-
gr.
|
40 |
],
|
41 |
"image",
|
42 |
examples=examples,
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
live=True
|
47 |
)
|
48 |
|
|
|
1 |
import gradio as gr
|
|
|
2 |
import kornia as K
|
3 |
from kornia.core import Tensor
|
4 |
+
import numpy as np
|
5 |
+
|
6 |
+
def enhance(image, brightness, contrast, saturation, gamma, hue):
|
7 |
+
# Convert numpy array to tensor
|
8 |
+
if isinstance(image, np.ndarray):
|
9 |
+
img = K.image_to_tensor(image).float() / 255.0
|
10 |
+
else:
|
11 |
+
# If it's a file path (for examples), load it using kornia
|
12 |
+
img = K.io.load_image(image, K.io.ImageLoadType.RGB32)
|
13 |
+
|
14 |
+
img = img.unsqueeze(0) # 1xCxHxW / fp32 / [0, 1]
|
15 |
+
|
16 |
# apply tensor image enhancement
|
17 |
+
x_out: Tensor = K.enhance.adjust_brightness(img, brightness)
|
18 |
+
x_out = K.enhance.adjust_contrast(x_out, contrast)
|
19 |
+
x_out = K.enhance.adjust_saturation(x_out, saturation)
|
20 |
+
x_out = K.enhance.adjust_gamma(x_out, gamma)
|
21 |
+
x_out = K.enhance.adjust_hue(x_out, hue)
|
22 |
+
|
23 |
+
return K.utils.tensor_to_image(x_out.squeeze())
|
|
|
24 |
|
25 |
examples = [
|
26 |
["examples/ninja_turtles.jpg", 0, 1, 1, 1, 0],
|
|
|
34 |
iface = gr.Interface(
|
35 |
enhance,
|
36 |
[
|
37 |
+
gr.Image(type="numpy"),
|
38 |
+
gr.Slider(minimum=0, maximum=1, step=0.1, value=0, label="Brightness"),
|
39 |
+
gr.Slider(minimum=0, maximum=4, step=0.1, value=1, label="Contrast"),
|
40 |
+
gr.Slider(minimum=0, maximum=4, step=0.1, value=1, label="Saturation"),
|
41 |
+
gr.Slider(minimum=0, maximum=1, step=0.1, value=1, label="Gamma"),
|
42 |
+
gr.Slider(minimum=-0.5, maximum=0.5, step=0.1, value=0, label="Hue"),
|
43 |
],
|
44 |
"image",
|
45 |
examples=examples,
|
46 |
+
title=title,
|
47 |
+
description=description,
|
48 |
+
article=article,
|
49 |
live=True
|
50 |
)
|
51 |
|