Update app.py
Browse files
app.py
CHANGED
@@ -6,6 +6,7 @@ import tensorflow as tf
|
|
6 |
import keras
|
7 |
from keras.models import Model
|
8 |
from keras.preprocessing import image
|
|
|
9 |
from huggingface_hub import hf_hub_download
|
10 |
import pandas as pd
|
11 |
from PIL import Image
|
@@ -162,18 +163,20 @@ from tensorflow.keras.preprocessing import image
|
|
162 |
from tensorflow.keras.preprocessing import image
|
163 |
import numpy as np
|
164 |
|
|
|
|
|
|
|
165 |
def predict_single(img_input, weights=(0.45, 0.25, 0.3), normalize=True):
|
166 |
print("🔍 DEBUG GRADIO - Début de la prédiction")
|
167 |
|
168 |
# Chargement et pré-traitement avec Keras (comme en local)
|
169 |
if isinstance(img_input, str):
|
170 |
-
# Chargement depuis un chemin
|
171 |
img_path = img_input
|
172 |
img_raw_x = image.load_img(img_path, target_size=(299, 299))
|
173 |
img_raw_r = image.load_img(img_path, target_size=(224, 224))
|
174 |
img_raw_d = image.load_img(img_path, target_size=(224, 224))
|
175 |
else:
|
176 |
-
# Cas d'upload via interface Gradio
|
177 |
temp_path = "temp_debug_image.jpg"
|
178 |
img_input.save(temp_path)
|
179 |
img_raw_x = image.load_img(temp_path, target_size=(299, 299))
|
@@ -182,10 +185,10 @@ def predict_single(img_input, weights=(0.45, 0.25, 0.3), normalize=True):
|
|
182 |
import os
|
183 |
os.remove(temp_path)
|
184 |
|
185 |
-
# Conversion en arrays
|
186 |
-
array_x = image.img_to_array(img_raw_x)
|
187 |
-
array_r = image.img_to_array(img_raw_r)
|
188 |
-
array_d = image.img_to_array(img_raw_d)
|
189 |
|
190 |
print(f"📸 Images loaded:")
|
191 |
print(f" Xception (299x299): {array_x.shape}")
|
@@ -265,8 +268,6 @@ def predict_single(img_input, weights=(0.45, 0.25, 0.3), normalize=True):
|
|
265 |
return preds
|
266 |
|
267 |
|
268 |
-
|
269 |
-
|
270 |
# ---- Helpers Grad-CAM ----
|
271 |
LAST_CONV_LAYERS = {
|
272 |
"xception": "block14_sepconv2_act",
|
@@ -536,7 +537,7 @@ with gr.Blocks(theme=theme, title="Analyse de lésions", css=css) as demo:
|
|
536 |
if model_resnet50: models_status.append("☑ ResNet50")
|
537 |
if model_densenet: models_status.append("☑ DenseNet201")
|
538 |
if model_xcept: models_status.append("☑ Xception")
|
539 |
-
gr.Markdown(f"**Avertissement
|
540 |
gr.Markdown(f"Ensemble de modèles utilisés : {', '.join(models_status) if models_status else 'AUCUN'}")
|
541 |
|
542 |
with gr.Row():
|
|
|
6 |
import keras
|
7 |
from keras.models import Model
|
8 |
from keras.preprocessing import image
|
9 |
+
from tensorflow.keras.preprocessing import image
|
10 |
from huggingface_hub import hf_hub_download
|
11 |
import pandas as pd
|
12 |
from PIL import Image
|
|
|
163 |
from tensorflow.keras.preprocessing import image
|
164 |
import numpy as np
|
165 |
|
166 |
+
from tensorflow.keras.preprocessing import image
|
167 |
+
import numpy as np
|
168 |
+
|
169 |
def predict_single(img_input, weights=(0.45, 0.25, 0.3), normalize=True):
|
170 |
print("🔍 DEBUG GRADIO - Début de la prédiction")
|
171 |
|
172 |
# Chargement et pré-traitement avec Keras (comme en local)
|
173 |
if isinstance(img_input, str):
|
|
|
174 |
img_path = img_input
|
175 |
img_raw_x = image.load_img(img_path, target_size=(299, 299))
|
176 |
img_raw_r = image.load_img(img_path, target_size=(224, 224))
|
177 |
img_raw_d = image.load_img(img_path, target_size=(224, 224))
|
178 |
else:
|
179 |
+
# Cas d'upload via interface Gradio
|
180 |
temp_path = "temp_debug_image.jpg"
|
181 |
img_input.save(temp_path)
|
182 |
img_raw_x = image.load_img(temp_path, target_size=(299, 299))
|
|
|
185 |
import os
|
186 |
os.remove(temp_path)
|
187 |
|
188 |
+
# Conversion en arrays (sans forcer float32)
|
189 |
+
array_x = image.img_to_array(img_raw_x)
|
190 |
+
array_r = image.img_to_array(img_raw_r)
|
191 |
+
array_d = image.img_to_array(img_raw_d)
|
192 |
|
193 |
print(f"📸 Images loaded:")
|
194 |
print(f" Xception (299x299): {array_x.shape}")
|
|
|
268 |
return preds
|
269 |
|
270 |
|
|
|
|
|
271 |
# ---- Helpers Grad-CAM ----
|
272 |
LAST_CONV_LAYERS = {
|
273 |
"xception": "block14_sepconv2_act",
|
|
|
537 |
if model_resnet50: models_status.append("☑ ResNet50")
|
538 |
if model_densenet: models_status.append("☑ DenseNet201")
|
539 |
if model_xcept: models_status.append("☑ Xception")
|
540 |
+
gr.Markdown(f"**Avertissement 🚨 ** cette application est un projet d'étudiant et ne doit être utilisé qu'à titre informatif. Seul votre médecin est habilité à vous donner un diagnostic.")
|
541 |
gr.Markdown(f"Ensemble de modèles utilisés : {', '.join(models_status) if models_status else 'AUCUN'}")
|
542 |
|
543 |
with gr.Row():
|