Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import matplotlib.pyplot as plt
|
| 4 |
+
|
| 5 |
+
# App Title and Description
|
| 6 |
+
st.title("π Cricket Player Dashboard")
|
| 7 |
+
st.markdown("""
|
| 8 |
+
### π Analyze Player Performance
|
| 9 |
+
- Select a **Team** and choose a **Player** to view their **Batting and Bowling Metrics**.
|
| 10 |
+
""")
|
| 11 |
+
|
| 12 |
+
# Load CSV directly from Hugging Face repository
|
| 13 |
+
@st.cache_data
|
| 14 |
+
def load_data():
|
| 15 |
+
return pd.read_csv("player_stats.csv")
|
| 16 |
+
|
| 17 |
+
df = load_data()
|
| 18 |
+
|
| 19 |
+
# Sidebar - Team and Player selection
|
| 20 |
+
teams = df['Team'].unique()
|
| 21 |
+
selected_team = st.sidebar.selectbox("Select Team", teams)
|
| 22 |
+
|
| 23 |
+
# Filter players by selected team
|
| 24 |
+
players = df[df['Team'] == selected_team]['Player_Name'].unique()
|
| 25 |
+
selected_player = st.sidebar.selectbox("Select Player", players)
|
| 26 |
+
|
| 27 |
+
# Filter the data by selected player
|
| 28 |
+
player_data = df[(df['Team'] == selected_team) & (df['Player_Name'] == selected_player)]
|
| 29 |
+
|
| 30 |
+
# Display Player Info
|
| 31 |
+
st.title(f"π {selected_player} - {selected_team}")
|
| 32 |
+
st.write(f"**Format:** {player_data['Format'].values[0]}")
|
| 33 |
+
st.write(f"**Matches:** {player_data['Matches'].values[0]}")
|
| 34 |
+
st.write(f"**Innings:** {player_data['Innings'].values[0]}")
|
| 35 |
+
|
| 36 |
+
# Batting Performance Visualization
|
| 37 |
+
st.subheader("π Batting Metrics")
|
| 38 |
+
|
| 39 |
+
fig, ax = plt.subplots(2, 2, figsize=(12, 10))
|
| 40 |
+
|
| 41 |
+
# Runs vs Balls Faced
|
| 42 |
+
ax[0, 0].bar(['Runs', 'Balls Faced'], [player_data['Runs'].values[0], player_data['Balls_Faced'].values[0]], color=['blue', 'orange'])
|
| 43 |
+
ax[0, 0].set_title("Runs vs Balls Faced")
|
| 44 |
+
|
| 45 |
+
# Batting Average and Strike Rate
|
| 46 |
+
ax[0, 1].bar(['Average', 'Strike Rate'], [player_data['Avg'].values[0], player_data['SR'].values[0]], color=['green', 'purple'])
|
| 47 |
+
ax[0, 1].set_title("Average and Strike Rate")
|
| 48 |
+
|
| 49 |
+
# Fifties and Hundreds
|
| 50 |
+
ax[1, 0].bar(['50s', '100s'], [player_data['50s'].values[0], player_data['100s'].values[0]], color=['cyan', 'magenta'])
|
| 51 |
+
ax[1, 0].set_title("50s and 100s")
|
| 52 |
+
|
| 53 |
+
# Bowling Performance Visualization
|
| 54 |
+
st.subheader("π― Bowling Metrics")
|
| 55 |
+
|
| 56 |
+
# Balls vs Wickets
|
| 57 |
+
ax[1, 1].bar(['Balls', 'Wickets'], [player_data['Balls'].values[0], player_data['Wickets'].values[0]], color=['red', 'yellow'])
|
| 58 |
+
ax[1, 1].set_title("Balls vs Wickets")
|
| 59 |
+
|
| 60 |
+
plt.tight_layout()
|
| 61 |
+
st.pyplot(fig)
|
| 62 |
+
|
| 63 |
+
# Advanced Bowling Metrics
|
| 64 |
+
fig, ax = plt.subplots(2, 2, figsize=(12, 10))
|
| 65 |
+
|
| 66 |
+
# Economy Rate
|
| 67 |
+
ax[0, 0].bar(['Economy Rate'], [player_data['Eco'].values[0]], color='purple')
|
| 68 |
+
ax[0, 0].set_title("Economy Rate")
|
| 69 |
+
|
| 70 |
+
# Best Bowling Figures in Innings (BBI) & Match (BBM)
|
| 71 |
+
ax[0, 1].bar(['BBI', 'BBM'], [player_data['BBI'].values[0], player_data['BBM'].values[0]], color=['blue', 'orange'])
|
| 72 |
+
ax[0, 1].set_title("Best Bowling Figures")
|
| 73 |
+
|
| 74 |
+
# 4w and 5w hauls
|
| 75 |
+
ax[1, 0].bar(['4w', '5w', '10w'], [player_data['4w'].values[0], player_data['5w'].values[0], player_data['10w'].values[0]], color=['green', 'red', 'yellow'])
|
| 76 |
+
ax[1, 0].set_title("4W, 5W, and 10W Hauls")
|
| 77 |
+
|
| 78 |
+
plt.tight_layout()
|
| 79 |
+
st.pyplot(fig)
|
| 80 |
+
|
| 81 |
+
# Display Summary Metrics
|
| 82 |
+
st.write("### Player Summary Metrics")
|
| 83 |
+
st.write(player_data[['Matches', 'Innings', 'Runs', 'Balls_Faced', 'Avg', 'SR', '50s', '100s',
|
| 84 |
+
'Balls', 'Wickets', 'Eco', 'BBI', 'BBM', '4w', '5w', '10w']])
|