aika42's picture
Update app.py
aa90ae8 verified
raw
history blame
1.58 kB
# app.py
import streamlit as st
from PIL import Image, ImageOps
import io
st.set_page_config(page_title="Image Filter App", layout="wide")
st.title("πŸ–ΌοΈ Image Filter App")
# 3-column layout
col1, col2, col3 = st.columns([1, 1, 1]) # equal width
with col1:
st.header("πŸ“€ Upload Image")
st.caption("Max 5MB β€’ Only PNG, JPG")
uploaded_file = st.file_uploader("Choose an image", type=["png", "jpg", "jpeg"])
image = None
filtered_image = None
filter_option = "None"
if uploaded_file:
# Size check
uploaded_file.seek(0, io.SEEK_END)
file_size = uploaded_file.tell()
uploaded_file.seek(0)
if file_size > 5 * 1024 * 1024:
with col1:
st.error("❌ File too large! Must be under 5MB.")
else:
image = Image.open(uploaded_file)
with col2:
st.header("πŸŽ›οΈ Select Filter")
filter_option = st.radio("Choose filter:", ["None", "Grayscale", "Invert Colors"])
with col3:
st.header("πŸ” Preview Output")
if filter_option == "Grayscale":
filtered_image = ImageOps.grayscale(image)
st.image(filtered_image, caption="Grayscale", use_container_width=True)
elif filter_option == "Invert Colors":
if image.mode != "RGB":
image = image.convert("RGB")
filtered_image = ImageOps.invert(image)
st.image(filtered_image, caption="Inverted", use_container_width=True)
else:
st.info("Select a filter to see output.")