Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from PIL import Image, ImageEnhance
|
| 3 |
+
|
| 4 |
+
# Set up the Streamlit app
|
| 5 |
+
st.title("Simple Image Editor")
|
| 6 |
+
st.write("Upload an image, apply filters, and download your edited image.")
|
| 7 |
+
|
| 8 |
+
# Image upload
|
| 9 |
+
uploaded_file = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
|
| 10 |
+
|
| 11 |
+
if uploaded_file is not None:
|
| 12 |
+
# Open the uploaded image
|
| 13 |
+
image = Image.open(uploaded_file)
|
| 14 |
+
st.image(image, caption="Original Image", use_column_width=True)
|
| 15 |
+
|
| 16 |
+
# Filters and adjustments
|
| 17 |
+
st.write("### Apply Filters")
|
| 18 |
+
|
| 19 |
+
# Grayscale
|
| 20 |
+
if st.checkbox("Convert to Grayscale"):
|
| 21 |
+
image = image.convert("L")
|
| 22 |
+
st.image(image, caption="Grayscale Image", use_column_width=True)
|
| 23 |
+
|
| 24 |
+
# Brightness adjustment
|
| 25 |
+
brightness = st.slider("Adjust Brightness", 0.5, 2.0, 1.0)
|
| 26 |
+
enhancer = ImageEnhance.Brightness(image)
|
| 27 |
+
image = enhancer.enhance(brightness)
|
| 28 |
+
st.image(image, caption="Brightness Adjusted Image", use_column_width=True)
|
| 29 |
+
|
| 30 |
+
# Download edited image
|
| 31 |
+
st.write("### Download Edited Image")
|
| 32 |
+
edited_image = image
|
| 33 |
+
edited_image_format = "JPEG" if uploaded_file.name.endswith(".jpg") or uploaded_file.name.endswith(".jpeg") else "PNG"
|
| 34 |
+
edited_image_bytes = edited_image.tobytes()
|
| 35 |
+
st.download_button(
|
| 36 |
+
label="Download Image",
|
| 37 |
+
data=edited_image_bytes,
|
| 38 |
+
file_name=f"edited_image.{edited_image_format.lower()}",
|
| 39 |
+
mime=f"image/{edited_image_format.lower()}",
|
| 40 |
+
)
|