Abdullah4747 commited on
Commit
05b8be6
·
1 Parent(s): 393dc75

Updating from matplotlib to plotly express for quality plots

Browse files
Files changed (1) hide show
  1. app.py +19 -11
app.py CHANGED
@@ -295,17 +295,25 @@ if st.session_state['prediction_made']:
295
  classes = list(tumor_info.keys())
296
  probs = st.session_state['prediction_probs'] * 100
297
 
298
- fig, ax = plt.subplots(figsize=(10, 5))
299
- colors = ['#1e88e5' if c != st.session_state['predicted_class'] else '#4CAF50' for c in classes]
300
- bars = ax.barh([c.replace('_', ' ').title() for c in classes], probs, color=colors)
301
- ax.set_xlabel('Probability (%)')
302
- ax.set_title('Prediction Confidence Distribution', fontsize=14, fontweight='bold')
303
- ax.set_xlim(0, 100)
304
-
305
- for bar, prob in zip(bars, probs):
306
- ax.text(min(prob + 2, 98), bar.get_y() + bar.get_height()/2, f'{prob:.1f}%',
307
- ha='left', va='center', color='white', fontweight='bold', fontsize=12)
308
- st.pyplot(fig)
 
 
 
 
 
 
 
 
309
 
310
  with tab2:
311
  if st.session_state['gradcam_img'] is not None:
 
295
  classes = list(tumor_info.keys())
296
  probs = st.session_state['prediction_probs'] * 100
297
 
298
+ # Use Plotly instead of matplotlib
299
+ fig = px.bar(
300
+ x=probs,
301
+ y=[c.replace('_', ' ').title() for c in classes],
302
+ orientation='h',
303
+ text=probs,
304
+ color=[c.replace('_', ' ').title() for c in classes],
305
+ color_discrete_sequence=['#1e88e5' if c != st.session_state['predicted_class'] else '#4CAF50' for c in classes]
306
+ )
307
+ fig.update_layout(
308
+ title='Prediction Confidence Distribution',
309
+ xaxis_title='Probability (%)',
310
+ yaxis_title='Class',
311
+ showlegend=False,
312
+ uniformtext_minsize=12,
313
+ uniformtext_mode='hide'
314
+ )
315
+ fig.update_traces(texttemplate='%{text:.1f}%', textposition='outside')
316
+ st.plotly_chart(fig, use_container_width=True)
317
 
318
  with tab2:
319
  if st.session_state['gradcam_img'] is not None: