Spaces:
No application file
No application file
| import gradio as gr | |
| from PIL import Image, ImageEnhance | |
| import numpy as np | |
| import cv2 | |
| # Functions for Enhancements | |
| def enhance_image(img, brightness, contrast, sharpness, saturation): | |
| # Brightness | |
| enhancer = ImageEnhance.Brightness(img) | |
| img = enhancer.enhance(brightness) | |
| # Contrast | |
| enhancer = ImageEnhance.Contrast(img) | |
| img = enhancer.enhance(contrast) | |
| # Sharpness | |
| enhancer = ImageEnhance.Sharpness(img) | |
| img = enhancer.enhance(sharpness) | |
| # Saturation | |
| img_cv = cv2.cvtColor(np.array(img), cv2.COLOR_RGB2HSV) | |
| img_cv[:, :, 1] = np.clip(img_cv[:, :, 1] * saturation, 0, 255) | |
| img = Image.fromarray(cv2.cvtColor(img_cv, cv2.COLOR_HSV2RGB)) | |
| return img | |
| # Gradio Interface | |
| def process_image(image, brightness, contrast, sharpness, saturation): | |
| return enhance_image(image, brightness, contrast, sharpness, saturation) | |
| # Gradio Inputs and Outputs | |
| inputs = [ | |
| gr.Image(type="pil", label="Upload an Image"), | |
| gr.Slider(0.5, 3.0, 1.0, label="Brightness"), | |
| gr.Slider(0.5, 3.0, 1.0, label="Contrast"), | |
| gr.Slider(0.5, 3.0, 1.0, label="Sharpness"), | |
| gr.Slider(0.5, 3.0, 1.0, label="Saturation"), | |
| ] | |
| outputs = gr.Image(type="pil", label="Enhanced Image") | |
| # Launch Gradio App | |
| title = "Image Enhancer App" | |
| description = """ | |
| Enhance your images with basic filters like brightness, contrast, sharpness, and saturation. | |
| Upload an image, adjust the sliders, and see the enhanced version! | |
| """ | |
| demo = gr.Interface( | |
| fn=process_image, | |
| inputs=inputs, | |
| outputs=outputs, | |
| title=title, | |
| description=description, | |
| allow_flagging="never" | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() | |