File size: 1,487 Bytes
c3f6167
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import numpy as np

# Function to apply grayscale filter
def apply_grayscale(image):
    return image.convert("L")

# Function to adjust brightness
def adjust_brightness(image, factor):
    enhancer = ImageEnhance.Brightness(image)
    return enhancer.enhance(factor)

# Streamlit UI
st.title("Simple Image Editor")

# Upload image
uploaded_file = st.file_uploader("Choose an image", type=["jpg", "png", "jpeg"])

if uploaded_file is not None:
    # Open image
    image = Image.open(uploaded_file)

    # Display original image
    st.image(image, caption="Original Image", use_column_width=True)

    # Select filter to apply
    filter_option = st.selectbox("Choose a filter", ("None", "Grayscale", "Brightness"))

    # Apply selected filter
    if filter_option == "Grayscale":
        image = apply_grayscale(image)
    elif filter_option == "Brightness":
        factor = st.slider("Adjust brightness", 0.5, 2.0, 1.0)
        image = adjust_brightness(image, factor)

    # Display edited image
    st.image(image, caption="Edited Image", use_column_width=True)

    # Provide option to download the edited image
    with st.spinner('Preparing your image for download...'):
        image.save("edited_image.png")
        st.download_button(
            label="Download Edited Image",
            data=open("edited_image.png", "rb").read(),
            file_name="edited_image.png",
            mime="image/png"
        )