Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -94,7 +94,7 @@ classes = ["Cubisme", "Expressionnisme", "Post-impressionnisme"]
|
|
| 94 |
return fig"""
|
| 95 |
|
| 96 |
# Solution 3 : Passer par Plotly
|
| 97 |
-
import plotly.graph_objects as go
|
| 98 |
|
| 99 |
def predire(image):
|
| 100 |
image_resized = tf.image.resize(image, (224, 224)) / 255.0
|
|
@@ -120,6 +120,30 @@ def predire(image):
|
|
| 120 |
height=280,
|
| 121 |
font=dict(size=17)
|
| 122 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
return fig
|
| 124 |
|
| 125 |
|
|
|
|
| 94 |
return fig"""
|
| 95 |
|
| 96 |
# Solution 3 : Passer par Plotly
|
| 97 |
+
"""import plotly.graph_objects as go
|
| 98 |
|
| 99 |
def predire(image):
|
| 100 |
image_resized = tf.image.resize(image, (224, 224)) / 255.0
|
|
|
|
| 120 |
height=280,
|
| 121 |
font=dict(size=17)
|
| 122 |
)
|
| 123 |
+
return fig"""
|
| 124 |
+
|
| 125 |
+
# Solution avec le graphique plus haut
|
| 126 |
+
def predire(image):
|
| 127 |
+
image_resized = tf.image.resize(image, (224, 224)) / 255.0
|
| 128 |
+
preds = model.predict(tf.expand_dims(image_resized, axis=0))[0]
|
| 129 |
+
sorted_indices = np.argsort(preds)[::-1]
|
| 130 |
+
sorted_classes = [classes[i] for i in sorted_indices]
|
| 131 |
+
sorted_probs = [preds[i] for i in sorted_indices]
|
| 132 |
+
colors = ['#2ecc71' if prob >= 0.5 else '#bdc3c7' for prob in sorted_probs]
|
| 133 |
+
|
| 134 |
+
fig = Figure(figsize=(6, 4.2)) # hauteur augmentée
|
| 135 |
+
ax = fig.add_subplot(111)
|
| 136 |
+
bars = ax.bar(sorted_classes, sorted_probs, color=colors, edgecolor='black', linewidth=1.5)
|
| 137 |
+
|
| 138 |
+
for bar, prob in zip(bars, sorted_probs):
|
| 139 |
+
ax.text(bar.get_x() + bar.get_width()/2, bar.get_height() + 0.035,
|
| 140 |
+
f"{prob*100:.1f}%", ha='center', va='bottom', fontsize=12, color='black', fontweight='bold')
|
| 141 |
+
|
| 142 |
+
ax.set_ylabel('Probabilité', fontsize=14, fontweight='bold')
|
| 143 |
+
ax.set_ylim(0, 1)
|
| 144 |
+
ax.set_title("Probabilités par mouvement pictural", fontsize=14, fontweight='bold', pad=20)
|
| 145 |
+
ax.set_xticklabels(sorted_classes, rotation=45, ha='right', fontsize=13, fontweight='bold')
|
| 146 |
+
fig.tight_layout(pad=2.0)
|
| 147 |
return fig
|
| 148 |
|
| 149 |
|