Spaces:
Runtime error
Runtime error
File size: 1,327 Bytes
489b1ee |
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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
import gradio as gr
import cv2
import numpy as np
# Function to apply grayscale filter
def grayscale(image):
return cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# Function to apply blur filter
def blur(image):
return cv2.GaussianBlur(image, (15, 15), 0)
# Function to apply edge detection
def edge_detection(image):
return cv2.Canny(image, 100, 200)
# Function to load and process the image
def process_image(image, filter_type):
if filter_type == "Grayscale":
return grayscale(image)
elif filter_type == "Blur":
return blur(image)
elif filter_type == "Edge Detection":
return edge_detection(image)
# Create the Gradio interface
def create_interface():
filters = ["Grayscale", "Blur", "Edge Detection"]
# Create a Gradio Interface
interface = gr.Interface(
fn=process_image,
inputs=[
gr.Image(type="numpy", label="Upload Image"),
gr.Dropdown(filters, label="Select Filter")
],
outputs=gr.Image(type="numpy", label="Processed Image"),
live=True,
title="Simple Photo Editor",
description="Upload an image and apply filters like Grayscale, Blur, or Edge Detection."
)
return interface
# Launch the app
if __name__ == "__main__":
app = create_interface()
app.launch()
|