Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,40 +3,51 @@ 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="
|
7 |
|
8 |
-
st.title("πΌοΈ
|
9 |
-
st.write("Upload a PNG or JPG image under 5MB to apply filters.")
|
10 |
-
st.caption("π¦ Only PNG or JPG under 5MB allowed.")
|
11 |
|
|
|
|
|
12 |
|
13 |
-
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
if uploaded_file:
|
17 |
-
#
|
18 |
uploaded_file.seek(0, io.SEEK_END)
|
19 |
file_size = uploaded_file.tell()
|
20 |
-
uploaded_file.seek(0)
|
21 |
|
22 |
if file_size > 5 * 1024 * 1024:
|
23 |
-
|
|
|
24 |
else:
|
25 |
image = Image.open(uploaded_file)
|
26 |
-
st.image(image, caption="Original Image", use_container_width=True)
|
27 |
|
28 |
-
|
29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
|
31 |
-
|
32 |
-
|
33 |
-
|
|
|
|
|
34 |
|
35 |
-
|
36 |
-
|
37 |
-
image = image.convert("RGB")
|
38 |
-
filtered_image = ImageOps.invert(image)
|
39 |
-
st.image(filtered_image, caption="Inverted Image", use_container_width=True)
|
40 |
|
41 |
-
elif filter_option == "None":
|
42 |
-
st.info("Select a filter to apply to the image.")
|
|
|
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
|
12 |
|
13 |
+
with col1:
|
14 |
+
st.header("π€ Upload Image")
|
15 |
+
st.caption("Max 5MB β’ Only PNG, JPG")
|
16 |
+
uploaded_file = st.file_uploader("Choose an image", type=["png", "jpg", "jpeg"])
|
17 |
+
|
18 |
+
image = None
|
19 |
+
filtered_image = None
|
20 |
+
filter_option = "None"
|
21 |
|
22 |
if uploaded_file:
|
23 |
+
# Size check
|
24 |
uploaded_file.seek(0, io.SEEK_END)
|
25 |
file_size = uploaded_file.tell()
|
26 |
+
uploaded_file.seek(0)
|
27 |
|
28 |
if file_size > 5 * 1024 * 1024:
|
29 |
+
with col1:
|
30 |
+
st.error("β File too large! Must be under 5MB.")
|
31 |
else:
|
32 |
image = Image.open(uploaded_file)
|
|
|
33 |
|
34 |
+
with col2:
|
35 |
+
st.header("ποΈ Select Filter")
|
36 |
+
filter_option = st.radio("Choose filter:", ["None", "Grayscale", "Invert Colors"])
|
37 |
+
|
38 |
+
with col3:
|
39 |
+
st.header("π Preview Output")
|
40 |
+
|
41 |
+
if filter_option == "Grayscale":
|
42 |
+
filtered_image = ImageOps.grayscale(image)
|
43 |
+
st.image(filtered_image, caption="Grayscale", use_container_width=True)
|
44 |
|
45 |
+
elif filter_option == "Invert Colors":
|
46 |
+
if image.mode != "RGB":
|
47 |
+
image = image.convert("RGB")
|
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 |
|
|
|
|