ericjedha commited on
Commit
e6a523f
·
verified ·
1 Parent(s): 51bbd1e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -1
app.py CHANGED
@@ -197,6 +197,39 @@ def _update_progress(progress, value, desc=""):
197
  if progress is not None:
198
  progress(value / 100.0, desc=desc)
199
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
200
  # ---- PREDICT SINGLE ----
201
  def predict_single(img_input, weights=(0.45, 0.25, 0.3), normalize=True):
202
  print("🔍 DEBUG GRADIO HARMONISÉ - Début de la prédiction")
@@ -614,7 +647,8 @@ def quick_predict_ui(image_pil):
614
  output_text_html,
615
  gr.update(value=warning_html, visible=warning_visible),
616
  fig, # Retourner la figure Plotly
617
- "✅ Analyse terminée."
 
618
  )
619
 
620
  except Exception as e:
@@ -741,6 +775,11 @@ with gr.Blocks(theme=theme, title="Analyse de lésions", css=css) as demo:
741
 
742
  # Configuration correcte du BarPlot
743
  output_plot = gr.Plot(label="Probabilités par classe")
 
 
 
 
 
744
 
745
  gr.Markdown(f"Ensemble de modèles utilisés : {', '.join(models_status) if models_status else 'AUCUN'}")
746
  gr.HTML(value="""
 
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="microsoft/BiomedNLP-PubMedBERT-base-uncased-abstract"
207
+ )
208
+
209
+ def dermato_second_opinion_text(top_class, probs_dict):
210
+ """
211
+ Génère un avis médical secondaire à partir du diagnostic et des probabilités.
212
+ """
213
+ text_input = (
214
+ f"Diagnostic automatique : {top_class}. "
215
+ f"Probabilités associées : " +
216
+ ", ".join([f"{cls} {p:.1f}%" for cls, p in probs_dict.items()]) + ". "
217
+ "Fournis un avis médical bref sur le caractère bénin ou malin."
218
+ )
219
+
220
+ try:
221
+ result = med_nlp(text_input, truncation=True)
222
+ return f"""
223
+ <div class='dermato-opinion' style="margin-top:15px;padding:10px;border:1px solid #ccc;border-radius:10px;background:#f9f9f9;">
224
+ <h4>🩺 Avis médical automatisé</h4>
225
+ <p><b>Label :</b> {result[0]['label']} (score {result[0]['score']:.2f})</p>
226
+ <p><i>Ceci est une interprétation automatique et ne remplace pas l’avis d’un dermatologue.</i></p>
227
+ </div>
228
+ """
229
+ except Exception as e:
230
+ return f"<div class='dermato-opinion'><b>Erreur :</b> {str(e)}</div>"
231
+ # ---- Fin Bert Medical ----
232
+
233
  # ---- PREDICT SINGLE ----
234
  def predict_single(img_input, weights=(0.45, 0.25, 0.3), normalize=True):
235
  print("🔍 DEBUG GRADIO HARMONISÉ - Début de la prédiction")
 
647
  output_text_html,
648
  gr.update(value=warning_html, visible=warning_visible),
649
  fig, # Retourner la figure Plotly
650
+ "✅ Analyse terminée.",
651
+ dermato_html
652
  )
653
 
654
  except Exception as e:
 
775
 
776
  # Configuration correcte du BarPlot
777
  output_plot = gr.Plot(label="Probabilités par classe")
778
+ # 👉 Nouvelle boîte d'avis médical
779
+ output_opinion = gr.HTML(
780
+ value="",
781
+ elem_classes="dermato-opinion"
782
+ )
783
 
784
  gr.Markdown(f"Ensemble de modèles utilisés : {', '.join(models_status) if models_status else 'AUCUN'}")
785
  gr.HTML(value="""