Sathwikchowdary commited on
Commit
db65e54
·
verified ·
1 Parent(s): 4ec975b

Update Home.py

Browse files
Files changed (1) hide show
  1. Home.py +44 -0
Home.py CHANGED
@@ -1,4 +1,6 @@
1
  import streamlit as st
 
 
2
 
3
  # Inject custom CSS (without background image)
4
  st.markdown(
@@ -109,3 +111,45 @@ if st.button("📊 Player Information"):
109
 
110
  # Footer
111
  st.markdown("<div class='footer'>Created with ❤️ by Sai Kalyan Satwik</div>", unsafe_allow_html=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ import matplotlib.pyplot as plt
3
+ import numpy as np
4
 
5
  # Inject custom CSS (without background image)
6
  st.markdown(
 
111
 
112
  # Footer
113
  st.markdown("<div class='footer'>Created with ❤️ by Sai Kalyan Satwik</div>", unsafe_allow_html=True)
114
+
115
+
116
+ # ---------- PIE CHART FUNCTION ----------
117
+
118
+ def plot_pie_charts(player1_data, player2_data, player1_name, player2_name):
119
+ # Extract batting and bowling values with fallback to 0 if not found
120
+ sizes1 = [
121
+ player1_data.get('Batting', 0),
122
+ player1_data.get('Bowling', 0)
123
+ ]
124
+ sizes2 = [
125
+ player2_data.get('Batting', 0),
126
+ player2_data.get('Bowling', 0)
127
+ ]
128
+
129
+ # Replace NaNs or None with 0
130
+ sizes1 = [0 if x is None or np.isnan(x) else x for x in sizes1]
131
+ sizes2 = [0 if x is None or np.isnan(x) else x for x in sizes2]
132
+
133
+ # Warn and skip if all values are 0 (nothing to plot)
134
+ if sum(sizes1) == 0 and sum(sizes2) == 0:
135
+ st.warning("Unable to display pie charts. No valid data found for both players.")
136
+ return
137
+ elif sum(sizes1) == 0:
138
+ st.warning(f"No valid contribution data for {player1_name}.")
139
+ return
140
+ elif sum(sizes2) == 0:
141
+ st.warning(f"No valid contribution data for {player2_name}.")
142
+ return
143
+
144
+ # Plot pie charts
145
+ fig, axes = plt.subplots(1, 2, figsize=(10, 5))
146
+ labels = ['Batting', 'Bowling']
147
+
148
+ axes[0].pie(sizes1, labels=labels, autopct='%1.1f%%', startangle=90, colors=['#4CAF50', '#2196F3'])
149
+ axes[0].set_title(f'{player1_name} Contribution')
150
+
151
+ axes[1].pie(sizes2, labels=labels, autopct='%1.1f%%', startangle=90, colors=['#4CAF50', '#2196F3'])
152
+ axes[1].set_title(f'{player2_name} Contribution')
153
+
154
+ # Display in Streamlit
155
+ st.pyplot(fig)