gdo commited on
Commit
0abd7e4
·
verified ·
1 Parent(s): ac46d02

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -0
app.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ !pip install gradio opencv-python numpy
2
+ import gradio as gr
3
+ import cv2
4
+ import numpy as np
5
+
6
+ # Function to apply filters
7
+ def process_image(image, filter_type):
8
+ image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR) # Convert to OpenCV format
9
+
10
+ if filter_type == "Grayscale":
11
+ processed = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
12
+ elif filter_type == "Blur":
13
+ processed = cv2.GaussianBlur(image, (15, 15), 0)
14
+ elif filter_type == "Edge Detection":
15
+ processed = cv2.Canny(image, 100, 200)
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()