Eric2mangel commited on
Commit
9442e1b
·
verified ·
1 Parent(s): da457da

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -1
app.py CHANGED
@@ -60,7 +60,8 @@ classes = ["Cubisme", "Expressionnisme", "Post-impressionnisme"]
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
 
@@ -90,9 +91,39 @@ def predire(image):
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,
 
60
 
61
  return fig"""
62
 
63
+ # Solution 2
64
+ """def predire(image):
65
  image_resized = tf.image.resize(image, (224, 224)) / 255.0
66
  preds = model.predict(tf.expand_dims(image_resized, axis=0))[0]
67
 
 
91
  ax.set_xticklabels(sorted_classes, rotation=45, ha='right', fontsize=15, fontweight='bold')
92
  fig.tight_layout()
93
 
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
101
+ preds = model.predict(tf.expand_dims(image_resized, axis=0))[0]
102
+
103
+ sorted_indices = np.argsort(preds)[::-1]
104
+ sorted_classes = [classes[i] for i in sorted_indices]
105
+ sorted_probs = [preds[i] for i in sorted_indices]
106
+ colors = ['#2ecc71' if prob >= 0.5 else '#bdc3c7' for prob in sorted_probs]
107
+
108
+ fig = go.Figure(go.Bar(
109
+ x=sorted_classes,
110
+ y=sorted_probs,
111
+ text=[f"{p*100:.1f}%" for p in sorted_probs],
112
+ marker=dict(color=colors, line=dict(color='black', width=1)),
113
+ textposition='auto',
114
+ ))
115
+ fig.update_layout(
116
+ xaxis=dict(tickangle=45, tickfont=dict(size=17)),
117
+ yaxis=dict(range=[0,1], title='Probabilité', tickfont=dict(size=17)),
118
+ title="Probabilités par mouvement pictural",
119
+ margin=dict(l=15, r=15, t=40, b=25),
120
+ height=280,
121
+ font=dict(size=17)
122
+ )
123
  return fig
124
 
125
 
126
+
127
  # Interface Gradio
128
  demo = gr.Interface(
129
  fn=predire,