Spaces:
Runtime error
Runtime error
lappemic
commited on
Commit
•
f38b5cf
1
Parent(s):
df804e9
readme and app.py
Browse files
README.md
CHANGED
@@ -7,6 +7,7 @@ sdk: gradio
|
|
7 |
sdk_version: 3.3
|
8 |
app_file: app.py
|
9 |
pinned: false
|
|
|
10 |
---
|
11 |
|
12 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
7 |
sdk_version: 3.3
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
+
license: apache-2.0
|
11 |
---
|
12 |
|
13 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# taken from https://huggingface.co/spaces/kornia/kornia-image-enhancement/blob/main/app.py created from https://github.com/NimaBoscarino
|
2 |
+
# as first try
|
3 |
+
|
4 |
+
import gradio as gr
|
5 |
+
|
6 |
+
import kornia as K
|
7 |
+
from kornia.core import Tensor
|
8 |
+
|
9 |
+
|
10 |
+
def enhance(file, brightness, contrast, saturation, gamma, hue):
|
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.enhance.adjust_brightness(img, float(brightness))
|
17 |
+
x_out = K.enhance.adjust_contrast(x_out, float(contrast))
|
18 |
+
x_out = K.enhance.adjust_saturation(x_out, float(saturation))
|
19 |
+
x_out = K.enhance.adjust_gamma(x_out, float(gamma))
|
20 |
+
x_out = K.enhance.adjust_hue(x_out, float(hue))
|
21 |
+
|
22 |
+
return K.utils.tensor_to_image(x_out)
|
23 |
+
|
24 |
+
|
25 |
+
examples = [
|
26 |
+
["examples/ninja_turtles.jpg", 0, 1, 1, 1, 0],
|
27 |
+
["examples/kitty.jpg", 0, 1, 1, 1, 0],
|
28 |
+
]
|
29 |
+
|
30 |
+
title = "Kornia Image Enhancements"
|
31 |
+
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>"
|
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="Brightness"),
|
39 |
+
gr.inputs.Slider(minimum=0, maximum=4, step=0.1, default=1, label="Contrast"),
|
40 |
+
gr.inputs.Slider(minimum=0, maximum=4, step=0.1, default=1, label="Saturation"),
|
41 |
+
gr.inputs.Slider(minimum=0, maximum=1, step=0.1, default=1, label="Gamma"),
|
42 |
+
gr.inputs.Slider(minimum=0, maximum=4, step=0.1, default=0, label="Hue"),
|
43 |
+
],
|
44 |
+
"image",
|
45 |
+
examples=examples,
|
46 |
+
# title=title,
|
47 |
+
# description=description,
|
48 |
+
# article=article,
|
49 |
+
live=True
|
50 |
+
)
|
51 |
+
|
52 |
+
iface.launch()
|