ayush12309 commited on
Commit
8cfe765
·
verified ·
1 Parent(s): 8186c43

Create app.py

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