arsalan16 commited on
Commit
a8b1bdc
·
verified ·
1 Parent(s): 095a7dd

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
+ import io
5
+
6
+ # Function to apply grayscale filter
7
+ def apply_grayscale(image):
8
+ return image.convert("L")
9
+
10
+ # Function to adjust brightness
11
+ def adjust_brightness(image, factor):
12
+ enhancer = ImageEnhance.Brightness(image)
13
+ return enhancer.enhance(factor)
14
+
15
+ # Main function for the app
16
+ def main():
17
+ st.title("Simple Image Editor")
18
+
19
+ # Upload image
20
+ uploaded_file = st.file_uploader("Upload an Image", type=["jpg", "png", "jpeg"])
21
+
22
+ if uploaded_file is not None:
23
+ # Open image
24
+ image = Image.open(uploaded_file)
25
+
26
+ # Display original image
27
+ st.image(image, caption="Original Image", use_column_width=True)
28
+
29
+ # Choose filter
30
+ filter_option = st.selectbox("Choose a filter", ("None", "Grayscale", "Adjust Brightness"))
31
+
32
+ if filter_option == "Grayscale":
33
+ image = apply_grayscale(image)
34
+ st.image(image, caption="Grayscale Image", use_column_width=True)
35
+
36
+ elif filter_option == "Adjust Brightness":
37
+ brightness_factor = st.slider("Brightness Factor", 0.1, 2.0, 1.0)
38
+ image = adjust_brightness(image, brightness_factor)
39
+ st.image(image, caption="Brightness Adjusted Image", use_column_width=True)
40
+
41
+ # Download the edited image
42
+ img_byte_arr = io.BytesIO()
43
+ image.save(img_byte_arr, format="PNG")
44
+ img_byte_arr.seek(0)
45
+ st.download_button("Download Image", img_byte_arr, file_name="edited_image.png", mime="image/png")
46
+
47
+ if __name__ == "__main__":
48
+ main()