import streamlit as st
import matplotlib.pyplot as plt
import numpy as np
# Inject custom CSS (without background image)
st.markdown(
"""
""",
unsafe_allow_html=True
)
# App Header with Logo
st.markdown(
"""
""",
unsafe_allow_html=True
)
# Sub-sections
st.markdown("", unsafe_allow_html=True)
st.markdown(
""
"Cricket is one of the most popular sports worldwide, loved by millions. "
"It is played in multiple formats, including Tests, ODIs, and T20s. "
"With legendary players, thrilling rivalries, and unforgettable moments, cricket is more than a gameβit's an emotion! π"
"
",
unsafe_allow_html=True
)
st.markdown("", unsafe_allow_html=True)
st.markdown(
""
"Cric Metrics is an AI-powered cricket analytics platform. It offers player comparisons, performance analysis, "
"team stats, and match predictions. It empowers fans, analysts, and teams with smart, data-driven insights. π€π"
"
",
unsafe_allow_html=True
)
st.markdown("", unsafe_allow_html=True)
st.markdown(
""
"From grassroots cricket to international glory, Cric Metrics helps track form, fitness, and match-winning impact. "
"We leverage machine learning models and visual analytics to make cricket smarter and more fun! π"
"
",
unsafe_allow_html=True
)
st.markdown("", unsafe_allow_html=True)
st.markdown(
"""
Sai Kalyan Satwik is a seasoned cricket enthusiast and tech entrepreneur having experience in data science and software development.
His passion for cricket meets his technical expertise in this app, blending numbers with narratives for fans and analysts alike.
""",
unsafe_allow_html=True
)
# Navigation Button
if st.button("π Player Information"):
st.switch_page("pages/1player_information.py")
# Footer
st.markdown("", unsafe_allow_html=True)
def plot_pie_charts(player1_data, player2_data, player1_name, player2_name):
# Extract batting and bowling values with fallback to 0 if not found
sizes1 = [
player1_data.get('Batting', 0),
player1_data.get('Bowling', 0)
]
sizes2 = [
player2_data.get('Batting', 0),
player2_data.get('Bowling', 0)
]
# Replace NaNs or None with 0
sizes1 = [0 if x is None or np.isnan(x) else x for x in sizes1]
sizes2 = [0 if x is None or np.isnan(x) else x for x in sizes2]
# Warn and skip if all values are 0 (nothing to plot)
if sum(sizes1) == 0 and sum(sizes2) == 0:
st.warning("Unable to display pie charts. No valid data found for both players.")
return
elif sum(sizes1) == 0:
st.warning(f"No valid contribution data for {player1_name}.")
return
elif sum(sizes2) == 0:
st.warning(f"No valid contribution data for {player2_name}.")
return
# Plot pie charts
fig, axes = plt.subplots(1, 2, figsize=(10, 5))
labels = ['Batting', 'Bowling']
axes[0].pie(sizes1, labels=labels, autopct='%1.1f%%', startangle=90, colors=['#4CAF50', '#2196F3'])
axes[0].set_title(f'{player1_name} Contribution')
axes[1].pie(sizes2, labels=labels, autopct='%1.1f%%', startangle=90, colors=['#4CAF50', '#2196F3'])
axes[1].set_title(f'{player2_name} Contribution')
# Display in Streamlit
st.pyplot(fig)