mimi111222 commited on
Commit
6d0cf2b
·
verified ·
1 Parent(s): 98d2dca

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -14
app.py CHANGED
@@ -578,9 +578,9 @@ def calculate_phishing_score(text):
578
  return probability
579
 
580
  def generate_confusion_matrix_plot(_cm):
581
- """Generate confusion matrix plot"""
582
  plt.style.use('dark_background')
583
- fig, ax = plt.subplots(figsize=(5, 4), facecolor='#1a1a1a')
584
  ax.set_facecolor('#1a1a1a')
585
 
586
  sns.heatmap(
@@ -591,27 +591,34 @@ def generate_confusion_matrix_plot(_cm):
591
  cmap="YlOrBr",
592
  cbar=True,
593
  square=True,
594
- annot_kws={"size": 16, "weight": "bold", "color": "#0f0f0f"},
595
- linewidths=2,
596
  linecolor='#0f0f0f',
597
- cbar_kws={'label': 'Count', 'shrink': 0.8}
 
 
598
  )
599
 
600
- ax.set_xlabel("Predicted", fontsize=11, fontweight='bold', color='#FFD700')
601
- ax.set_ylabel("Actual", fontsize=11, fontweight='bold', color='#FFD700')
602
- ax.set_xticklabels(["Safe", "Phishing"], fontsize=10, color='#e5e7eb')
603
- ax.set_yticklabels(["Safe", "Phishing"], fontsize=10, rotation=0, color='#e5e7eb')
604
- ax.set_title("Confusion Matrix", fontsize=13, fontweight='bold', pad=12, color='#FFD700')
605
 
606
- cbar = ax.collections[0].colorbar
607
- cbar.ax.yaxis.set_tick_params(color='#e5e7eb')
608
- plt.setp(plt.getp(cbar.ax.axes, 'yticklabels'), color='#e5e7eb')
 
 
 
 
609
 
610
  plt.tight_layout()
611
  buf = io.BytesIO()
612
- plt.savefig(buf, format='png', facecolor='#1a1a1a', dpi=100)
613
  buf.seek(0)
614
  plt.close(fig)
 
615
 
616
  return buf
617
 
 
578
  return probability
579
 
580
  def generate_confusion_matrix_plot(_cm):
581
+ """Generate confusion matrix plot - optimized for performance"""
582
  plt.style.use('dark_background')
583
+ fig, ax = plt.subplots(figsize=(5, 4), facecolor='#1a1a1a', dpi=80)
584
  ax.set_facecolor('#1a1a1a')
585
 
586
  sns.heatmap(
 
591
  cmap="YlOrBr",
592
  cbar=True,
593
  square=True,
594
+ annot_kws={"size": 14, "weight": "bold", "color": "#0f0f0f"},
595
+ linewidths=1,
596
  linecolor='#0f0f0f',
597
+ cbar_kws={'label': 'Count', 'shrink': 0.8},
598
+ vmin=0,
599
+ vmax=_cm.max()
600
  )
601
 
602
+ ax.set_xlabel("Predicted", fontsize=10, fontweight='bold', color='#FFD700')
603
+ ax.set_ylabel("Actual", fontsize=10, fontweight='bold', color='#FFD700')
604
+ ax.set_xticklabels(["Safe", "Phishing"], fontsize=9, color='#e5e7eb')
605
+ ax.set_yticklabels(["Safe", "Phishing"], fontsize=9, rotation=0, color='#e5e7eb')
606
+ ax.set_title("Confusion Matrix", fontsize=12, fontweight='bold', pad=10, color='#FFD700')
607
 
608
+ try:
609
+ cbar = ax.collections[0].colorbar
610
+ if cbar:
611
+ cbar.ax.yaxis.set_tick_params(color='#e5e7eb')
612
+ plt.setp(plt.getp(cbar.ax.axes, 'yticklabels'), color='#e5e7eb')
613
+ except:
614
+ pass
615
 
616
  plt.tight_layout()
617
  buf = io.BytesIO()
618
+ plt.savefig(buf, format='png', facecolor='#1a1a1a', dpi=80, bbox_inches='tight')
619
  buf.seek(0)
620
  plt.close(fig)
621
+ plt.close('all')
622
 
623
  return buf
624