Update app.py
Browse files
app.py
CHANGED
@@ -100,23 +100,27 @@ def make_gradcam(img_path, model, last_conv_layer_name="conv5_block32_concat", c
|
|
100 |
|
101 |
# ---- Fonction Gradio ----
|
102 |
def gradio_predict(image_file):
|
|
|
103 |
probs = predict_single(image_file)
|
104 |
|
105 |
-
|
106 |
-
sorted_labels = [CLASS_NAMES[i].upper() for i in sorted_idx]
|
107 |
-
sorted_probs = probs[sorted_idx] * 100
|
108 |
-
|
109 |
benign_prob = sum(probs[i] for i, cls in enumerate(CLASS_NAMES) if diagnosis_map[cls] == "Bénin")
|
110 |
malign_prob = sum(probs[i] for i, cls in enumerate(CLASS_NAMES) if diagnosis_map[cls] == "Malin")
|
111 |
global_diag = "Bénin" if benign_prob >= malign_prob else "Malin"
|
112 |
|
113 |
-
|
|
|
|
|
|
|
|
|
114 |
|
115 |
-
# Grad-CAM
|
116 |
top_class = np.argmax(probs)
|
117 |
gradcam_img = make_gradcam(image_file, model_densenet, class_index=top_class)
|
118 |
|
119 |
-
|
|
|
|
|
120 |
|
121 |
# ---- Gradio UI ----
|
122 |
examples = [
|
|
|
100 |
|
101 |
# ---- Fonction Gradio ----
|
102 |
def gradio_predict(image_file):
|
103 |
+
# Prédiction
|
104 |
probs = predict_single(image_file)
|
105 |
|
106 |
+
# Classe globale
|
|
|
|
|
|
|
107 |
benign_prob = sum(probs[i] for i, cls in enumerate(CLASS_NAMES) if diagnosis_map[cls] == "Bénin")
|
108 |
malign_prob = sum(probs[i] for i, cls in enumerate(CLASS_NAMES) if diagnosis_map[cls] == "Malin")
|
109 |
global_diag = "Bénin" if benign_prob >= malign_prob else "Malin"
|
110 |
|
111 |
+
# BarPlot
|
112 |
+
sorted_idx = np.argsort(-probs)
|
113 |
+
sorted_labels = [CLASS_NAMES[i].upper() for i in sorted_idx]
|
114 |
+
sorted_probs = (probs[sorted_idx] * 100).tolist()
|
115 |
+
bar_data = {"Classes": sorted_labels, "Probabilité (%)": sorted_probs}
|
116 |
|
117 |
+
# Grad-CAM
|
118 |
top_class = np.argmax(probs)
|
119 |
gradcam_img = make_gradcam(image_file, model_densenet, class_index=top_class)
|
120 |
|
121 |
+
# ✅ Retour exact attendu par Gradio
|
122 |
+
return global_diag, bar_data, gradcam_img
|
123 |
+
|
124 |
|
125 |
# ---- Gradio UI ----
|
126 |
examples = [
|