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" )