Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# File: app.py
|
| 2 |
+
import streamlit as st
|
| 3 |
+
from PIL import Image, ImageEnhance
|
| 4 |
+
import numpy as np
|
| 5 |
+
|
| 6 |
+
# Title and Description
|
| 7 |
+
st.title("Image Editor")
|
| 8 |
+
st.write("Upload an image, apply filters like Grayscale or Brightness Adjustment, and download the edited image.")
|
| 9 |
+
|
| 10 |
+
# Image Upload
|
| 11 |
+
uploaded_image = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
|
| 12 |
+
if uploaded_image:
|
| 13 |
+
image = Image.open(uploaded_image)
|
| 14 |
+
st.image(image, caption="Uploaded Image", use_column_width=True)
|
| 15 |
+
|
| 16 |
+
# Grayscale Filter
|
| 17 |
+
if st.checkbox("Apply Grayscale Filter"):
|
| 18 |
+
image = image.convert("L")
|
| 19 |
+
st.image(image, caption="Grayscale Image", use_column_width=True)
|
| 20 |
+
|
| 21 |
+
# Brightness Adjustment
|
| 22 |
+
brightness = st.slider("Adjust Brightness", 0.1, 3.0, 1.0)
|
| 23 |
+
if brightness != 1.0:
|
| 24 |
+
enhancer = ImageEnhance.Brightness(image)
|
| 25 |
+
image = enhancer.enhance(brightness)
|
| 26 |
+
st.image(image, caption="Brightness Adjusted Image", use_column_width=True)
|
| 27 |
+
|
| 28 |
+
# Download Button
|
| 29 |
+
st.write("### Download Edited Image")
|
| 30 |
+
edited_image = np.array(image)
|
| 31 |
+
image_pil = Image.fromarray(edited_image)
|
| 32 |
+
|
| 33 |
+
download_button = st.download_button(
|
| 34 |
+
label="Download Image",
|
| 35 |
+
data=edited_image.tobytes(),
|
| 36 |
+
file_name="edited_image.png",
|
| 37 |
+
mime="image/png"
|
| 38 |
+
)
|