import gradio as gr import kornia as K from kornia.core import Tensor def enhance(file, brightness, contrast, saturation, gamma, hue): # load the image using the rust backend img: Tensor = K.io.load_image(file.name, K.io.ImageLoadType.RGB32) img = img[None] / 255. # apply tensor image enhancement x_out: Tensor = K.enhance.adjust_brightness(img, float(brightness)) x_out = K.enhance.adjust_contrast(x_out, float(contrast)) x_out = K.enhance.adjust_saturation(x_out, float(saturation)) x_out = K.enhance.adjust_gamma(x_out, float(gamma)) x_out = K.enhance.adjust_hue(x_out, float(hue)) return K.utils.tensor_to_image(x_out) examples = [ ["examples/ninja_turtles.jpg", 0, 1, 1, 1, 0], ["examples/kitty.jpg", 0, 1, 1, 1, 0], ] title = "Kornia Image Enhancements" description = "
This is a Gradio demo for Kornia's Image Enhancements.
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.
" article = "Kornia Docs | Kornia Github Repo | Kornia Enhancements Tutorial
" iface = gr.Interface( enhance, [ gr.inputs.Image(type="file"), gr.inputs.Slider(minimum=0, maximum=1, step=0.1, default=0, label="Brightness"), gr.inputs.Slider(minimum=0, maximum=4, step=0.1, default=1, label="Contrast"), gr.inputs.Slider(minimum=0, maximum=4, step=0.1, default=1, label="Saturation"), gr.inputs.Slider(minimum=0, maximum=1, step=0.1, default=1, label="Gamma"), gr.inputs.Slider(minimum=0, maximum=4, step=0.1, default=0, label="Hue"), ], "image", examples=examples, # title=title, # description=description, # article=article, live=True ) iface.launch()