LoloSemper commited on
Commit
5786038
·
verified ·
1 Parent(s): 9fec758

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -0
app.py CHANGED
@@ -361,6 +361,39 @@ def create_probability_chart(predictions, consensus_class):
361
 
362
  # Gráfico 2: Confianza por modelo
363
  model_names = [pred['model'].split(' ')[1] if len(pred['model'].split(' ')) > 1 else pred['model'] for pred in predictions]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
364
 
365
  try:
366
  # Convertir a RGB si es necesario
 
361
 
362
  # Gráfico 2: Confianza por modelo
363
  model_names = [pred['model'].split(' ')[1] if len(pred['model'].split(' ')) > 1 else pred['model'] for pred in predictions]
364
+ confidences = [pred['confidence'] for pred in predictions]
365
+
366
+ colors_conf = ['#ff6b35' if pred['is_malignant'] else '#44ff44' for pred in predictions]
367
+ bars2 = ax2.bar(range(len(predictions)), confidences, color=colors_conf, alpha=0.8)
368
+
369
+ ax2.set_xlabel('Modelos')
370
+ ax2.set_ylabel('Confianza')
371
+ ax2.set_title('🎯 Confianza por Modelo')
372
+ ax2.set_xticks(range(len(predictions)))
373
+ ax2.set_xticklabels(model_names, rotation=45)
374
+ ax2.grid(True, alpha=0.3)
375
+ ax2.set_ylim(0, 1)
376
+
377
+ # Añadir valores en las barras
378
+ for i, bar in enumerate(bars2):
379
+ height = bar.get_height()
380
+ ax2.text(bar.get_x() + bar.get_width()/2., height + 0.01,
381
+ f'{height:.1%}', ha='center', va='bottom', fontsize=9)
382
+
383
+ plt.tight_layout()
384
+
385
+ # Convertir a base64
386
+ buf = io.BytesIO()
387
+ plt.savefig(buf, format='png', dpi=300, bbox_inches='tight')
388
+ buf.seek(0)
389
+ chart_b64 = base64.b64encode(buf.getvalue()).decode()
390
+ plt.close()
391
+
392
+ return f'<img src="data:image/png;base64,{chart_b64}" style="width:100%; max-width:800px;">'
393
+
394
+ except Exception as e:
395
+ print(f"Error creando gráfico: {e}")
396
+ return "<p>❌ Error generando gráfico de probabilidades</p>"
397
 
398
  try:
399
  # Convertir a RGB si es necesario