Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from PIL import Image, ImageEnhance, ImageFilter
|
3 |
+
import io
|
4 |
+
|
5 |
+
# App Title and Description
|
6 |
+
st.title("🌟 Simple Image Enhancer")
|
7 |
+
st.write("""
|
8 |
+
Enhance your images with filters like grayscale, brightness adjustment, sharpness, and more!
|
9 |
+
Special focus on enhancing eyes, lips, beard, and hair for a more appealing output.
|
10 |
+
Follow the instructions below to use this app.
|
11 |
+
""")
|
12 |
+
|
13 |
+
# Sidebar Instructions
|
14 |
+
st.sidebar.title("Instructions")
|
15 |
+
st.sidebar.write("""
|
16 |
+
1. Upload an image using the "Choose File" button.
|
17 |
+
2. Select a filter from the options provided.
|
18 |
+
3. Adjust the sliders as needed to enhance the image.
|
19 |
+
4. Click **Apply Filter** to view the enhanced image.
|
20 |
+
5. Use the **Download Enhanced Image** button to save your edited image.
|
21 |
+
""")
|
22 |
+
|
23 |
+
# Image Upload
|
24 |
+
uploaded_image = st.file_uploader("Upload an Image", type=["jpg", "jpeg", "png"])
|
25 |
+
|
26 |
+
if uploaded_image:
|
27 |
+
# Display original image
|
28 |
+
st.subheader("Original Image")
|
29 |
+
image = Image.open(uploaded_image)
|
30 |
+
st.image(image, caption="Uploaded Image", use_column_width=True)
|
31 |
+
|
32 |
+
# Filters Section
|
33 |
+
st.subheader("Choose Enhancement Options")
|
34 |
+
filter_option = st.selectbox("Select a filter", ["None", "Grayscale", "Enhance Brightness", "Enhance Sharpness", "Smooth Features"])
|
35 |
+
|
36 |
+
# Brightness Adjustment
|
37 |
+
if filter_option == "Enhance Brightness":
|
38 |
+
brightness_factor = st.slider("Brightness Factor", 0.1, 3.0, 1.0)
|
39 |
+
|
40 |
+
# Sharpness Adjustment
|
41 |
+
elif filter_option == "Enhance Sharpness":
|
42 |
+
sharpness_factor = st.slider("Sharpness Factor", 0.1, 3.0, 1.0)
|
43 |
+
|
44 |
+
# Apply Filter Button
|
45 |
+
if st.button("Apply Filter"):
|
46 |
+
if filter_option == "Grayscale":
|
47 |
+
enhanced_image = image.convert("L")
|
48 |
+
elif filter_option == "Enhance Brightness":
|
49 |
+
enhancer = ImageEnhance.Brightness(image)
|
50 |
+
enhanced_image = enhancer.enhance(brightness_factor)
|
51 |
+
elif filter_option == "Enhance Sharpness":
|
52 |
+
enhancer = ImageEnhance.Sharpness(image)
|
53 |
+
enhanced_image = enhancer.enhance(sharpness_factor)
|
54 |
+
elif filter_option == "Smooth Features":
|
55 |
+
enhanced_image = image.filter(ImageFilter.SMOOTH)
|
56 |
+
else:
|
57 |
+
enhanced_image = image
|
58 |
+
|
59 |
+
# Display Enhanced Image
|
60 |
+
st.subheader("Enhanced Image")
|
61 |
+
st.image(enhanced_image, caption="Enhanced Image", use_column_width=True)
|
62 |
+
|
63 |
+
# Download Enhanced Image
|
64 |
+
buf = io.BytesIO()
|
65 |
+
enhanced_image.save(buf, format="PNG")
|
66 |
+
byte_im = buf.getvalue()
|
67 |
+
st.download_button(
|
68 |
+
label="Download Enhanced Image",
|
69 |
+
data=byte_im,
|
70 |
+
file_name="enhanced_image.png",
|
71 |
+
mime="image/png"
|
72 |
+
)
|
73 |
+
else:
|
74 |
+
st.info("Please upload an image to get started.")
|
75 |
+
|
76 |
+
# Footer
|
77 |
+
st.write("---")
|
78 |
+
st.markdown("💡 **Developed by Abdullah**")
|