Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from PIL import Image, ImageEnhance, ImageFilter
|
| 3 |
+
import io
|
| 4 |
+
|
| 5 |
+
# Title and file uploader
|
| 6 |
+
st.title("Image Editor")
|
| 7 |
+
uploaded_file = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
|
| 8 |
+
|
| 9 |
+
if uploaded_file:
|
| 10 |
+
# Load the uploaded image
|
| 11 |
+
image = Image.open(uploaded_file)
|
| 12 |
+
st.image(image, caption="Uploaded Image", use_column_width=True)
|
| 13 |
+
|
| 14 |
+
# Feature controls
|
| 15 |
+
st.sidebar.title("Editing Options")
|
| 16 |
+
|
| 17 |
+
# Brightness
|
| 18 |
+
brightness = st.sidebar.slider("Brightness", 0.1, 2.0, 1.0)
|
| 19 |
+
enhancer = ImageEnhance.Brightness(image)
|
| 20 |
+
image = enhancer.enhance(brightness)
|
| 21 |
+
|
| 22 |
+
# Contrast
|
| 23 |
+
contrast = st.sidebar.slider("Contrast", 0.1, 2.0, 1.0)
|
| 24 |
+
enhancer = ImageEnhance.Contrast(image)
|
| 25 |
+
image = enhancer.enhance(contrast)
|
| 26 |
+
|
| 27 |
+
# Sharpness
|
| 28 |
+
sharpness = st.sidebar.slider("Sharpness", 0.1, 2.0, 1.0)
|
| 29 |
+
enhancer = ImageEnhance.Sharpness(image)
|
| 30 |
+
image = enhancer.enhance(sharpness)
|
| 31 |
+
|
| 32 |
+
# Convert to grayscale
|
| 33 |
+
if st.sidebar.checkbox("Convert to Grayscale"):
|
| 34 |
+
image = image.convert("L")
|
| 35 |
+
|
| 36 |
+
# Apply filters
|
| 37 |
+
filter_option = st.sidebar.selectbox("Apply Filter", ["None", "BLUR", "CONTOUR", "DETAIL", "EDGE_ENHANCE", "SHARPEN"])
|
| 38 |
+
if filter_option == "BLUR":
|
| 39 |
+
image = image.filter(ImageFilter.BLUR)
|
| 40 |
+
elif filter_option == "CONTOUR":
|
| 41 |
+
image = image.filter(ImageFilter.CONTOUR)
|
| 42 |
+
elif filter_option == "DETAIL":
|
| 43 |
+
image = image.filter(ImageFilter.DETAIL)
|
| 44 |
+
elif filter_option == "EDGE_ENHANCE":
|
| 45 |
+
image = image.filter(ImageFilter.EDGE_ENHANCE)
|
| 46 |
+
elif filter_option == "SHARPEN":
|
| 47 |
+
image = image.filter(ImageFilter.SHARPEN)
|
| 48 |
+
|
| 49 |
+
# Crop
|
| 50 |
+
if st.sidebar.checkbox("Crop Image"):
|
| 51 |
+
left = st.sidebar.number_input("Left", 0, image.width, 0)
|
| 52 |
+
top = st.sidebar.number_input("Top", 0, image.height, 0)
|
| 53 |
+
right = st.sidebar.number_input("Right", left + 1, image.width, image.width)
|
| 54 |
+
bottom = st.sidebar.number_input("Bottom", top + 1, image.height, image.height)
|
| 55 |
+
image = image.crop((left, top, right, bottom))
|
| 56 |
+
|
| 57 |
+
# Display the edited image
|
| 58 |
+
st.image(image, caption="Edited Image", use_column_width=True)
|
| 59 |
+
|
| 60 |
+
# Download the edited image
|
| 61 |
+
buf = io.BytesIO()
|
| 62 |
+
image.save(buf, format="PNG")
|
| 63 |
+
byte_im = buf.getvalue()
|
| 64 |
+
st.download_button("Download Edited Image", data=byte_im, file_name="edited_image.png", mime="image/png")
|
| 65 |
+
|
| 66 |
+
# Instructions if no file uploaded
|
| 67 |
+
else:
|
| 68 |
+
st.write("Please upload an image to start editing.")
|