Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import cv2
|
| 3 |
+
import numpy as np
|
| 4 |
+
|
| 5 |
+
# Function to apply filters
|
| 6 |
+
def process_image(image, filter_type):
|
| 7 |
+
image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR) # Convert to OpenCV format
|
| 8 |
+
|
| 9 |
+
if filter_type == "Grayscale":
|
| 10 |
+
processed = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
| 11 |
+
elif filter_type == "Blur":
|
| 12 |
+
processed = cv2.GaussianBlur(image, (15, 15), 0)
|
| 13 |
+
elif filter_type == "Edge Detection":
|
| 14 |
+
edges = cv2.Canny(image, 100, 200) # Detect edges
|
| 15 |
+
processed = cv2.bitwise_not(edges) # Invert to make edges black on white background
|
| 16 |
+
else:
|
| 17 |
+
processed = image # No filter
|
| 18 |
+
|
| 19 |
+
return processed
|
| 20 |
+
|
| 21 |
+
# Gradio Interface
|
| 22 |
+
demo = gr.Interface(
|
| 23 |
+
fn=process_image,
|
| 24 |
+
inputs=[
|
| 25 |
+
gr.Image(type="numpy"), # Upload Image
|
| 26 |
+
gr.Radio(["Grayscale", "Blur", "Edge Detection"], label="Choose Filter")
|
| 27 |
+
],
|
| 28 |
+
outputs="image",
|
| 29 |
+
title="🖼️ Image Filters & Processing",
|
| 30 |
+
description="Upload an image and apply filters like Grayscale, Blur, or Edge Detection."
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
# Launch the app
|
| 34 |
+
demo.launch()
|