Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from PIL import Image, ImageEnhance
|
| 3 |
+
import cv2
|
| 4 |
+
import numpy as np
|
| 5 |
+
|
| 6 |
+
# Function to apply grayscale filter
|
| 7 |
+
def apply_grayscale(image):
|
| 8 |
+
return image.convert("L")
|
| 9 |
+
|
| 10 |
+
# Function to adjust brightness
|
| 11 |
+
def adjust_brightness(image, factor):
|
| 12 |
+
enhancer = ImageEnhance.Brightness(image)
|
| 13 |
+
return enhancer.enhance(factor)
|
| 14 |
+
|
| 15 |
+
# Streamlit app
|
| 16 |
+
def main():
|
| 17 |
+
st.title("Simple Image Editor")
|
| 18 |
+
|
| 19 |
+
# Upload image
|
| 20 |
+
uploaded_image = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
|
| 21 |
+
|
| 22 |
+
if uploaded_image is not None:
|
| 23 |
+
# Open the uploaded image using PIL
|
| 24 |
+
image = Image.open(uploaded_image)
|
| 25 |
+
st.image(image, caption="Uploaded Image", use_column_width=True)
|
| 26 |
+
|
| 27 |
+
# Apply filters
|
| 28 |
+
st.sidebar.title("Adjust Filters")
|
| 29 |
+
|
| 30 |
+
filter_option = st.sidebar.selectbox("Choose a filter", ("None", "Grayscale", "Brightness"))
|
| 31 |
+
|
| 32 |
+
if filter_option == "Grayscale":
|
| 33 |
+
image = apply_grayscale(image)
|
| 34 |
+
st.image(image, caption="Grayscale Image", use_column_width=True)
|
| 35 |
+
|
| 36 |
+
elif filter_option == "Brightness":
|
| 37 |
+
brightness_factor = st.sidebar.slider("Brightness Factor", 0.1, 2.0, 1.0)
|
| 38 |
+
image = adjust_brightness(image, brightness_factor)
|
| 39 |
+
st.image(image, caption="Brightness Adjusted Image", use_column_width=True)
|
| 40 |
+
|
| 41 |
+
# Button to download the edited image
|
| 42 |
+
st.sidebar.download_button("Download Edited Image", image, "edited_image.jpg", "image/jpeg")
|
| 43 |
+
|
| 44 |
+
if __name__ == "__main__":
|
| 45 |
+
main()
|