File size: 1,558 Bytes
8cfe765 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
import streamlit as st
import tensorflow as tf
import cv2
import numpy as np
from PIL import Image
@st.cache_resource
def load_model():
return tf.keras.models.load_model('synthetic_underwater_esrgan.h5')
model = load_model()
st.set_page_config(page_title="🌊 Underwater Image Enhancer", layout="wide")
st.title("🌊 Deep Sea Image Super Resolution")
st.write("Upload blurry underwater images to enhance their quality")
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "png", "jpeg"])
if uploaded_file is not None:
col1, col2 = st.columns(2)
with col1:
st.header("Original Image")
image = Image.open(uploaded_file)
st.image(image, use_column_width=True)
if st.button("Enhance Image", type="primary"):
with st.spinner("Enhancing image..."):
# Convert to numpy array
lr_img = np.array(image) / 255.0
# Predict
sr_img = model.predict(np.expand_dims(lr_img, axis=0))[0]
sr_img = np.clip(sr_img * 255, 0, 255).astype(np.uint8)
with col2:
st.header("Enhanced Image")
st.image(sr_img, use_column_width=True)
# Download button
st.download_button(
label="⬇️ Download Enhanced Image",
data=cv2.imencode('.png', cv2.cvtColor(sr_img, cv2.COLOR_RGB2BGR))[1].tobytes(),
file_name="enhanced.png",
mime="image/png"
) |