Update app.py
Browse files
app.py
CHANGED
@@ -493,7 +493,7 @@ def quick_predict_ui(image_pil):
|
|
493 |
return (
|
494 |
'<div class="diagnostic-global"><h2>Veuillez uploader une image.</h2></div>',
|
495 |
"", # output_text vide
|
496 |
-
|
497 |
None, # output_plot
|
498 |
"❌ Erreur: Aucune image fournie."
|
499 |
)
|
@@ -514,7 +514,7 @@ def quick_predict_ui(image_pil):
|
|
514 |
# Description
|
515 |
desc_top = description.get(top_class_name, "")
|
516 |
|
517 |
-
# HTML pour le diagnostic global
|
518 |
if global_diag == "Malin":
|
519 |
global_diag_html = f'''
|
520 |
<div class="diagnostic-global clearfix">
|
@@ -541,10 +541,10 @@ def quick_predict_ui(image_pil):
|
|
541 |
</div>
|
542 |
'''
|
543 |
|
544 |
-
# Contenu pour output_text
|
545 |
output_text_html = f'<div class="feedback-text">{desc_top}</div>'
|
546 |
|
547 |
-
# Contenu pour output_warning
|
548 |
warning_visible = False
|
549 |
warning_html = ""
|
550 |
if mel_prob > 5 and top_class_name != "mel":
|
@@ -556,7 +556,7 @@ def quick_predict_ui(image_pil):
|
|
556 |
'''
|
557 |
warning_visible = True
|
558 |
|
559 |
-
# Génération du graphique
|
560 |
df = pd.DataFrame.from_dict(
|
561 |
{CLASS_NAMES[i]: float(ensemble_probs[i]*100) for i in range(len(CLASS_NAMES))},
|
562 |
orient='index', columns=['Probabilité']
|
@@ -564,15 +564,15 @@ def quick_predict_ui(image_pil):
|
|
564 |
df = df.sort_values(by='Probabilité', ascending=False)
|
565 |
df['Pourcentage'] = df['Probabilité'].apply(lambda x: f"{x:.1f}%")
|
566 |
fig = px.bar(df, x="Classe", y="Probabilité", color="Probabilité",
|
567 |
-
|
568 |
-
|
569 |
fig.update_traces(textposition="outside" if df['Probabilité'].max() < 15 else "inside")
|
570 |
fig.update_layout(xaxis_title="", yaxis_title="Probabilité (%)", height=350)
|
571 |
|
572 |
return (
|
573 |
global_diag_html,
|
574 |
output_text_html,
|
575 |
-
gr.
|
576 |
fig,
|
577 |
"✅ Analyse terminée."
|
578 |
)
|
@@ -581,7 +581,7 @@ def quick_predict_ui(image_pil):
|
|
581 |
return (
|
582 |
f'<div class="diagnostic-global"><h2>Erreur: {str(e)}</h2></div>',
|
583 |
"",
|
584 |
-
gr.
|
585 |
<div class="warning-message" style="background-color:#ffebee;border:1px solid #ef9a9a;">
|
586 |
❌ Une erreur est survenue : {str(e)}
|
587 |
</div>
|
|
|
493 |
return (
|
494 |
'<div class="diagnostic-global"><h2>Veuillez uploader une image.</h2></div>',
|
495 |
"", # output_text vide
|
496 |
+
gr.update(value="", visible=False), # output_warning masqué
|
497 |
None, # output_plot
|
498 |
"❌ Erreur: Aucune image fournie."
|
499 |
)
|
|
|
514 |
# Description
|
515 |
desc_top = description.get(top_class_name, "")
|
516 |
|
517 |
+
# HTML pour le diagnostic global
|
518 |
if global_diag == "Malin":
|
519 |
global_diag_html = f'''
|
520 |
<div class="diagnostic-global clearfix">
|
|
|
541 |
</div>
|
542 |
'''
|
543 |
|
544 |
+
# Contenu pour output_text
|
545 |
output_text_html = f'<div class="feedback-text">{desc_top}</div>'
|
546 |
|
547 |
+
# Contenu pour output_warning
|
548 |
warning_visible = False
|
549 |
warning_html = ""
|
550 |
if mel_prob > 5 and top_class_name != "mel":
|
|
|
556 |
'''
|
557 |
warning_visible = True
|
558 |
|
559 |
+
# Génération du graphique
|
560 |
df = pd.DataFrame.from_dict(
|
561 |
{CLASS_NAMES[i]: float(ensemble_probs[i]*100) for i in range(len(CLASS_NAMES))},
|
562 |
orient='index', columns=['Probabilité']
|
|
|
564 |
df = df.sort_values(by='Probabilité', ascending=False)
|
565 |
df['Pourcentage'] = df['Probabilité'].apply(lambda x: f"{x:.1f}%")
|
566 |
fig = px.bar(df, x="Classe", y="Probabilité", color="Probabilité",
|
567 |
+
color_continuous_scale=px.colors.sequential.Viridis,
|
568 |
+
title="Probabilités par classe", text="Pourcentage")
|
569 |
fig.update_traces(textposition="outside" if df['Probabilité'].max() < 15 else "inside")
|
570 |
fig.update_layout(xaxis_title="", yaxis_title="Probabilité (%)", height=350)
|
571 |
|
572 |
return (
|
573 |
global_diag_html,
|
574 |
output_text_html,
|
575 |
+
gr.update(value=warning_html, visible=warning_visible), # Mise à jour dynamique
|
576 |
fig,
|
577 |
"✅ Analyse terminée."
|
578 |
)
|
|
|
581 |
return (
|
582 |
f'<div class="diagnostic-global"><h2>Erreur: {str(e)}</h2></div>',
|
583 |
"",
|
584 |
+
gr.update(value=f'''
|
585 |
<div class="warning-message" style="background-color:#ffebee;border:1px solid #ef9a9a;">
|
586 |
❌ Une erreur est survenue : {str(e)}
|
587 |
</div>
|