Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,11 +1,11 @@
|
|
| 1 |
import os
|
| 2 |
import io
|
| 3 |
-
import numpy as np
|
| 4 |
-
import streamlit as st
|
| 5 |
import tensorflow as tf
|
| 6 |
import cv2
|
| 7 |
import multiprocessing
|
| 8 |
import threading
|
|
|
|
|
|
|
| 9 |
import plotly.graph_objects as go
|
| 10 |
from PIL import Image
|
| 11 |
|
|
@@ -31,10 +31,11 @@ def main():
|
|
| 31 |
|
| 32 |
if uploaded_file is not None:
|
| 33 |
|
|
|
|
| 34 |
image = Image.open(uploaded_file).convert("RGB")
|
| 35 |
image_np = np.array(image)
|
| 36 |
|
| 37 |
-
#
|
| 38 |
metrics = run_image_enhancement(image_np)
|
| 39 |
|
| 40 |
col1, col2 = st.columns(2)
|
|
@@ -46,19 +47,22 @@ def main():
|
|
| 46 |
with col2:
|
| 47 |
st.subheader(f"Enhanced ({mode})")
|
| 48 |
|
| 49 |
-
#
|
| 50 |
result_img = metrics["result"]
|
| 51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
st.image(result_img, use_container_width=True)
|
| 54 |
|
| 55 |
st.markdown("---")
|
| 56 |
|
| 57 |
# =================================================
|
| 58 |
-
# METRICS
|
| 59 |
# =================================================
|
| 60 |
m1, m2, m3 = st.columns(3)
|
| 61 |
-
|
| 62 |
m1.metric("Sequential", f"{metrics['sequential_time']:.4f}s")
|
| 63 |
m2.metric("Parallel", f"{metrics['parallel_time']:.4f}s")
|
| 64 |
m3.metric("Speedup", f"{metrics['speedup']:.2f}x")
|
|
@@ -74,13 +78,13 @@ def main():
|
|
| 74 |
st.plotly_chart(fig, use_container_width=True)
|
| 75 |
|
| 76 |
# =================================================
|
| 77 |
-
# DOWNLOAD
|
| 78 |
# =================================================
|
| 79 |
result_pil = Image.fromarray(result_img)
|
| 80 |
|
| 81 |
buf = io.BytesIO()
|
| 82 |
result_pil.save(buf, format="PNG")
|
| 83 |
-
buf.seek(0)
|
| 84 |
|
| 85 |
st.download_button(
|
| 86 |
label="Download Enhanced Image",
|
|
@@ -100,31 +104,33 @@ def main():
|
|
| 100 |
|
| 101 |
if not samples:
|
| 102 |
st.warning("Dataset not found")
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
|
|
|
| 106 |
|
| 107 |
-
|
| 108 |
|
| 109 |
-
|
| 110 |
|
| 111 |
-
|
| 112 |
-
|
| 113 |
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
|
| 124 |
-
|
| 125 |
-
|
|
|
|
| 126 |
|
| 127 |
-
|
| 128 |
|
| 129 |
# =====================================================
|
| 130 |
# WEBCAM MODE
|
|
@@ -144,7 +150,8 @@ def main():
|
|
| 144 |
|
| 145 |
output = result["result"]
|
| 146 |
|
| 147 |
-
#
|
|
|
|
| 148 |
output = np.clip(output, 0, 255).astype(np.uint8)
|
| 149 |
|
| 150 |
st.image(output, use_container_width=True)
|
|
@@ -162,7 +169,7 @@ def main():
|
|
| 162 |
|
| 163 |
|
| 164 |
# ---------------------------------------------------------
|
| 165 |
-
# RUN
|
| 166 |
# ---------------------------------------------------------
|
| 167 |
if __name__ == "__main__":
|
| 168 |
main()
|
|
|
|
| 1 |
import os
|
| 2 |
import io
|
|
|
|
|
|
|
| 3 |
import tensorflow as tf
|
| 4 |
import cv2
|
| 5 |
import multiprocessing
|
| 6 |
import threading
|
| 7 |
+
import numpy as np
|
| 8 |
+
import streamlit as st
|
| 9 |
import plotly.graph_objects as go
|
| 10 |
from PIL import Image
|
| 11 |
|
|
|
|
| 31 |
|
| 32 |
if uploaded_file is not None:
|
| 33 |
|
| 34 |
+
# ---------- SAFE IMAGE LOAD ----------
|
| 35 |
image = Image.open(uploaded_file).convert("RGB")
|
| 36 |
image_np = np.array(image)
|
| 37 |
|
| 38 |
+
# ---------- RUN PIPELINE ----------
|
| 39 |
metrics = run_image_enhancement(image_np)
|
| 40 |
|
| 41 |
col1, col2 = st.columns(2)
|
|
|
|
| 47 |
with col2:
|
| 48 |
st.subheader(f"Enhanced ({mode})")
|
| 49 |
|
| 50 |
+
# ---------- CRITICAL FIX: SAFE OUTPUT ----------
|
| 51 |
result_img = metrics["result"]
|
| 52 |
+
|
| 53 |
+
if isinstance(result_img, np.ndarray):
|
| 54 |
+
result_img = np.nan_to_num(result_img) # remove NaNs/Infs
|
| 55 |
+
result_img = np.clip(result_img, 0, 255)
|
| 56 |
+
result_img = result_img.astype(np.uint8)
|
| 57 |
|
| 58 |
st.image(result_img, use_container_width=True)
|
| 59 |
|
| 60 |
st.markdown("---")
|
| 61 |
|
| 62 |
# =================================================
|
| 63 |
+
# METRICS
|
| 64 |
# =================================================
|
| 65 |
m1, m2, m3 = st.columns(3)
|
|
|
|
| 66 |
m1.metric("Sequential", f"{metrics['sequential_time']:.4f}s")
|
| 67 |
m2.metric("Parallel", f"{metrics['parallel_time']:.4f}s")
|
| 68 |
m3.metric("Speedup", f"{metrics['speedup']:.2f}x")
|
|
|
|
| 78 |
st.plotly_chart(fig, use_container_width=True)
|
| 79 |
|
| 80 |
# =================================================
|
| 81 |
+
# DOWNLOAD
|
| 82 |
# =================================================
|
| 83 |
result_pil = Image.fromarray(result_img)
|
| 84 |
|
| 85 |
buf = io.BytesIO()
|
| 86 |
result_pil.save(buf, format="PNG")
|
| 87 |
+
buf.seek(0)
|
| 88 |
|
| 89 |
st.download_button(
|
| 90 |
label="Download Enhanced Image",
|
|
|
|
| 104 |
|
| 105 |
if not samples:
|
| 106 |
st.warning("Dataset not found")
|
| 107 |
+
return
|
| 108 |
+
|
| 109 |
+
selected = st.selectbox("Select Sample", [s['name'] for s in samples])
|
| 110 |
+
sample = next(s for s in samples if s['name'] == selected)
|
| 111 |
|
| 112 |
+
low, high = load_lol_pair(sample)
|
| 113 |
|
| 114 |
+
col1, col2, col3 = st.columns(3)
|
| 115 |
|
| 116 |
+
col1.image(low, caption="Low", use_container_width=True)
|
| 117 |
+
col2.image(high, caption="Ground Truth", use_container_width=True)
|
| 118 |
|
| 119 |
+
enhanced = enhancement_pipeline(low, {
|
| 120 |
+
"gamma_enable": True,
|
| 121 |
+
"gamma": gamma_val,
|
| 122 |
+
"clahe_enable": True,
|
| 123 |
+
"clahe_clip": clahe_clip,
|
| 124 |
+
"denoise_enable": True,
|
| 125 |
+
"denoise_h": denoise_h,
|
| 126 |
+
"sharpen_enable": True
|
| 127 |
+
})
|
| 128 |
|
| 129 |
+
# ---------- CRITICAL FIX ----------
|
| 130 |
+
enhanced = np.nan_to_num(enhanced)
|
| 131 |
+
enhanced = np.clip(enhanced, 0, 255).astype(np.uint8)
|
| 132 |
|
| 133 |
+
col3.image(enhanced, caption="Enhanced", use_container_width=True)
|
| 134 |
|
| 135 |
# =====================================================
|
| 136 |
# WEBCAM MODE
|
|
|
|
| 150 |
|
| 151 |
output = result["result"]
|
| 152 |
|
| 153 |
+
# ---------- FIX ----------
|
| 154 |
+
output = np.nan_to_num(output)
|
| 155 |
output = np.clip(output, 0, 255).astype(np.uint8)
|
| 156 |
|
| 157 |
st.image(output, use_container_width=True)
|
|
|
|
| 169 |
|
| 170 |
|
| 171 |
# ---------------------------------------------------------
|
| 172 |
+
# RUN
|
| 173 |
# ---------------------------------------------------------
|
| 174 |
if __name__ == "__main__":
|
| 175 |
main()
|