File size: 994 Bytes
0abd7e4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
!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()