Sefat33 commited on
Commit
5839dfa
·
verified ·
1 Parent(s): 42534cf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -26
app.py CHANGED
@@ -104,32 +104,31 @@ explanation_text = {
104
  'Others': "Non-specific features detected, marked as Others."
105
  }
106
 
107
- # --- Display LIME only (Grad-CAM not possible with TFSMLayer) ---
108
  def display_lime_visualization(img, true_label, pred_label, pred_idx):
109
- st.info("⚠️ Grad-CAM is disabled because the model is loaded as a TFSMLayer (inference-only).")
110
-
111
- explanation = explainer.explain_instance(
112
- image=img,
113
- classifier_fn=predict_fn,
114
- top_labels=1,
115
- hide_color=0,
116
- num_samples=1000
117
- )
118
- temp, mask = explanation.get_image_and_mask(label=pred_idx, positive_only=True, num_features=10, hide_rest=False)
119
-
120
- fig, axs = plt.subplots(1, 2, figsize=(12, 5))
121
- axs[0].imshow(img)
122
- axs[0].set_title(f"Original\nTrue: {true_label}")
123
- axs[1].imshow(mark_boundaries(temp, mask))
124
- axs[1].set_title(f"LIME Explanation\nPred: {pred_label}")
125
- for ax in axs:
126
- ax.axis('off')
127
-
128
- summary = explanation_text.get(pred_label, "Model detected features matching this class.")
129
- plt.figtext(0.5, 0.01, summary, wrap=True, ha='center', fontsize=10)
130
- plt.tight_layout(rect=[0, 0.03, 1, 1])
131
- st.pyplot(fig)
132
- plt.close()
133
 
134
  # --- Streamlit UI ---
135
  st.set_page_config(page_title="🧠 Retina Disease Classifier with LIME", layout="centered")
@@ -153,6 +152,6 @@ if uploaded_file:
153
  pred_label = CLASS_NAMES[pred_idx]
154
  confidence = np.max(preds) * 100
155
 
156
- st.success(f"Prediction: **{pred_label}** with confidence {confidence:.2f}%")
157
 
158
  display_lime_visualization(processed_img, "Uploaded Image", pred_label, pred_idx)
 
104
  'Others': "Non-specific features detected, marked as Others."
105
  }
106
 
107
+ # --- Display LIME only ---
108
  def display_lime_visualization(img, true_label, pred_label, pred_idx):
109
+ with st.spinner("🟡 LIME Explanation is Loading..."):
110
+ explanation = explainer.explain_instance(
111
+ image=img,
112
+ classifier_fn=predict_fn,
113
+ top_labels=1,
114
+ hide_color=0,
115
+ num_samples=1000
116
+ )
117
+ temp, mask = explanation.get_image_and_mask(label=pred_idx, positive_only=True, num_features=10, hide_rest=False)
118
+
119
+ fig, axs = plt.subplots(1, 2, figsize=(12, 5))
120
+ axs[0].imshow(img)
121
+ axs[0].set_title(f"Original\nTrue: {true_label}")
122
+ axs[1].imshow(mark_boundaries(temp, mask))
123
+ axs[1].set_title(f"LIME Explanation\nPred: {pred_label}")
124
+ for ax in axs:
125
+ ax.axis('off')
126
+
127
+ summary = explanation_text.get(pred_label, "Model detected features matching this class.")
128
+ plt.figtext(0.5, 0.01, summary, wrap=True, ha='center', fontsize=10)
129
+ plt.tight_layout(rect=[0, 0.03, 1, 1])
130
+ st.pyplot(fig)
131
+ plt.close()
 
132
 
133
  # --- Streamlit UI ---
134
  st.set_page_config(page_title="🧠 Retina Disease Classifier with LIME", layout="centered")
 
152
  pred_label = CLASS_NAMES[pred_idx]
153
  confidence = np.max(preds) * 100
154
 
155
+ st.success(f"Prediction: **{pred_label}** with confidence **{confidence:.2f}%**")
156
 
157
  display_lime_visualization(processed_img, "Uploaded Image", pred_label, pred_idx)