Spaces:
Sleeping
Sleeping
import gradio as gr | |
from equalize import Equalize | |
def set_levels(image): | |
if image is None: | |
return 0, 0, 0 | |
eq = Equalize(0, 0, 0) | |
eq.set_level(image) | |
return round(eq.level[Equalize.R], 2), round(eq.level[Equalize.G], 2), round(eq.level[Equalize.B], 2) | |
def equalize(image, level_r, level_g, level_b): | |
eq = Equalize(level_r, level_g, level_b) | |
dest = eq.filter(image) | |
return dest | |
with gr.Blocks(title='image color equalizer') as app: | |
gr.Markdown('# Image Color Equalizer') | |
with gr.Row(): | |
with gr.Column(): | |
image = gr.Image(type='pil') | |
level_r = gr.Slider(maximum=1.0, value=0.0, step=0.01, label='R level') | |
level_g = gr.Slider(maximum=1.0, value=0.0, step=0.01, label='G level') | |
level_b = gr.Slider(maximum=1.0, value=0.0, step=0.01, label='B level') | |
inputs = [image, level_r, level_g, level_b] | |
clear = gr.ClearButton([image, level_r, level_g, level_b]) | |
btn = gr.Button(value='Submit') | |
with gr.Column(): | |
outputs = [gr.Image(label='output', type='pil')] | |
clear.add(inputs + outputs) | |
btn.click(equalize, inputs=inputs, outputs=outputs, concurrency_limit=20) | |
image.change(set_levels, inputs=[image], outputs=[level_r, level_g, level_b], concurrency_limit=20) | |
gr.Examples( | |
[['examples/example1.jpg'], ['examples/example2.jpg']], | |
[image], | |
#cache_examples=True | |
) | |
app.launch() | |