|
|
import gradio as gr |
|
|
import cv2 |
|
|
import numpy as np |
|
|
|
|
|
|
|
|
def process_image(image, filter_type): |
|
|
image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR) |
|
|
|
|
|
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": |
|
|
edges = cv2.Canny(image, 100, 200) |
|
|
processed = cv2.bitwise_not(edges) |
|
|
else: |
|
|
processed = image |
|
|
|
|
|
return processed |
|
|
|
|
|
|
|
|
demo = gr.Interface( |
|
|
fn=process_image, |
|
|
inputs=[ |
|
|
gr.Image(type="numpy"), |
|
|
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." |
|
|
) |
|
|
|
|
|
|
|
|
demo.launch() |
|
|
|