Spaces:
Build error
Build error
File size: 1,882 Bytes
6ed8b17 6a2aa7b 6ed8b17 6a2aa7b 6ed8b17 6a2aa7b 6ed8b17 6a2aa7b 6ed8b17 d22cd08 6a2aa7b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
import streamlit as st
from PIL import Image, ImageEnhance, ImageOps
import io
# Function to apply filters to the image
def apply_filter(image, filter_type, brightness_factor):
if filter_type == 'Grayscale':
return ImageOps.grayscale(image)
elif filter_type == 'Brightness':
enhancer = ImageEnhance.Brightness(image)
return enhancer.enhance(brightness_factor) # Adjust brightness based on the slider value
return image
# Set up the Streamlit app
st.title("Simple Image Editor")
# Image upload
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "png", "jpeg"])
if uploaded_file is not None:
# Open the image
image = Image.open(uploaded_file)
st.image(image, caption="Uploaded Image", use_column_width=True)
# Options for filters
filter_type = st.selectbox("Choose a filter", ["None", "Grayscale", "Brightness"])
if filter_type == "Brightness":
# Add a slider to adjust the brightness factor
brightness_factor = st.slider("Adjust Brightness", 0.5, 3.0, 1.0) # Range from 0.5 to 3.0 with default value 1.0
if filter_type != "None":
# Apply the selected filter
edited_image = apply_filter(image, filter_type, brightness_factor) if filter_type == "Brightness" else apply_filter(image, filter_type, 1.0)
st.image(edited_image, caption=f"Edited Image with {filter_type} filter", use_column_width=True)
# Convert edited image to bytes for download
img_byte_arr = io.BytesIO()
edited_image.save(img_byte_arr, format="PNG")
img_byte_arr = img_byte_arr.getvalue()
# Allow the user to download the edited image
st.download_button(
label="Download Edited Image",
data=img_byte_arr,
file_name="edited_image.png",
mime="image/png"
)
|