Muhammad-Faizan-Ahmed commited on
Commit
95a28bd
·
verified ·
1 Parent(s): 7137a46

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -0
app.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from PIL import Image, ImageEnhance
3
+ import numpy as np
4
+
5
+ # Set up the app
6
+ st.title("Image Editor")
7
+ st.write("Upload an image, apply filters, and download the edited version.")
8
+
9
+ # Upload image
10
+ uploaded_file = st.file_uploader("Upload an image", type=["png", "jpg", "jpeg"])
11
+
12
+ if uploaded_file:
13
+ # Open the uploaded image
14
+ image = Image.open(uploaded_file)
15
+ st.image(image, caption="Uploaded Image", use_column_width=True)
16
+
17
+ # Filters
18
+ st.sidebar.title("Filters")
19
+
20
+ # Grayscale filter
21
+ if st.sidebar.checkbox("Apply Grayscale"):
22
+ image = image.convert("L")
23
+
24
+ # Brightness adjustment
25
+ brightness = st.sidebar.slider("Adjust Brightness", 0.5, 3.0, 1.0)
26
+ enhancer = ImageEnhance.Brightness(image)
27
+ image = enhancer.enhance(brightness)
28
+
29
+ # Display the edited image
30
+ st.image(image, caption="Edited Image", use_column_width=True)
31
+
32
+ # Download the edited image
33
+ img_download = st.sidebar.button("Download Edited Image")
34
+ if img_download:
35
+ # Save the image to a BytesIO object
36
+ from io import BytesIO
37
+ buf = BytesIO()
38
+ image_format = "PNG" if image.mode in ["RGBA", "LA"] else "JPEG"
39
+ image.save(buf, format=image_format)
40
+ byte_im = buf.getvalue()
41
+
42
+ # Provide a download button
43
+ st.download_button(
44
+ label="Download Image",
45
+ data=byte_im,
46
+ file_name=f"edited_image.{image_format.lower()}",
47
+ mime=f"image/{image_format.lower()}",
48
+ )