Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from PIL import Image, ImageEnhance
|
| 3 |
+
import io
|
| 4 |
+
|
| 5 |
+
st.title("Image Editor")
|
| 6 |
+
|
| 7 |
+
# Upload an image
|
| 8 |
+
uploaded_image = st.file_uploader("Add Image", type=["jpg", "jpeg", "png"])
|
| 9 |
+
|
| 10 |
+
if uploaded_image:
|
| 11 |
+
image = Image.open(uploaded_image)
|
| 12 |
+
st.image(image, caption="Uploaded Image", use_column_width=True)
|
| 13 |
+
|
| 14 |
+
# Sidebar for filters
|
| 15 |
+
st.sidebar.header("Adjust Filters")
|
| 16 |
+
brightness = st.sidebar.slider("Brightness", 0.1, 3.0, 1.0)
|
| 17 |
+
contrast = st.sidebar.slider("Contrast", 0.1, 3.0, 1.0)
|
| 18 |
+
sharpness = st.sidebar.slider("Sharpness", 0.1, 3.0, 1.0)
|
| 19 |
+
|
| 20 |
+
# Resize options
|
| 21 |
+
st.sidebar.header("Resize Image")
|
| 22 |
+
width = st.sidebar.number_input("Width", value=image.width, step=1)
|
| 23 |
+
height = st.sidebar.number_input("Height", value=image.height, step=1)
|
| 24 |
+
|
| 25 |
+
# Apply filters
|
| 26 |
+
enhancer_brightness = ImageEnhance.Brightness(image)
|
| 27 |
+
image = enhancer_brightness.enhance(brightness)
|
| 28 |
+
|
| 29 |
+
enhancer_contrast = ImageEnhance.Contrast(image)
|
| 30 |
+
image = enhancer_contrast.enhance(contrast)
|
| 31 |
+
|
| 32 |
+
enhancer_sharpness = ImageEnhance.Sharpness(image)
|
| 33 |
+
image = enhancer_sharpness.enhance(sharpness)
|
| 34 |
+
|
| 35 |
+
# Resize image
|
| 36 |
+
image = image.resize((int(width), int(height)))
|
| 37 |
+
|
| 38 |
+
# Display edited image
|
| 39 |
+
st.image(image, caption="Edited Image", use_column_width=True)
|
| 40 |
+
|
| 41 |
+
# Convert to bytes for download
|
| 42 |
+
img_bytes = io.BytesIO()
|
| 43 |
+
image.save(img_bytes, format="PNG")
|
| 44 |
+
img_bytes = img_bytes.getvalue()
|
| 45 |
+
|
| 46 |
+
# Download button
|
| 47 |
+
st.download_button("Download Image", data=img_bytes, file_name="edited_image.png", mime="image/png")
|