Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,12 +3,12 @@ from PIL import Image, ImageEnhance, ImageOps
|
|
| 3 |
import io
|
| 4 |
|
| 5 |
# Function to apply filters to the image
|
| 6 |
-
def apply_filter(image, filter_type):
|
| 7 |
if filter_type == 'Grayscale':
|
| 8 |
return ImageOps.grayscale(image)
|
| 9 |
elif filter_type == 'Brightness':
|
| 10 |
enhancer = ImageEnhance.Brightness(image)
|
| 11 |
-
return enhancer.enhance(
|
| 12 |
return image
|
| 13 |
|
| 14 |
# Set up the Streamlit app
|
|
@@ -25,9 +25,13 @@ if uploaded_file is not None:
|
|
| 25 |
# Options for filters
|
| 26 |
filter_type = st.selectbox("Choose a filter", ["None", "Grayscale", "Brightness"])
|
| 27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
if filter_type != "None":
|
| 29 |
# Apply the selected filter
|
| 30 |
-
edited_image = apply_filter(image, filter_type)
|
| 31 |
st.image(edited_image, caption=f"Edited Image with {filter_type} filter", use_column_width=True)
|
| 32 |
|
| 33 |
# Convert edited image to bytes for download
|
|
@@ -41,4 +45,4 @@ if uploaded_file is not None:
|
|
| 41 |
data=img_byte_arr,
|
| 42 |
file_name="edited_image.png",
|
| 43 |
mime="image/png"
|
| 44 |
-
)
|
|
|
|
| 3 |
import io
|
| 4 |
|
| 5 |
# Function to apply filters to the image
|
| 6 |
+
def apply_filter(image, filter_type, brightness_factor):
|
| 7 |
if filter_type == 'Grayscale':
|
| 8 |
return ImageOps.grayscale(image)
|
| 9 |
elif filter_type == 'Brightness':
|
| 10 |
enhancer = ImageEnhance.Brightness(image)
|
| 11 |
+
return enhancer.enhance(brightness_factor) # Adjust brightness based on the slider value
|
| 12 |
return image
|
| 13 |
|
| 14 |
# Set up the Streamlit app
|
|
|
|
| 25 |
# Options for filters
|
| 26 |
filter_type = st.selectbox("Choose a filter", ["None", "Grayscale", "Brightness"])
|
| 27 |
|
| 28 |
+
if filter_type == "Brightness":
|
| 29 |
+
# Add a slider to adjust the brightness factor
|
| 30 |
+
brightness_factor = st.slider("Adjust Brightness", 0.5, 3.0, 1.0) # Range from 0.5 to 3.0 with default value 1.0
|
| 31 |
+
|
| 32 |
if filter_type != "None":
|
| 33 |
# Apply the selected filter
|
| 34 |
+
edited_image = apply_filter(image, filter_type, brightness_factor) if filter_type == "Brightness" else apply_filter(image, filter_type, 1.0)
|
| 35 |
st.image(edited_image, caption=f"Edited Image with {filter_type} filter", use_column_width=True)
|
| 36 |
|
| 37 |
# Convert edited image to bytes for download
|
|
|
|
| 45 |
data=img_byte_arr,
|
| 46 |
file_name="edited_image.png",
|
| 47 |
mime="image/png"
|
| 48 |
+
)
|