Spaces:
Build error
Build error
Download app.py from saikumar27/WicketWise: direct link, hf CLI and curl.
- Browser
- Download file 10.6 kB
-
https://huggingface.co/spaces/saikumar27/WicketWise/resolve/main/app.py
- Command line
-
hf download hf://spaces/saikumar27/WicketWise/app.py
-
curl -L -o app.py https://huggingface.co/spaces/saikumar27/WicketWise/resolve/main/app.py
10.6 kB
| import streamlit as st | |
| import pandas as pd | |
| import plotly.express as px | |
| import numpy as np | |
| # Configure page | |
| st.set_page_config( | |
| page_title="Cricket Analytics Pro", | |
| page_icon="π", | |
| layout="wide" | |
| ) | |
| # Custom CSS | |
| st.markdown(""" | |
| <style> | |
| .main-title { | |
| color: #1e3d8f; | |
| font-size: 2.8rem; | |
| text-align: center; | |
| margin-bottom: 0.5rem; | |
| } | |
| .header { | |
| color: #e63946; | |
| font-size: 1.8rem; | |
| border-bottom: 2px solid #1e3d8f; | |
| padding-bottom: 0.3rem; | |
| margin-top: 1.5rem; | |
| } | |
| .metric-card { | |
| background: white; | |
| border-radius: 10px; | |
| padding: 1rem; | |
| box-shadow: 0 2px 4px rgba(0,0,0,0.1); | |
| margin-bottom: 1rem; | |
| } | |
| .about-card { | |
| background: white; | |
| border-radius: 10px; | |
| padding: 1.5rem; | |
| box-shadow: 0 4px 6px rgba(0,0,0,0.1); | |
| margin-bottom: 1.5rem; | |
| } | |
| .author-card { | |
| display: flex; | |
| align-items: center; | |
| gap: 20px; | |
| background: white; | |
| border-radius: 10px; | |
| padding: 1.5rem; | |
| box-shadow: 0 4px 6px rgba(0,0,0,0.1); | |
| } | |
| .author-img { | |
| width: 120px; | |
| height: 120px; | |
| border-radius: 50%; | |
| object-fit: cover; | |
| border: 3px solid #1e3d8f; | |
| } | |
| </style> | |
| """, unsafe_allow_html=True) | |
| def load_data(): | |
| try: | |
| df = pd.read_csv("All_Cric_Stats.csv") | |
| # Convert numeric columns, handling errors | |
| numeric_cols = ['Batting_Runs', 'Batting_Average', 'Batting_SR', | |
| 'Bowling_Wickets', 'Bowling_Avg', 'Bowling_SR', 'Bowling_Eco'] | |
| for col in numeric_cols: | |
| if col in df.columns: | |
| df[col] = pd.to_numeric(df[col], errors='coerce') | |
| return df | |
| except Exception as e: | |
| st.error(f"Error loading data: {str(e)}") | |
| return pd.DataFrame() | |
| df = load_data() | |
| # --- Home Page Content --- | |
| st.markdown('<h1 class="main-title">π Cricket Analytics Dashboard</h1>', unsafe_allow_html=True) | |
| # ====== NEW SECTIONS ====== | |
| # About the Dashboard | |
| with st.container(): | |
| st.markdown('<h2 class="header">About This Dashboard</h2>', unsafe_allow_html=True) | |
| st.markdown(""" | |
| <div class="about-card"> | |
| <p>This Cricket Analytics Dashboard transforms raw cricket statistics into actionable insights through:</p> | |
| <ul> | |
| <li><strong>Comprehensive Player Analysis:</strong> Compare batting and bowling performances across formats</li> | |
| <li><strong>Team Performance Metrics:</strong> Evaluate team strengths and historical trends</li> | |
| <li><strong>Interactive Visualizations:</strong> Explore data through dynamic, customizable charts</li> | |
| <li><strong>Data-Driven Insights:</strong> Identify patterns and anomalies in player/team statistics</li> | |
| </ul> | |
| <p>The dashboard serves cricket analysts, team selectors, fantasy players, and enthusiasts who want deeper understanding beyond traditional statistics.</p> | |
| </div> | |
| """, unsafe_allow_html=True) | |
| # Goals Section | |
| with st.container(): | |
| st.markdown('<h2 class="header">Our Goals</h2>', unsafe_allow_html=True) | |
| col1, col2 = st.columns(2) | |
| with col1: | |
| st.markdown(""" | |
| <div class="about-card"> | |
| <h3>π Analytical Objectives</h3> | |
| <ul> | |
| <li>Provide advanced metrics beyond traditional averages</li> | |
| <li>Identify performance patterns across conditions</li> | |
| <li>Benchmark players against peers and legends</li> | |
| <li>Visualize career trajectories and form trends</li> | |
| </ul> | |
| </div> | |
| """, unsafe_allow_html=True) | |
| with col2: | |
| st.markdown(""" | |
| <div class="about-card"> | |
| <h3>π Technical Objectives</h3> | |
| <ul> | |
| <li>Implement interactive data exploration tools</li> | |
| <li>Develop predictive performance models</li> | |
| <li>Create responsive, user-friendly visualizations</li> | |
| <li>Process large cricket datasets efficiently</li> | |
| </ul> | |
| </div> | |
| """, unsafe_allow_html=True) | |
| # About Author | |
| with st.container(): | |
| st.markdown('<h2 class="header">About the Author</h2>', unsafe_allow_html=True) | |
| st.markdown(""" | |
| <div class="author-card"> | |
| <img src="https://avatars.githubusercontent.com/u/87555846?v=4" class="author-img" alt="Saikumar Nambaru"> | |
| <div> | |
| <h3>Saikumar Nambaru</h3> | |
| <p><strong>Data Scientist Traine| Cricket Analyst</strong></p> | |
| <p>A passionate data enthusiast with a deep interest in cricket analytics, Saikumar Nambaru leverages data science techniques | |
| to extract meaningful insights from cricket statistics. He is driven to bridge the gap between traditional cricket analysis and modern, | |
| data-driven insight Tis work combines technical expertise in data science with deep understanding of cricket dynamics.</p> | |
| <p>"My mission is to bridge the gap between traditional cricket statistics and modern analytics, | |
| making advanced insights accessible to everyone from coaches to casual fans."</p> | |
| </div> | |
| </div> | |
| """, unsafe_allow_html=True) | |
| # ====== DATA ANALYSIS SECTIONS ====== | |
| if not df.empty: | |
| st.markdown('<h2 class="header">Data Analysis</h2>', unsafe_allow_html=True) | |
| # Format Selection | |
| selected_format = st.selectbox( | |
| "Select Cricket Format", | |
| options=df['Format'].unique(), | |
| index=0 | |
| ) | |
| # Filter data by selected format | |
| format_df = df[df['Format'] == selected_format].copy() | |
| # Key Metrics | |
| st.markdown(f'<h3 class="header">Top Performers in {selected_format}</h3>', unsafe_allow_html=True) | |
| col1, col2, col3 = st.columns(3) | |
| # Batting Metrics | |
| with col1: | |
| if not format_df.empty: | |
| top_batter = format_df.loc[format_df['Batting_Runs'].idxmax()] | |
| st.markdown(f""" | |
| <div class="metric-card"> | |
| <h3>Top Batter</h3> | |
| <p style="font-size: 1.5rem; margin-bottom: 0;">{top_batter['Player Name']}</p> | |
| <p style="font-size: 1.2rem; color: #555;"> | |
| {top_batter['Batting_Runs']:,.0f} runs | Avg: {top_batter['Batting_Average']:.1f} | SR: {top_batter['Batting_SR']:.1f} | |
| </p> | |
| </div> | |
| """, unsafe_allow_html=True) | |
| # Bowling Metrics | |
| with col2: | |
| if 'Bowling_Wickets' in format_df.columns: | |
| bowlers = format_df[format_df['Bowling_Wickets'] > 0] | |
| if not bowlers.empty: | |
| top_wicket_taker = bowlers.loc[bowlers['Bowling_Wickets'].idxmax()] | |
| st.markdown(f""" | |
| <div class="metric-card"> | |
| <h3>Top Wicket Taker</h3> | |
| <p style="font-size: 1.5rem; margin-bottom: 0;">{top_wicket_taker['Player Name']}</p> | |
| <p style="font-size: 1.2rem; color: #555;"> | |
| {top_wicket_taker['Bowling_Wickets']} wickets | Avg: {top_wicket_taker['Bowling_Avg']:.1f} | |
| </p> | |
| </div> | |
| """, unsafe_allow_html=True) | |
| # Best Bowling Average | |
| with col3: | |
| if 'Bowling_Avg' in format_df.columns and 'Bowling_Wickets' in format_df.columns: | |
| qualified_bowlers = format_df[(format_df['Bowling_Wickets'] >= 5) & (format_df['Bowling_Avg'] > 0)] | |
| if not qualified_bowlers.empty: | |
| best_bowler = qualified_bowlers.loc[qualified_bowlers['Bowling_Avg'].idxmin()] | |
| st.markdown(f""" | |
| <div class="metric-card"> | |
| <h3>Best Bowling Average</h3> | |
| <p style="font-size: 1.5rem; margin-bottom: 0;">{best_bowler['Player Name']}</p> | |
| <p style="font-size: 1.2rem; color: #555;"> | |
| Avg: {best_bowler['Bowling_Avg']:.1f} | Wkts: {best_bowler['Bowling_Wickets']} | |
| </p> | |
| </div> | |
| """, unsafe_allow_html=True) | |
| # Visualizations | |
| st.markdown('<h3 class="header">Performance Analysis</h3>', unsafe_allow_html=True) | |
| tab1, tab2 = st.tabs(["Batting", "Bowling"]) | |
| with tab1: | |
| if not format_df.empty: | |
| top_batters = format_df.groupby('Player Name').agg({ | |
| 'Batting_Runs': 'sum', | |
| 'Batting_Average': 'mean', | |
| 'Batting_SR': 'mean', | |
| 'Team Name': 'first' | |
| }).nlargest(10, 'Batting_Runs').reset_index() | |
| fig = px.bar(top_batters, | |
| x='Batting_Runs', y='Player Name', | |
| color='Team Name', | |
| title=f'Top 10 Run Scorers in {selected_format}', | |
| labels={'Batting_Runs': 'Total Runs'}, | |
| hover_data=['Batting_Average', 'Batting_SR']) | |
| st.plotly_chart(fig, use_container_width=True) | |
| with tab2: | |
| if 'Bowling_Wickets' in format_df.columns: | |
| top_bowlers = format_df[format_df['Bowling_Wickets'] > 0].groupby('Player Name').agg({ | |
| 'Bowling_Wickets': 'sum', | |
| 'Bowling_Avg': 'mean', | |
| 'Bowling_SR': 'mean', | |
| 'Team Name': 'first' | |
| }).nlargest(10, 'Bowling_Wickets').reset_index() | |
| fig = px.bar(top_bowlers, | |
| x='Bowling_Wickets', y='Player Name', | |
| color='Team Name', | |
| title=f'Top 10 Wicket Takers in {selected_format}', | |
| labels={'Bowling_Wickets': 'Total Wickets'}, | |
| hover_data=['Bowling_Avg', 'Bowling_SR']) | |
| st.plotly_chart(fig, use_container_width=True) | |
| # Data Explorer | |
| st.markdown('<h3 class="header">Data Explorer</h3>', unsafe_allow_html=True) | |
| with st.expander("View Raw Data", expanded=False): | |
| st.dataframe(format_df, use_container_width=True, height=400) | |
| else: | |
| st.warning(""" | |
| Data loading issue detected. Please verify: | |
| 1. The CSV file is named 'All_Cric_Stats.csv' | |
| 2. It's in the same folder as this app | |
| 3. The file contains valid data | |
| """) | |
| # Footer | |
| st.markdown("---") | |
| st.markdown(""" | |
| <div style="text-align: center; padding: 1.5rem; color: #666;"> | |
| <p>Β© 2023 Cricket Analytics Pro | Developed by Saikumar Nambaru | Built with Streamlit</p> | |
| </div> | |
| """, unsafe_allow_html=True) |