rizwanaidris2 commited on
Commit
6ed8b17
·
verified ·
1 Parent(s): 8a2d18e

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -0
app.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from PIL import Image, ImageEnhance, ImageOps
3
+ import io
4
+
5
+ # Function to apply filters to the image
6
+ def apply_filter(image, filter_type):
7
+ if filter_type == 'Grayscale':
8
+ return ImageOps.grayscale(image)
9
+ elif filter_type == 'Brightness':
10
+ enhancer = ImageEnhance.Brightness(image)
11
+ return enhancer.enhance(1.5) # Adjust brightness factor (1.0 is original)
12
+ return image
13
+
14
+ # Set up the Streamlit app
15
+ st.title("Simple Image Editor")
16
+
17
+ # Image upload
18
+ uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "png", "jpeg"])
19
+
20
+ if uploaded_file is not None:
21
+ # Open the image
22
+ image = Image.open(uploaded_file)
23
+ st.image(image, caption="Uploaded Image", use_column_width=True)
24
+
25
+ # Options for filters
26
+ filter_type = st.selectbox("Choose a filter", ["None", "Grayscale", "Brightness"])
27
+
28
+ if filter_type != "None":
29
+ # Apply the selected filter
30
+ edited_image = apply_filter(image, filter_type)
31
+ st.image(edited_image, caption=f"Edited Image with {filter_type} filter", use_column_width=True)
32
+
33
+ # Convert edited image to bytes for download
34
+ img_byte_arr = io.BytesIO()
35
+ edited_image.save(img_byte_arr, format="PNG")
36
+ img_byte_arr = img_byte_arr.getvalue()
37
+
38
+ # Allow the user to download the edited image
39
+ st.download_button(
40
+ label="Download Edited Image",
41
+ data=img_byte_arr,
42
+ f