Update app.py
Browse files
app.py
CHANGED
|
@@ -8,6 +8,7 @@ from skimage.segmentation import mark_boundaries
|
|
| 8 |
from keras.layers import BatchNormalization, DepthwiseConv2D, TFSMLayer
|
| 9 |
import os
|
| 10 |
from io import BytesIO
|
|
|
|
| 11 |
|
| 12 |
# --- Fix deserialization issues ---
|
| 13 |
original_bn = BatchNormalization.from_config
|
|
@@ -21,6 +22,30 @@ DepthwiseConv2D.from_config = classmethod(
|
|
| 21 |
lambda cls, config, *a, **k: original_dw({k: v for k, v in config.items() if k != "groups"}, *a, **k)
|
| 22 |
)
|
| 23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
# --- Constants ---
|
| 25 |
IMG_SIZE = (224, 224)
|
| 26 |
CLASS_NAMES = [
|
|
@@ -154,10 +179,8 @@ def show_lime(img, model, pred_idx, pred_label, all_probs):
|
|
| 154 |
|
| 155 |
col1, col2 = st.columns([1, 1])
|
| 156 |
with col1:
|
| 157 |
-
# π Compact image display with fixed pixel width
|
| 158 |
st.image(lime_img, caption="π LIME Focus", width=200)
|
| 159 |
|
| 160 |
-
# πΎ Download LIME image
|
| 161 |
buf = BytesIO()
|
| 162 |
plt.imsave(buf, lime_img, format="png")
|
| 163 |
buf.seek(0)
|
|
@@ -165,10 +188,7 @@ def show_lime(img, model, pred_idx, pred_label, all_probs):
|
|
| 165 |
|
| 166 |
with col2:
|
| 167 |
st.markdown("### π§ Model's Reasoning")
|
| 168 |
-
st.markdown(explanation_text.get(pred_label,
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
|
| 173 |
# --- UI ---
|
| 174 |
st.set_page_config(page_title="π Retina Classifier with LIME", layout="wide")
|
|
|
|
| 8 |
from keras.layers import BatchNormalization, DepthwiseConv2D, TFSMLayer
|
| 9 |
import os
|
| 10 |
from io import BytesIO
|
| 11 |
+
import base64
|
| 12 |
|
| 13 |
# --- Fix deserialization issues ---
|
| 14 |
original_bn = BatchNormalization.from_config
|
|
|
|
| 22 |
lambda cls, config, *a, **k: original_dw({k: v for k, v in config.items() if k != "groups"}, *a, **k)
|
| 23 |
)
|
| 24 |
|
| 25 |
+
# --- Background Setup ---
|
| 26 |
+
def set_background(image_path):
|
| 27 |
+
with open(image_path, "rb") as f:
|
| 28 |
+
encoded = base64.b64encode(f.read()).decode()
|
| 29 |
+
st.markdown(f"""
|
| 30 |
+
<style>
|
| 31 |
+
.stApp {{
|
| 32 |
+
background-image: url("data:image/jpg;base64,{encoded}");
|
| 33 |
+
background-size: cover;
|
| 34 |
+
background-attachment: fixed;
|
| 35 |
+
}}
|
| 36 |
+
.overlay {{
|
| 37 |
+
background-color: rgba(255, 255, 255, 0.80); /* light semi-transparent */
|
| 38 |
+
padding: 1.5rem;
|
| 39 |
+
border-radius: 10px;
|
| 40 |
+
}}
|
| 41 |
+
h1, h2, h3, h4, h5, h6, .stMarkdown p {{
|
| 42 |
+
color: #000000 !important;
|
| 43 |
+
}}
|
| 44 |
+
</style>
|
| 45 |
+
""", unsafe_allow_html=True)
|
| 46 |
+
|
| 47 |
+
set_background("background.jpg")
|
| 48 |
+
|
| 49 |
# --- Constants ---
|
| 50 |
IMG_SIZE = (224, 224)
|
| 51 |
CLASS_NAMES = [
|
|
|
|
| 179 |
|
| 180 |
col1, col2 = st.columns([1, 1])
|
| 181 |
with col1:
|
|
|
|
| 182 |
st.image(lime_img, caption="π LIME Focus", width=200)
|
| 183 |
|
|
|
|
| 184 |
buf = BytesIO()
|
| 185 |
plt.imsave(buf, lime_img, format="png")
|
| 186 |
buf.seek(0)
|
|
|
|
| 188 |
|
| 189 |
with col2:
|
| 190 |
st.markdown("### π§ Model's Reasoning")
|
| 191 |
+
st.markdown(f"<div class='overlay'>{explanation_text.get(pred_label, 'No explanation available.')}</div>", unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
| 192 |
|
| 193 |
# --- UI ---
|
| 194 |
st.set_page_config(page_title="π Retina Classifier with LIME", layout="wide")
|