Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,23 +1,7 @@
|
|
| 1 |
-
import os
|
| 2 |
import streamlit as st
|
| 3 |
from PIL import Image, ImageEnhance
|
| 4 |
import numpy as np
|
| 5 |
-
|
| 6 |
-
# Check and ensure OpenCV (cv2) is installed with compatible NumPy
|
| 7 |
-
try:
|
| 8 |
-
import cv2
|
| 9 |
-
except ImportError:
|
| 10 |
-
st.warning("OpenCV not found or incompatible. Attempting to fix...")
|
| 11 |
-
os.system("pip install numpy==1.24.3 opencv-python-headless==4.8.0.74")
|
| 12 |
-
try:
|
| 13 |
-
import cv2
|
| 14 |
-
except ImportError:
|
| 15 |
-
st.error("Failed to fix OpenCV installation. Check requirements.txt for compatibility.")
|
| 16 |
-
st.stop()
|
| 17 |
-
|
| 18 |
-
# Verify Versions
|
| 19 |
-
st.sidebar.write(f"OpenCV Version: {cv2.__version__}")
|
| 20 |
-
st.sidebar.write(f"NumPy Version: {np.__version__}")
|
| 21 |
|
| 22 |
# Title and Description
|
| 23 |
st.title("Image Enhancer App")
|
|
@@ -35,7 +19,7 @@ if uploaded_file:
|
|
| 35 |
|
| 36 |
# Sidebar Filters
|
| 37 |
st.sidebar.header("Enhancement Options")
|
| 38 |
-
|
| 39 |
# Brightness
|
| 40 |
brightness = st.sidebar.slider("Brightness", 0.5, 3.0, 1.0)
|
| 41 |
enhancer = ImageEnhance.Brightness(image)
|
|
@@ -51,11 +35,18 @@ if uploaded_file:
|
|
| 51 |
enhancer = ImageEnhance.Sharpness(image)
|
| 52 |
image = enhancer.enhance(sharpness)
|
| 53 |
|
| 54 |
-
# Saturation (Using OpenCV for Saturation)
|
| 55 |
saturation = st.sidebar.slider("Saturation", 0.5, 3.0, 1.0)
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
|
| 60 |
# Display Enhanced Image
|
| 61 |
st.image(image, caption="Enhanced Image", use_column_width=True)
|
|
@@ -67,4 +58,4 @@ if uploaded_file:
|
|
| 67 |
st.sidebar.write("Image saved as `enhanced_image.png`!")
|
| 68 |
|
| 69 |
# Footer
|
| 70 |
-
st.markdown("
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from PIL import Image, ImageEnhance
|
| 3 |
import numpy as np
|
| 4 |
+
import cv2
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
# Title and Description
|
| 7 |
st.title("Image Enhancer App")
|
|
|
|
| 19 |
|
| 20 |
# Sidebar Filters
|
| 21 |
st.sidebar.header("Enhancement Options")
|
| 22 |
+
|
| 23 |
# Brightness
|
| 24 |
brightness = st.sidebar.slider("Brightness", 0.5, 3.0, 1.0)
|
| 25 |
enhancer = ImageEnhance.Brightness(image)
|
|
|
|
| 35 |
enhancer = ImageEnhance.Sharpness(image)
|
| 36 |
image = enhancer.enhance(sharpness)
|
| 37 |
|
| 38 |
+
# Saturation Adjustment (Using OpenCV for Saturation)
|
| 39 |
saturation = st.sidebar.slider("Saturation", 0.5, 3.0, 1.0)
|
| 40 |
+
|
| 41 |
+
# Ensure the image is in a valid NumPy format
|
| 42 |
+
image_np = np.array(image).astype(np.uint8)
|
| 43 |
+
|
| 44 |
+
if len(image_np.shape) == 3: # Check if the image has color channels
|
| 45 |
+
image_cv = cv2.cvtColor(image_np, cv2.COLOR_RGB2HSV)
|
| 46 |
+
image_cv[:, :, 1] = np.clip(image_cv[:, :, 1] * saturation, 0, 255)
|
| 47 |
+
image = Image.fromarray(cv2.cvtColor(image_cv, cv2.COLOR_HSV2RGB))
|
| 48 |
+
else:
|
| 49 |
+
st.warning("Saturation adjustment is only available for color images.")
|
| 50 |
|
| 51 |
# Display Enhanced Image
|
| 52 |
st.image(image, caption="Enhanced Image", use_column_width=True)
|
|
|
|
| 58 |
st.sidebar.write("Image saved as `enhanced_image.png`!")
|
| 59 |
|
| 60 |
# Footer
|
| 61 |
+
st.markdown("Built by NS!")
|