yunusajib commited on
Commit
489b1ee
·
verified ·
1 Parent(s): 38212cd
Files changed (1) hide show
  1. app1.py +48 -0
app1.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import cv2
3
+ import numpy as np
4
+
5
+ # Function to apply grayscale filter
6
+ def grayscale(image):
7
+ return cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
8
+
9
+ # Function to apply blur filter
10
+ def blur(image):
11
+ return cv2.GaussianBlur(image, (15, 15), 0)
12
+
13
+ # Function to apply edge detection
14
+ def edge_detection(image):
15
+ return cv2.Canny(image, 100, 200)
16
+
17
+ # Function to load and process the image
18
+ def process_image(image, filter_type):
19
+ if filter_type == "Grayscale":
20
+ return grayscale(image)
21
+ elif filter_type == "Blur":
22
+ return blur(image)
23
+ elif filter_type == "Edge Detection":
24
+ return edge_detection(image)
25
+
26
+ # Create the Gradio interface
27
+ def create_interface():
28
+ filters = ["Grayscale", "Blur", "Edge Detection"]
29
+
30
+ # Create a Gradio Interface
31
+ interface = gr.Interface(
32
+ fn=process_image,
33
+ inputs=[
34
+ gr.Image(type="numpy", label="Upload Image"),
35
+ gr.Dropdown(filters, label="Select Filter")
36
+ ],
37
+ outputs=gr.Image(type="numpy", label="Processed Image"),
38
+ live=True,
39
+ title="Simple Photo Editor",
40
+ description="Upload an image and apply filters like Grayscale, Blur, or Edge Detection."
41
+ )
42
+
43
+ return interface
44
+
45
+ # Launch the app
46
+ if __name__ == "__main__":
47
+ app = create_interface()
48
+ app.launch()