Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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="centered")
|
| 7 |
+
|
| 8 |
+
st.title("🖼️ Simple Image Filter App")
|
| 9 |
+
st.write("Upload a PNG or JPG image under 5MB to apply filters.")
|
| 10 |
+
|
| 11 |
+
# File uploader with type restriction
|
| 12 |
+
uploaded_file = st.file_uploader("Upload Image", type=["png", "jpg", "jpeg"])
|
| 13 |
+
|
| 14 |
+
if uploaded_file:
|
| 15 |
+
# Check file size
|
| 16 |
+
uploaded_file.seek(0, io.SEEK_END)
|
| 17 |
+
file_size = uploaded_file.tell()
|
| 18 |
+
uploaded_file.seek(0) # Reset pointer
|
| 19 |
+
|
| 20 |
+
if file_size > 5 * 1024 * 1024:
|
| 21 |
+
st.error("❌ File size exceeds 5MB. Please upload a smaller image.")
|
| 22 |
+
else:
|
| 23 |
+
image = Image.open(uploaded_file)
|
| 24 |
+
st.image(image, caption="Original Image", use_column_width=True)
|
| 25 |
+
|
| 26 |
+
st.subheader("Choose a Filter")
|
| 27 |
+
filter_option = st.radio("Select filter:", ["None", "Grayscale", "Invert Colors"])
|
| 28 |
+
|
| 29 |
+
if filter_option == "Grayscale":
|
| 30 |
+
filtered_image = ImageOps.grayscale(image)
|
| 31 |
+
st.image(filtered_image, caption="Grayscale Image", use_column_width=True)
|
| 32 |
+
|
| 33 |
+
elif filter_option == "Invert Colors":
|
| 34 |
+
if image.mode != "RGB":
|
| 35 |
+
image = image.convert("RGB")
|
| 36 |
+
filtered_image = ImageOps.invert(image)
|
| 37 |
+
st.image(filtered_image, caption="Inverted Image", use_column_width=True)
|
| 38 |
+
|
| 39 |
+
elif filter_option == "None":
|
| 40 |
+
st.info("Select a filter to apply to the image.")
|
| 41 |
+
|