Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,19 +4,27 @@ from PIL import Image, ImageEnhance, ImageFilter
|
|
| 4 |
import numpy as np
|
| 5 |
import cv2
|
| 6 |
|
| 7 |
-
def apply_filters(image, filter_option, brightness, contrast, saturation):
|
|
|
|
|
|
|
|
|
|
| 8 |
# Apply selected filter
|
| 9 |
if filter_option == "Gray Scale":
|
| 10 |
image = image.convert("L")
|
| 11 |
elif filter_option == "Blur":
|
| 12 |
image = image.filter(ImageFilter.GaussianBlur(5))
|
| 13 |
-
elif filter_option == "
|
| 14 |
image = image.filter(ImageFilter.SHARPEN)
|
| 15 |
-
elif filter_option == "
|
| 16 |
-
image = image.filter(ImageFilter.
|
| 17 |
elif filter_option == "Magic Eraser":
|
| 18 |
image = image.filter(ImageFilter.SMOOTH)
|
| 19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
# Apply adjustments
|
| 21 |
enhancer = ImageEnhance.Brightness(image)
|
| 22 |
image = enhancer.enhance(brightness)
|
|
@@ -42,12 +50,20 @@ def main():
|
|
| 42 |
|
| 43 |
# Filters & Enhancements
|
| 44 |
filter_option = st.sidebar.selectbox("Select a Filter", [
|
| 45 |
-
"None", "Gray Scale", "Blur", "
|
| 46 |
])
|
| 47 |
|
| 48 |
brightness = st.sidebar.slider("Brightness", 0.5, 3.0, 1.0)
|
| 49 |
contrast = st.sidebar.slider("Contrast", 0.5, 3.0, 1.0)
|
| 50 |
saturation = st.sidebar.slider("Saturation", 0.5, 3.0, 1.0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
# Display original and edited images side by side
|
| 53 |
col1, col2 = st.columns(2)
|
|
@@ -56,7 +72,16 @@ def main():
|
|
| 56 |
st.image(image, caption="Original Image", use_column_width=True)
|
| 57 |
|
| 58 |
with col2:
|
| 59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
st.image(edited_image, caption="Edited Image", use_column_width=True)
|
| 61 |
|
| 62 |
if st.sidebar.button("Download Edited Image"):
|
|
|
|
| 4 |
import numpy as np
|
| 5 |
import cv2
|
| 6 |
|
| 7 |
+
def apply_filters(image, filter_option, brightness, contrast, saturation, tint):
|
| 8 |
+
# Convert image to numpy array for OpenCV manipulations
|
| 9 |
+
img_array = np.array(image)
|
| 10 |
+
|
| 11 |
# Apply selected filter
|
| 12 |
if filter_option == "Gray Scale":
|
| 13 |
image = image.convert("L")
|
| 14 |
elif filter_option == "Blur":
|
| 15 |
image = image.filter(ImageFilter.GaussianBlur(5))
|
| 16 |
+
elif filter_option == "Sharpness":
|
| 17 |
image = image.filter(ImageFilter.SHARPEN)
|
| 18 |
+
elif filter_option == "Shadow":
|
| 19 |
+
image = image.filter(ImageFilter.CONTOUR)
|
| 20 |
elif filter_option == "Magic Eraser":
|
| 21 |
image = image.filter(ImageFilter.SMOOTH)
|
| 22 |
|
| 23 |
+
# Apply tint (using OpenCV)
|
| 24 |
+
if tint != 0:
|
| 25 |
+
img_array = cv2.addWeighted(img_array, 1, np.zeros_like(img_array, img_array.dtype), 0, tint)
|
| 26 |
+
image = Image.fromarray(img_array)
|
| 27 |
+
|
| 28 |
# Apply adjustments
|
| 29 |
enhancer = ImageEnhance.Brightness(image)
|
| 30 |
image = enhancer.enhance(brightness)
|
|
|
|
| 50 |
|
| 51 |
# Filters & Enhancements
|
| 52 |
filter_option = st.sidebar.selectbox("Select a Filter", [
|
| 53 |
+
"None", "Gray Scale", "Blur", "Sharpness", "Shadow", "Magic Eraser"
|
| 54 |
])
|
| 55 |
|
| 56 |
brightness = st.sidebar.slider("Brightness", 0.5, 3.0, 1.0)
|
| 57 |
contrast = st.sidebar.slider("Contrast", 0.5, 3.0, 1.0)
|
| 58 |
saturation = st.sidebar.slider("Saturation", 0.5, 3.0, 1.0)
|
| 59 |
+
tint = st.sidebar.slider("Tint Adjustment", -50, 50, 0)
|
| 60 |
+
|
| 61 |
+
# Crop Tool
|
| 62 |
+
st.sidebar.subheader("Crop")
|
| 63 |
+
crop_left = st.sidebar.slider("Left", 0, 100, 0)
|
| 64 |
+
crop_top = st.sidebar.slider("Top", 0, 100, 0)
|
| 65 |
+
crop_right = st.sidebar.slider("Right", 0, 100, 0)
|
| 66 |
+
crop_bottom = st.sidebar.slider("Bottom", 0, 100, 0)
|
| 67 |
|
| 68 |
# Display original and edited images side by side
|
| 69 |
col1, col2 = st.columns(2)
|
|
|
|
| 72 |
st.image(image, caption="Original Image", use_column_width=True)
|
| 73 |
|
| 74 |
with col2:
|
| 75 |
+
# Apply cropping
|
| 76 |
+
width, height = image.size
|
| 77 |
+
left = crop_left / 100 * width
|
| 78 |
+
top = crop_top / 100 * height
|
| 79 |
+
right = width - (crop_right / 100 * width)
|
| 80 |
+
bottom = height - (crop_bottom / 100 * height)
|
| 81 |
+
cropped_image = image.crop((left, top, right, bottom))
|
| 82 |
+
|
| 83 |
+
# Apply filters and adjustments
|
| 84 |
+
edited_image = apply_filters(cropped_image, filter_option, brightness, contrast, saturation, tint)
|
| 85 |
st.image(edited_image, caption="Edited Image", use_column_width=True)
|
| 86 |
|
| 87 |
if st.sidebar.button("Download Edited Image"):
|