Spaces:
Runtime error
Runtime error
| !pip install gradio opencv-python numpy | |
| import gradio as gr | |
| import cv2 | |
| import numpy as np | |
| # Function to apply filters | |
| def process_image(image, filter_type): | |
| image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR) # Convert to OpenCV format | |
| if filter_type == "Grayscale": | |
| processed = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) | |
| elif filter_type == "Blur": | |
| processed = cv2.GaussianBlur(image, (15, 15), 0) | |
| elif filter_type == "Edge Detection": | |
| processed = cv2.Canny(image, 100, 200) | |
| else: | |
| processed = image # No filter | |
| return processed | |
| # Gradio Interface | |
| demo = gr.Interface( | |
| fn=process_image, | |
| inputs=[ | |
| gr.Image(type="numpy"), # Upload Image | |
| gr.Radio(["Grayscale", "Blur", "Edge Detection"], label="Choose Filter") | |
| ], | |
| outputs="image", | |
| title="🖼️ Image Filters & Processing", | |
| description="Upload an image and apply filters like Grayscale, Blur, or Edge Detection." | |
| ) | |
| # Launch the app | |
| demo.launch() | |