Talha1786 commited on
Commit
c3f6167
·
verified ·
1 Parent(s): 949fa46

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
+ # Function to apply grayscale filter
6
+ def apply_grayscale(image):
7
+ return image.convert("L")
8
+
9
+ # Function to adjust brightness
10
+ def adjust_brightness(image, factor):
11
+ enhancer = ImageEnhance.Brightness(image)
12
+ return enhancer.enhance(factor)
13
+
14
+ # Streamlit UI
15
+ st.title("Simple Image Editor")
16
+
17
+ # Upload image
18
+ uploaded_file = st.file_uploader("Choose an image", type=["jpg", "png", "jpeg"])
19
+
20
+ if uploaded_file is not None:
21
+ # Open image
22
+ image = Image.open(uploaded_file)
23
+
24
+ # Display original image
25
+ st.image(image, caption="Original Image", use_column_width=True)
26
+
27
+ # Select filter to apply
28
+ filter_option = st.selectbox("Choose a filter", ("None", "Grayscale", "Brightness"))
29
+
30
+ # Apply selected filter
31
+ if filter_option == "Grayscale":
32
+ image = apply_grayscale(image)
33
+ elif filter_option == "Brightness":
34
+ factor = st.slider("Adjust brightness", 0.5, 2.0, 1.0)
35
+ image = adjust_brightness(image, factor)
36
+
37
+ # Display edited image
38
+ st.image(image, caption="Edited Image", use_column_width=True)
39
+
40
+ # Provide option to download the edited image
41
+ with st.spinner('Preparing your image for download...'):
42
+ image.save("edited_image.png")
43
+ st.download_button(
44
+ label="Download Edited Image",
45
+ data=open("edited_image.png", "rb").read(),
46
+ file_name="edited_image.png",
47
+ mime="image/png"
48
+ )