Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import cv2
|
| 3 |
+
import numpy as np
|
| 4 |
+
from PIL import Image
|
| 5 |
+
|
| 6 |
+
st.set_page_config(page_title="AI Image Enhancer", page_icon="🖼️")
|
| 7 |
+
|
| 8 |
+
st.title("🖼️ Image Quality Enhancer (HD + Deblur)")
|
| 9 |
+
|
| 10 |
+
uploaded_file = st.file_uploader("Upload Image", type=["jpg", "png", "jpeg"])
|
| 11 |
+
|
| 12 |
+
def enhance_image(image, scale=2):
|
| 13 |
+
img = np.array(image)
|
| 14 |
+
|
| 15 |
+
# Upscale (pseudo 4K)
|
| 16 |
+
width = int(img.shape[1] * scale)
|
| 17 |
+
height = int(img.shape[0] * scale)
|
| 18 |
+
resized = cv2.resize(img, (width, height), interpolation=cv2.INTER_CUBIC)
|
| 19 |
+
|
| 20 |
+
# Denoise
|
| 21 |
+
denoised = cv2.fastNlMeansDenoisingColored(resized, None, 10, 10, 7, 21)
|
| 22 |
+
|
| 23 |
+
# Sharpen
|
| 24 |
+
kernel = np.array([[0, -1, 0],
|
| 25 |
+
[-1, 5,-1],
|
| 26 |
+
[0, -1, 0]])
|
| 27 |
+
sharpened = cv2.filter2D(denoised, -1, kernel)
|
| 28 |
+
|
| 29 |
+
return sharpened
|
| 30 |
+
|
| 31 |
+
if uploaded_file:
|
| 32 |
+
image = Image.open(uploaded_file)
|
| 33 |
+
|
| 34 |
+
st.subheader("Original Image")
|
| 35 |
+
st.image(image, use_column_width=True)
|
| 36 |
+
|
| 37 |
+
scale = st.slider("Upscale Level", 1, 4, 2)
|
| 38 |
+
|
| 39 |
+
if st.button("Enhance Image"):
|
| 40 |
+
enhanced = enhance_image(image, scale)
|
| 41 |
+
|
| 42 |
+
st.subheader("Enhanced Image")
|
| 43 |
+
st.image(enhanced, use_column_width=True)
|
| 44 |
+
|
| 45 |
+
# Download
|
| 46 |
+
result = Image.fromarray(enhanced)
|
| 47 |
+
st.download_button(
|
| 48 |
+
"Download Image",
|
| 49 |
+
data=result.tobytes(),
|
| 50 |
+
file_name="enhanced.png",
|
| 51 |
+
mime="image/png"
|
| 52 |
+
)
|
| 53 |
+
|
| 54 |
+
st.markdown("---")
|
| 55 |
+
st.caption("Built with ❤️ using Streamlit")
|