Update app.py
Browse files
app.py
CHANGED
@@ -27,12 +27,10 @@ css = """
|
|
27 |
body {
|
28 |
font-family: Arial, sans-serif !important;
|
29 |
}
|
30 |
-
|
31 |
/* Conteneur du diagnostic global */
|
32 |
.diagnostic-global {
|
33 |
padding: 10px;
|
34 |
}
|
35 |
-
|
36 |
/* Style pour les badges Malin/Bénin */
|
37 |
.highlight.malin {
|
38 |
background-color: #F54927;
|
@@ -44,7 +42,6 @@ body {
|
|
44 |
font-size:24px;
|
45 |
margin: 5px 0;
|
46 |
}
|
47 |
-
|
48 |
.highlight.benin {
|
49 |
background-color: #34EA3A;
|
50 |
color: black;
|
@@ -55,7 +52,6 @@ body {
|
|
55 |
font-size:24px;
|
56 |
margin: 5px 0;
|
57 |
}
|
58 |
-
|
59 |
/* Conteneur pour le warning */
|
60 |
.warning-container {
|
61 |
background-color: #f9f9f9;
|
@@ -64,7 +60,6 @@ body {
|
|
64 |
margin-bottom: 0px;
|
65 |
border: 1px solid #e0e0e0;
|
66 |
}
|
67 |
-
|
68 |
/* Message d'avertissement */
|
69 |
.warning-message {
|
70 |
background-color: #e9d5ff;
|
@@ -75,8 +70,6 @@ body {
|
|
75 |
color: #333;
|
76 |
font-family: Arial, sans-serif !important;
|
77 |
}
|
78 |
-
|
79 |
-
|
80 |
/* Pour les images dans le diagnostic */
|
81 |
.diagnostic-global img {
|
82 |
max-width: 100%;
|
@@ -85,7 +78,6 @@ body {
|
|
85 |
margin-right: 10px;
|
86 |
margin-bottom: 10px;
|
87 |
}
|
88 |
-
|
89 |
.feedback-container {
|
90 |
background-color: #f9f9f9;
|
91 |
border-radius: 5px;
|
@@ -95,7 +87,6 @@ body {
|
|
95 |
font-size:16px;
|
96 |
font-family: Arial, sans-serif !important;
|
97 |
}
|
98 |
-
|
99 |
/* Clearfix pour les flottants */
|
100 |
.clearfix::after {
|
101 |
content: "";
|
@@ -197,40 +188,6 @@ def _update_progress(progress, value, desc=""):
|
|
197 |
if progress is not None:
|
198 |
progress(value / 100.0, desc=desc)
|
199 |
|
200 |
-
# ---- Bert Medical ----
|
201 |
-
from transformers import pipeline
|
202 |
-
|
203 |
-
# Chargement du modèle Hugging Face léger pour interprétation médicale
|
204 |
-
med_nlp = pipeline(
|
205 |
-
"text-classification",
|
206 |
-
model="d4data/biomedical-bert-mini",
|
207 |
-
framework="pt" # <-- on force PyTorch
|
208 |
-
)
|
209 |
-
|
210 |
-
def dermato_second_opinion_text(top_class, probs_dict):
|
211 |
-
"""
|
212 |
-
Génère un avis médical secondaire à partir du diagnostic et des probabilités.
|
213 |
-
"""
|
214 |
-
text_input = (
|
215 |
-
f"Diagnostic automatique : {top_class}. "
|
216 |
-
f"Probabilités associées : " +
|
217 |
-
", ".join([f"{cls} {p:.1f}%" for cls, p in probs_dict.items()]) + ". "
|
218 |
-
"Fournis un avis médical bref sur le caractère bénin ou malin."
|
219 |
-
)
|
220 |
-
|
221 |
-
try:
|
222 |
-
result = med_nlp(text_input, truncation=True)
|
223 |
-
return f"""
|
224 |
-
<div class='dermato-opinion' style="margin-top:15px;padding:10px;border:1px solid #ccc;border-radius:10px;background:#f9f9f9;">
|
225 |
-
<h4>🩺 Avis médical automatisé</h4>
|
226 |
-
<p><b>Label :</b> {result[0]['label']} (score {result[0]['score']:.2f})</p>
|
227 |
-
<p><i>Ceci est une interprétation automatique et ne remplace pas l’avis d’un dermatologue.</i></p>
|
228 |
-
</div>
|
229 |
-
"""
|
230 |
-
except Exception as e:
|
231 |
-
return f"<div class='dermato-opinion'><b>Erreur :</b> {str(e)}</div>"
|
232 |
-
# ---- Fin Bert Medical ----
|
233 |
-
|
234 |
# ---- PREDICT SINGLE ----
|
235 |
def predict_single(img_input, weights=(0.45, 0.25, 0.3), normalize=True):
|
236 |
print("🔍 DEBUG GRADIO HARMONISÉ - Début de la prédiction")
|
@@ -648,8 +605,7 @@ def quick_predict_ui(image_pil):
|
|
648 |
output_text_html,
|
649 |
gr.update(value=warning_html, visible=warning_visible),
|
650 |
fig, # Retourner la figure Plotly
|
651 |
-
"✅ Analyse terminée."
|
652 |
-
dermato_html
|
653 |
)
|
654 |
|
655 |
except Exception as e:
|
@@ -741,8 +697,8 @@ with gr.Blocks(theme=theme, title="Analyse de lésions", css=css) as demo:
|
|
741 |
input_image = gr.Image(type="pil", label="📸 Uploader une image")
|
742 |
|
743 |
with gr.Row():
|
744 |
-
quick_btn = gr.Button("1️⃣ Analyse
|
745 |
-
gradcam_btn = gr.Button("2️⃣ Carte
|
746 |
|
747 |
gr.Examples(examples=example_paths, inputs=input_image)
|
748 |
output_gradcam = gr.Image(label="🔍 Carte Colorée Grad-CAM")
|
@@ -776,11 +732,6 @@ with gr.Blocks(theme=theme, title="Analyse de lésions", css=css) as demo:
|
|
776 |
|
777 |
# Configuration correcte du BarPlot
|
778 |
output_plot = gr.Plot(label="Probabilités par classe")
|
779 |
-
# 👉 Nouvelle boîte d'avis médical
|
780 |
-
output_opinion = gr.HTML(
|
781 |
-
value="",
|
782 |
-
elem_classes="dermato-opinion"
|
783 |
-
)
|
784 |
|
785 |
gr.Markdown(f"Ensemble de modèles utilisés : {', '.join(models_status) if models_status else 'AUCUN'}")
|
786 |
gr.HTML(value="""
|
@@ -790,7 +741,6 @@ with gr.Blocks(theme=theme, title="Analyse de lésions", css=css) as demo:
|
|
790 |
<br>
|
791 |
<strong> RGPD & Digital Act </strong> :
|
792 |
Ce dataset ne peut pas être utilisé pour des cas réels aujourd'hui notamment du fait qu'il ne comporte qu'essentiellement des peaux de populations européennes (allemands et autrichiens). <br>Cette application ne collecte pas vos données personnelles. <b>Les images uploadées ne sont pas stockées</b>. <br>La politique de Cookies 🍪 est gérée par <a href='https://huggingface.co/privacy'>Hugging Face disponible ici</a>.
|
793 |
-
|
794 |
""")
|
795 |
|
796 |
# Configuration des événements
|
|
|
27 |
body {
|
28 |
font-family: Arial, sans-serif !important;
|
29 |
}
|
|
|
30 |
/* Conteneur du diagnostic global */
|
31 |
.diagnostic-global {
|
32 |
padding: 10px;
|
33 |
}
|
|
|
34 |
/* Style pour les badges Malin/Bénin */
|
35 |
.highlight.malin {
|
36 |
background-color: #F54927;
|
|
|
42 |
font-size:24px;
|
43 |
margin: 5px 0;
|
44 |
}
|
|
|
45 |
.highlight.benin {
|
46 |
background-color: #34EA3A;
|
47 |
color: black;
|
|
|
52 |
font-size:24px;
|
53 |
margin: 5px 0;
|
54 |
}
|
|
|
55 |
/* Conteneur pour le warning */
|
56 |
.warning-container {
|
57 |
background-color: #f9f9f9;
|
|
|
60 |
margin-bottom: 0px;
|
61 |
border: 1px solid #e0e0e0;
|
62 |
}
|
|
|
63 |
/* Message d'avertissement */
|
64 |
.warning-message {
|
65 |
background-color: #e9d5ff;
|
|
|
70 |
color: #333;
|
71 |
font-family: Arial, sans-serif !important;
|
72 |
}
|
|
|
|
|
73 |
/* Pour les images dans le diagnostic */
|
74 |
.diagnostic-global img {
|
75 |
max-width: 100%;
|
|
|
78 |
margin-right: 10px;
|
79 |
margin-bottom: 10px;
|
80 |
}
|
|
|
81 |
.feedback-container {
|
82 |
background-color: #f9f9f9;
|
83 |
border-radius: 5px;
|
|
|
87 |
font-size:16px;
|
88 |
font-family: Arial, sans-serif !important;
|
89 |
}
|
|
|
90 |
/* Clearfix pour les flottants */
|
91 |
.clearfix::after {
|
92 |
content: "";
|
|
|
188 |
if progress is not None:
|
189 |
progress(value / 100.0, desc=desc)
|
190 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
191 |
# ---- PREDICT SINGLE ----
|
192 |
def predict_single(img_input, weights=(0.45, 0.25, 0.3), normalize=True):
|
193 |
print("🔍 DEBUG GRADIO HARMONISÉ - Début de la prédiction")
|
|
|
605 |
output_text_html,
|
606 |
gr.update(value=warning_html, visible=warning_visible),
|
607 |
fig, # Retourner la figure Plotly
|
608 |
+
"✅ Analyse terminée."
|
|
|
609 |
)
|
610 |
|
611 |
except Exception as e:
|
|
|
697 |
input_image = gr.Image(type="pil", label="📸 Uploader une image")
|
698 |
|
699 |
with gr.Row():
|
700 |
+
quick_btn = gr.Button("1️⃣ Analyse Rapide <br> (~ 10s)", variant="primary")
|
701 |
+
gradcam_btn = gr.Button("2️⃣ Carte colorée <br> (~ 60s) ", variant="secondary")
|
702 |
|
703 |
gr.Examples(examples=example_paths, inputs=input_image)
|
704 |
output_gradcam = gr.Image(label="🔍 Carte Colorée Grad-CAM")
|
|
|
732 |
|
733 |
# Configuration correcte du BarPlot
|
734 |
output_plot = gr.Plot(label="Probabilités par classe")
|
|
|
|
|
|
|
|
|
|
|
735 |
|
736 |
gr.Markdown(f"Ensemble de modèles utilisés : {', '.join(models_status) if models_status else 'AUCUN'}")
|
737 |
gr.HTML(value="""
|
|
|
741 |
<br>
|
742 |
<strong> RGPD & Digital Act </strong> :
|
743 |
Ce dataset ne peut pas être utilisé pour des cas réels aujourd'hui notamment du fait qu'il ne comporte qu'essentiellement des peaux de populations européennes (allemands et autrichiens). <br>Cette application ne collecte pas vos données personnelles. <b>Les images uploadées ne sont pas stockées</b>. <br>La politique de Cookies 🍪 est gérée par <a href='https://huggingface.co/privacy'>Hugging Face disponible ici</a>.
|
|
|
744 |
""")
|
745 |
|
746 |
# Configuration des événements
|