Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -11,7 +11,7 @@ model = tf.keras.models.load_model("MobileNetV2_UL_ML_c3_l0_acc88_auc94_20251007
|
|
| 11 |
classes = ["Cubisme", "Expressionnisme", "Post-impressionnisme"]
|
| 12 |
|
| 13 |
# Fonction de prédiction avec graphique personnalisé
|
| 14 |
-
def predire(image):
|
| 15 |
# Prédiction
|
| 16 |
image_resized = tf.image.resize(image, (224, 224)) / 255.0
|
| 17 |
preds = model.predict(tf.expand_dims(image_resized, axis=0))[0]
|
|
@@ -58,8 +58,41 @@ def predire(image):
|
|
| 58 |
|
| 59 |
fig.tight_layout()
|
| 60 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
return fig
|
| 62 |
|
|
|
|
| 63 |
# Interface Gradio
|
| 64 |
demo = gr.Interface(
|
| 65 |
fn=predire,
|
|
|
|
| 11 |
classes = ["Cubisme", "Expressionnisme", "Post-impressionnisme"]
|
| 12 |
|
| 13 |
# Fonction de prédiction avec graphique personnalisé
|
| 14 |
+
"""def predire(image):
|
| 15 |
# Prédiction
|
| 16 |
image_resized = tf.image.resize(image, (224, 224)) / 255.0
|
| 17 |
preds = model.predict(tf.expand_dims(image_resized, axis=0))[0]
|
|
|
|
| 58 |
|
| 59 |
fig.tight_layout()
|
| 60 |
|
| 61 |
+
return fig"""
|
| 62 |
+
|
| 63 |
+
def predire(image):
|
| 64 |
+
image_resized = tf.image.resize(image, (224, 224)) / 255.0
|
| 65 |
+
preds = model.predict(tf.expand_dims(image_resized, axis=0))[0]
|
| 66 |
+
|
| 67 |
+
sorted_indices = np.argsort(preds)[::-1]
|
| 68 |
+
sorted_classes = [classes[i] for i in sorted_indices]
|
| 69 |
+
sorted_probs = [preds[i] for i in sorted_indices]
|
| 70 |
+
colors = ['#2ecc71' if prob >= 0.5 else '#bdc3c7' for prob in sorted_probs]
|
| 71 |
+
|
| 72 |
+
fig = Figure(figsize=(4, 3)) # Format compact adapté mobile
|
| 73 |
+
ax = fig.add_subplot(111)
|
| 74 |
+
|
| 75 |
+
# Barres verticales
|
| 76 |
+
bars = ax.bar(sorted_classes, sorted_probs, color=colors, edgecolor='black', linewidth=1.5)
|
| 77 |
+
|
| 78 |
+
# Ajout pourcentages
|
| 79 |
+
for bar, prob in zip(bars, sorted_probs):
|
| 80 |
+
ax.text(bar.get_x() + bar.get_width()/2, bar.get_height() + 0.03,
|
| 81 |
+
f"{prob*100:.1f}%", ha='center', va='bottom', fontsize=13, fontweight='bold', color='black')
|
| 82 |
+
|
| 83 |
+
ax.set_ylabel('Probabilité', fontsize=15, fontweight='bold')
|
| 84 |
+
ax.set_ylim(0, 1.0)
|
| 85 |
+
ax.set_title('Probabilités par mouvement pictural', fontsize=16, fontweight='bold', pad=20)
|
| 86 |
+
ax.grid(axis='y', alpha=0.15, linestyle='--')
|
| 87 |
+
ax.set_axisbelow(True)
|
| 88 |
+
|
| 89 |
+
# Titres inclinés à 45°
|
| 90 |
+
ax.set_xticklabels(sorted_classes, rotation=45, ha='right', fontsize=15, fontweight='bold')
|
| 91 |
+
fig.tight_layout()
|
| 92 |
+
|
| 93 |
return fig
|
| 94 |
|
| 95 |
+
|
| 96 |
# Interface Gradio
|
| 97 |
demo = gr.Interface(
|
| 98 |
fn=predire,
|