Ayesha003 commited on
Commit
8662504
Β·
verified Β·
1 Parent(s): 676c907

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +87 -18
app.py CHANGED
@@ -1,40 +1,109 @@
1
  import streamlit as st
2
- from PIL import Image, ImageEnhance
3
 
4
- # Title and Description
5
- st.title("Image Editor")
6
- st.write("Upload an image, apply filters, and download the edited version.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
 
8
- # Upload Image
 
 
 
 
 
 
 
 
 
 
 
9
  uploaded_image = st.file_uploader("Choose an image to edit", type=["jpg", "jpeg", "png"])
10
 
11
  if uploaded_image:
12
  image = Image.open(uploaded_image)
13
- st.image(image, caption="Uploaded Image", use_column_width=True)
 
 
 
14
 
15
- # Image Filters
16
- st.sidebar.header("Filters")
17
-
18
- # Grayscale
19
  if st.sidebar.checkbox("Apply Grayscale"):
20
  image = image.convert("L")
21
-
22
- # Brightness
23
- brightness = st.sidebar.slider("Adjust Brightness", 0.5, 3.0, 1.0)
 
 
 
 
 
24
  enhancer = ImageEnhance.Brightness(image)
25
  image = enhancer.enhance(brightness)
26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  # Display Edited Image
28
- st.image(image, caption="Edited Image", use_column_width=True)
 
29
 
30
- # Download Edited Image
31
- st.sidebar.header("Download")
32
  edited_image_path = "edited_image.png"
33
  image.save(edited_image_path)
34
  with open(edited_image_path, "rb") as file:
35
- btn = st.sidebar.download_button(
36
- label="Download Edited Image",
37
  data=file,
38
  file_name="edited_image.png",
39
  mime="image/png"
40
  )
 
 
 
 
 
1
  import streamlit as st
2
+ from PIL import Image, ImageEnhance, ImageFilter
3
 
4
+ # Custom CSS Styling
5
+ st.markdown("""
6
+ <style>
7
+ body {
8
+ background-color: #f4f4f4;
9
+ }
10
+ .main {
11
+ background-color: #ffffff;
12
+ padding: 20px;
13
+ border-radius: 10px;
14
+ box-shadow: 0px 4px 10px rgba(0, 0, 0, 0.1);
15
+ }
16
+ .stButton > button {
17
+ background-color: #007BFF;
18
+ color: white;
19
+ border-radius: 5px;
20
+ padding: 10px 20px;
21
+ }
22
+ .stButton > button:hover {
23
+ background-color: #0056b3;
24
+ }
25
+ .stSidebar {
26
+ background-color: #f8f9fa;
27
+ }
28
+ </style>
29
+ """, unsafe_allow_html=True)
30
 
31
+ # App Banner
32
+ st.image(
33
+ "https://via.placeholder.com/1200x300?text=Welcome+to+Image+Editor+Pro",
34
+ caption="Edit, Enhance, and Download Your Images Instantly",
35
+ use_container_width=True,
36
+ )
37
+
38
+ # Title
39
+ st.title("✨ Advanced Image Editor Pro")
40
+
41
+ # File Upload
42
+ st.header("Upload Your Image")
43
  uploaded_image = st.file_uploader("Choose an image to edit", type=["jpg", "jpeg", "png"])
44
 
45
  if uploaded_image:
46
  image = Image.open(uploaded_image)
47
+ st.image(image, caption="Original Image", use_container_width=True)
48
+
49
+ # Sidebar Filters
50
+ st.sidebar.header("🎨 Customize Your Image")
51
 
52
+ # Grayscale Filter
 
 
 
53
  if st.sidebar.checkbox("Apply Grayscale"):
54
  image = image.convert("L")
55
+
56
+ # Sepia Filter
57
+ if st.sidebar.checkbox("Apply Sepia"):
58
+ sepia_filter = ImageEnhance.Color(image)
59
+ image = sepia_filter.enhance(1.5)
60
+
61
+ # Brightness Adjustment
62
+ brightness = st.sidebar.slider("Brightness πŸ”†", 0.5, 3.0, 1.0)
63
  enhancer = ImageEnhance.Brightness(image)
64
  image = enhancer.enhance(brightness)
65
 
66
+ # Contrast Adjustment
67
+ contrast = st.sidebar.slider("Contrast 🌟", 0.5, 3.0, 1.0)
68
+ enhancer = ImageEnhance.Contrast(image)
69
+ image = enhancer.enhance(contrast)
70
+
71
+ # Blur Effect
72
+ blur_level = st.sidebar.slider("Blur Level 🌫️", 0, 10, 0)
73
+ if blur_level > 0:
74
+ image = image.filter(ImageFilter.GaussianBlur(blur_level))
75
+
76
+ # Flip Image
77
+ flip_option = st.sidebar.radio("Flip Image πŸ”„", ["None", "Horizontal", "Vertical"])
78
+ if flip_option == "Horizontal":
79
+ image = image.transpose(Image.FLIP_LEFT_RIGHT)
80
+ elif flip_option == "Vertical":
81
+ image = image.transpose(Image.FLIP_TOP_BOTTOM)
82
+
83
+ # Crop Image
84
+ st.sidebar.header("Crop Image βœ‚οΈ")
85
+ left = st.sidebar.slider("Left", 0, image.width, 0)
86
+ top = st.sidebar.slider("Top", 0, image.height, 0)
87
+ right = st.sidebar.slider("Right", left + 10, image.width, image.width)
88
+ bottom = st.sidebar.slider("Bottom", top + 10, image.height, image.height)
89
+ image = image.crop((left, top, right, bottom))
90
+
91
  # Display Edited Image
92
+ st.subheader("Edited Image")
93
+ st.image(image, caption="Your Enhanced Image", use_container_width=True)
94
 
95
+ # Download Section
96
+ st.sidebar.header("πŸ“₯ Download Your Image")
97
  edited_image_path = "edited_image.png"
98
  image.save(edited_image_path)
99
  with open(edited_image_path, "rb") as file:
100
+ st.sidebar.download_button(
101
+ label="Download Enhanced Image πŸ“‚",
102
  data=file,
103
  file_name="edited_image.png",
104
  mime="image/png"
105
  )
106
+
107
+ # Footer
108
+ st.markdown("---")
109
+ st.markdown("Designed with ❀️ using Streamlit. Happy Editing!")