import gradio as gr from PIL import Image, ImageEnhance def enhance_image(image, vibrancy=1.0, sharpness=1.0, yellow_reduce=0.0, magenta_reduce=0.0, brightness=0.0): # Convert to RGB image = image.convert("RGB") # Yellow reduction matrix (targets red/green channels) yellow_matrix = ( 1.0 - yellow_reduce*0.4, 0, 0, 0, 0, 1.0 - yellow_reduce*0.6, 0, 0, 0, 0, 1.0 + yellow_reduce*0.2, 0 # Compensate with slight blue ) image = image.convert("RGB", yellow_matrix) # Magenta reduction matrix (targets red/blue channels) magenta_matrix = ( 1.0 - magenta_reduce*0.3, 0, 0, 0, 0, 1.0 + magenta_reduce*0.4, 0, 0, 0, 0, 1.0 - magenta_reduce*0.3, 0 ) image = image.convert("RGB", magenta_matrix) # Apply brightness boost if brightness > 0: image = ImageEnhance.Brightness(image).enhance(1.0 + brightness) # Apply vibrancy enhancements image = ImageEnhance.Color(image).enhance(vibrancy) image = ImageEnhance.Contrast(image).enhance(1.0 + (vibrancy-1)*0.15) # Apply sharpness last image = ImageEnhance.Sharpness(image).enhance(sharpness) return image iface = gr.Interface( fn=enhance_image, inputs=[ gr.Image(type="pil", label="Original Image"), gr.Slider(0.5, 2.0, 1.0, step=0.1, label="Vibrancy"), gr.Slider(0.5, 3.0, 1.0, step=0.1, label="Sharpness"), gr.Slider(0.0, 0.5, 0.0, step=0.05, label="Yellow Reduction"), gr.Slider(0.0, 0.5, 0.0, step=0.05, label="Magenta Reduction"), gr.Slider(0.0, 0.5, 0.0, step=0.05, label="Brightness Boost") ], outputs=gr.Image(type="pil", label="Enhanced Image", format="jpeg"), title="Professional Image Corrector", description="Independent controls for yellow/magenta reduction with brightness preservation" ) if __name__ == "__main__": iface.launch()