Spaces:
Build error
Build error
| 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" | |
| ) | |