HErsoy commited on
Commit
935312a
·
verified ·
1 Parent(s): 9454b09

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +58 -0
app.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import numpy as np
3
+ from PIL import Image, ImageEnhance, ImageFilter
4
+
5
+ def apply_filter(image, filter_type):
6
+ if image is None:
7
+ return None
8
+
9
+ img = Image.fromarray(image.astype('uint8'), 'RGB')
10
+
11
+ if filter_type == "Sepia":
12
+ sepia_filter = np.array([
13
+ [0.393, 0.769, 0.189],
14
+ [0.349, 0.686, 0.168],
15
+ [0.272, 0.534, 0.131]
16
+ ])
17
+ sepia_img = image.dot(sepia_filter.T)
18
+ sepia_img /= sepia_img.max()
19
+ return sepia_img
20
+
21
+ elif filter_type == "Black and White":
22
+ return np.array(img.convert('L'))
23
+
24
+ elif filter_type == "Blur":
25
+ return np.array(img.filter(ImageFilter.BLUR))
26
+
27
+ elif filter_type == "Sharpen":
28
+ return np.array(img.filter(ImageFilter.SHARPEN))
29
+
30
+ elif filter_type == "Emboss":
31
+ return np.array(img.filter(ImageFilter.EMBOSS))
32
+
33
+ elif filter_type == "Edge Enhance":
34
+ return np.array(img.filter(ImageFilter.EDGE_ENHANCE))
35
+
36
+ else: # Original
37
+ return image
38
+
39
+ # Define the Gradio interface
40
+ iface = gr.Interface(
41
+ fn=apply_filter,
42
+ inputs=[
43
+ gr.Image(label="Upload an image"),
44
+ gr.Radio(["Original", "Sepia", "Black and White", "Blur", "Sharpen", "Emboss", "Edge Enhance"],
45
+ label="Select a filter", value="Original")
46
+ ],
47
+ outputs=gr.Image(label="Filtered Image"),
48
+ title="Photo Filter Application",
49
+ description="Upload an image and apply different filters to it.",
50
+ examples=[
51
+ ["examples/example1.jpg", "Sepia"],
52
+ ["examples/example2.jpg", "Black and White"],
53
+ ["examples/example3.jpg", "Blur"]
54
+ ]
55
+ )
56
+
57
+ # Launch the interface
58
+ iface.launch()