Eric2mangel commited on
Commit
dced319
·
verified ·
1 Parent(s): 9eace46

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -3
app.py CHANGED
@@ -122,8 +122,8 @@ def predire(image):
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]
@@ -144,7 +144,25 @@ def predire(image):
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
 
150
 
 
122
  )
123
  return fig"""
124
 
125
+ # Solution avec le graphique plus haut (ADAPTER LA HAUTEUR)
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]
 
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
+ # Façon 5 uniquement sur le texte
150
+ def predire(image):
151
+ image_resized = tf.image.resize(image, (224, 224)) / 255.0
152
+ preds = model.predict(tf.expand_dims(image_resized, axis=0))[0]
153
+ sorted_indices = np.argsort(preds)[::-1]
154
+ sorted_classes = [classes[i] for i in sorted_indices]
155
+ sorted_probs = [preds[i] for i in sorted_indices]
156
+
157
+ # HTML pour Gradio : barres remplies & label
158
+ bars = []
159
+ for cls, prob in zip(sorted_classes, sorted_probs):
160
+ color = "#2ecc71" if prob >= 0.5 else "#bdc3c7"
161
+ bars.append(f'''
162
+ <div style="background:linear-gradient(90deg,{color} {prob*100:.1f}%,#fff {prob*100:.1f}%);padding:6px 0;margin:5px 0;border-radius:4px;">
163
+ <span style="padding-left:12px;font-size:15px;font-weight:bold;">{cls} — {prob*100:.1f} %</span>
164
+ </div>''')
165
+ return gr.HTML("".join(bars))
166
 
167
 
168