Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,11 +1,11 @@
|
|
1 |
# app.py
|
2 |
import streamlit as st
|
3 |
-
from PIL import Image, ImageOps
|
4 |
import io
|
5 |
|
6 |
st.set_page_config(page_title="Image Filter App", layout="wide")
|
7 |
|
8 |
-
st.title("🖼️ Image Filter App")
|
9 |
|
10 |
# 3-column layout
|
11 |
col1, col2, col3 = st.columns([1, 1, 1]) # equal width
|
@@ -33,7 +33,11 @@ if uploaded_file:
|
|
33 |
|
34 |
with col2:
|
35 |
st.header("🎛️ Select Filter")
|
36 |
-
filter_option = st.
|
|
|
|
|
|
|
|
|
37 |
|
38 |
with col3:
|
39 |
st.header("🔍 Preview Output")
|
@@ -48,6 +52,71 @@ if uploaded_file:
|
|
48 |
filtered_image = ImageOps.invert(image)
|
49 |
st.image(filtered_image, caption="Inverted", use_container_width=True)
|
50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
else:
|
52 |
st.info("Select a filter to see output.")
|
53 |
-
|
|
|
1 |
# app.py
|
2 |
import streamlit as st
|
3 |
+
from PIL import Image, ImageOps, ImageFilter, ImageEnhance
|
4 |
import io
|
5 |
|
6 |
st.set_page_config(page_title="Image Filter App", layout="wide")
|
7 |
|
8 |
+
st.title("🖼️ Fun Image Filter App")
|
9 |
|
10 |
# 3-column layout
|
11 |
col1, col2, col3 = st.columns([1, 1, 1]) # equal width
|
|
|
33 |
|
34 |
with col2:
|
35 |
st.header("🎛️ Select Filter")
|
36 |
+
filter_option = st.selectbox("Choose a filter:", [
|
37 |
+
"None", "Grayscale", "Invert Colors", "Sepia", "Blur", "Edge Detection",
|
38 |
+
"Posterize", "Emboss", "Solarize", "Brightness Boost", "Contrast Boost",
|
39 |
+
"Flip Horizontal", "Flip Vertical", "Rotate 90°"
|
40 |
+
])
|
41 |
|
42 |
with col3:
|
43 |
st.header("🔍 Preview Output")
|
|
|
52 |
filtered_image = ImageOps.invert(image)
|
53 |
st.image(filtered_image, caption="Inverted", use_container_width=True)
|
54 |
|
55 |
+
elif filter_option == "Sepia":
|
56 |
+
# Sepia filter
|
57 |
+
width, height = image.size
|
58 |
+
pixels = image.load() # create the pixel map
|
59 |
+
for py in range(height):
|
60 |
+
for px in range(width):
|
61 |
+
r, g, b = image.getpixel((px, py))
|
62 |
+
|
63 |
+
tr = int(0.393 * r + 0.769 * g + 0.189 * b)
|
64 |
+
tg = int(0.349 * r + 0.686 * g + 0.168 * b)
|
65 |
+
tb = int(0.272 * r + 0.534 * g + 0.131 * b)
|
66 |
+
|
67 |
+
# Apply filter
|
68 |
+
if tr > 255:
|
69 |
+
tr = 255
|
70 |
+
if tg > 255:
|
71 |
+
tg = 255
|
72 |
+
if tb > 255:
|
73 |
+
tb = 255
|
74 |
+
|
75 |
+
pixels[px, py] = (tr, tg, tb)
|
76 |
+
filtered_image = image
|
77 |
+
st.image(filtered_image, caption="Sepia", use_container_width=True)
|
78 |
+
|
79 |
+
elif filter_option == "Blur":
|
80 |
+
filtered_image = image.filter(ImageFilter.GaussianBlur(radius=5))
|
81 |
+
st.image(filtered_image, caption="Blurred", use_container_width=True)
|
82 |
+
|
83 |
+
elif filter_option == "Edge Detection":
|
84 |
+
filtered_image = image.filter(ImageFilter.FIND_EDGES)
|
85 |
+
st.image(filtered_image, caption="Edge Detection", use_container_width=True)
|
86 |
+
|
87 |
+
elif filter_option == "Posterize":
|
88 |
+
filtered_image = ImageOps.posterize(image, 4)
|
89 |
+
st.image(filtered_image, caption="Posterized", use_container_width=True)
|
90 |
+
|
91 |
+
elif filter_option == "Emboss":
|
92 |
+
filtered_image = image.filter(ImageFilter.EMBOSS)
|
93 |
+
st.image(filtered_image, caption="Emboss", use_container_width=True)
|
94 |
+
|
95 |
+
elif filter_option == "Solarize":
|
96 |
+
filtered_image = ImageOps.solarize(image, threshold=128)
|
97 |
+
st.image(filtered_image, caption="Solarized", use_container_width=True)
|
98 |
+
|
99 |
+
elif filter_option == "Brightness Boost":
|
100 |
+
enhancer = ImageEnhance.Brightness(image)
|
101 |
+
filtered_image = enhancer.enhance(2) # increase brightness
|
102 |
+
st.image(filtered_image, caption="Brightness Boosted", use_container_width=True)
|
103 |
+
|
104 |
+
elif filter_option == "Contrast Boost":
|
105 |
+
enhancer = ImageEnhance.Contrast(image)
|
106 |
+
filtered_image = enhancer.enhance(2) # increase contrast
|
107 |
+
st.image(filtered_image, caption="Contrast Boosted", use_container_width=True)
|
108 |
+
|
109 |
+
elif filter_option == "Flip Horizontal":
|
110 |
+
filtered_image = image.transpose(Image.FLIP_LEFT_RIGHT)
|
111 |
+
st.image(filtered_image, caption="Flipped Horizontal", use_container_width=True)
|
112 |
+
|
113 |
+
elif filter_option == "Flip Vertical":
|
114 |
+
filtered_image = image.transpose(Image.FLIP_TOP_BOTTOM)
|
115 |
+
st.image(filtered_image, caption="Flipped Vertical", use_container_width=True)
|
116 |
+
|
117 |
+
elif filter_option == "Rotate 90°":
|
118 |
+
filtered_image = image.rotate(90)
|
119 |
+
st.image(filtered_image, caption="Rotated 90°", use_container_width=True)
|
120 |
+
|
121 |
else:
|
122 |
st.info("Select a filter to see output.")
|
|