Afeefa123 commited on
Commit
88f47fc
·
verified ·
1 Parent(s): 7d57750

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +87 -15
app.py CHANGED
@@ -1,10 +1,34 @@
1
  import streamlit as st
2
- from PIL import Image, ImageEnhance, ImageOps
3
  import io
4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  # Title
6
- st.title("Image Editor")
7
- st.write("Upload an image, apply filters, and download the edited image.")
8
 
9
  # Upload image
10
  uploaded_file = st.file_uploader("Choose an image", type=["jpg", "jpeg", "png"])
@@ -13,23 +37,71 @@ if uploaded_file:
13
  # Load the image
14
  image = Image.open(uploaded_file)
15
  st.image(image, caption="Original Image", use_container_width=True)
16
-
 
 
 
 
 
 
17
  # Grayscale filter
18
- if st.checkbox("Apply Grayscale"):
19
- image = ImageOps.grayscale(image)
20
- st.image(image, caption="Grayscale Image", use_container_width=True)
21
-
22
  # Brightness adjustment
23
- brightness = st.slider("Adjust Brightness", 0.5, 3.0, 1.0, step=0.1)
24
- enhancer = ImageEnhance.Brightness(image)
25
- image = enhancer.enhance(brightness)
26
- st.image(image, caption="Brightness Adjusted Image", use_container_width=True)
27
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  # Download the edited image
29
  buf = io.BytesIO()
30
- image.save(buf, format="PNG")
31
  byte_im = buf.getvalue()
32
-
33
  st.download_button(
34
  label="Download Edited Image",
35
  data=byte_im,
 
1
  import streamlit as st
2
+ from PIL import Image, ImageEnhance, ImageOps, ImageDraw
3
  import io
4
 
5
+ # Set Page Config
6
+ st.set_page_config(page_title="Modern Image Editor", layout="centered")
7
+
8
+ # Custom Style
9
+ st.markdown(
10
+ """
11
+ <style>
12
+ .stApp {
13
+ background-color: #f5f5f5;
14
+ font-family: Arial, sans-serif;
15
+ }
16
+ .title {
17
+ color: #333;
18
+ font-size: 32px;
19
+ font-weight: bold;
20
+ }
21
+ .caption {
22
+ color: #555;
23
+ }
24
+ </style>
25
+ """,
26
+ unsafe_allow_html=True
27
+ )
28
+
29
  # Title
30
+ st.markdown("<div class='title'>Modern Image Editor</div>", unsafe_allow_html=True)
31
+ st.write("Upload an image, apply multiple filters, and download the edited image.")
32
 
33
  # Upload image
34
  uploaded_file = st.file_uploader("Choose an image", type=["jpg", "jpeg", "png"])
 
37
  # Load the image
38
  image = Image.open(uploaded_file)
39
  st.image(image, caption="Original Image", use_container_width=True)
40
+
41
+ # Create a copy for editing
42
+ edited_image = image.copy()
43
+
44
+ # Sidebar for controls
45
+ st.sidebar.title("Editing Options")
46
+
47
  # Grayscale filter
48
+ if st.sidebar.checkbox("Apply Grayscale"):
49
+ edited_image = ImageOps.grayscale(edited_image)
50
+
 
51
  # Brightness adjustment
52
+ brightness = st.sidebar.slider("Adjust Brightness", 0.5, 3.0, 1.0, step=0.1)
53
+ enhancer = ImageEnhance.Brightness(edited_image)
54
+ edited_image = enhancer.enhance(brightness)
55
+
56
+ # Contrast adjustment
57
+ contrast = st.sidebar.slider("Adjust Contrast", 0.5, 3.0, 1.0, step=0.1)
58
+ enhancer = ImageEnhance.Contrast(edited_image)
59
+ edited_image = enhancer.enhance(contrast)
60
+
61
+ # Saturation adjustment
62
+ saturation = st.sidebar.slider("Adjust Saturation", 0.5, 3.0, 1.0, step=0.1)
63
+ enhancer = ImageEnhance.Color(edited_image)
64
+ edited_image = enhancer.enhance(saturation)
65
+
66
+ # Sharpness adjustment
67
+ sharpness = st.sidebar.slider("Adjust Sharpness", 0.5, 3.0, 1.0, step=0.1)
68
+ enhancer = ImageEnhance.Sharpness(edited_image)
69
+ edited_image = enhancer.enhance(sharpness)
70
+
71
+ # Add text overlay
72
+ if st.sidebar.checkbox("Add Text Overlay"):
73
+ text = st.sidebar.text_input("Enter Text", "Sample Text")
74
+ font_size = st.sidebar.slider("Font Size", 10, 100, 30)
75
+ draw = ImageDraw.Draw(edited_image)
76
+ draw.text((10, 10), text, fill="white")
77
+
78
+ # Flip options
79
+ flip_horizontal = st.sidebar.checkbox("Flip Horizontal")
80
+ if flip_horizontal:
81
+ edited_image = ImageOps.mirror(edited_image)
82
+
83
+ flip_vertical = st.sidebar.checkbox("Flip Vertical")
84
+ if flip_vertical:
85
+ edited_image = ImageOps.flip(edited_image)
86
+
87
+ # Rotate options
88
+ rotation = st.sidebar.slider("Rotate Image", 0, 360, 0, step=1)
89
+ if rotation:
90
+ edited_image = edited_image.rotate(rotation, expand=True)
91
+
92
+ # Border effect
93
+ if st.sidebar.checkbox("Add Border"):
94
+ border_width = st.sidebar.slider("Border Width", 1, 50, 10)
95
+ edited_image = ImageOps.expand(edited_image, border=border_width, fill="black")
96
+
97
+ # Display the edited image
98
+ st.image(edited_image, caption="Edited Image", use_container_width=True)
99
+
100
  # Download the edited image
101
  buf = io.BytesIO()
102
+ edited_image.save(buf, format="PNG")
103
  byte_im = buf.getvalue()
104
+
105
  st.download_button(
106
  label="Download Edited Image",
107
  data=byte_im,