Download pages/Automatic_Machine_learning_app.py from shwetashweta05/Automatic_Machine_Learning-app: direct link, hf CLI and curl.
- Browser
- Download file 5.99 kB
-
https://huggingface.co/spaces/shwetashweta05/Automatic_Machine_Learning-app/resolve/main/pages/Automatic_Machine_learning_app.py
- Command line
-
hf download hf://spaces/shwetashweta05/Automatic_Machine_Learning-app/pages/Automatic_Machine_learning_app.py
-
curl -L -o Automatic_Machine_learning_app.py https://huggingface.co/spaces/shwetashweta05/Automatic_Machine_Learning-app/resolve/main/pages/Automatic_Machine_learning_app.py
5.99 kB
| import streamlit as st | |
| import pandas as pd | |
| import plotly.express as px | |
| import os | |
| # Streamlit Configuration | |
| st.set_page_config( | |
| page_title="Cricket Performance Analytics", | |
| layout="wide", | |
| initial_sidebar_state="expanded" | |
| ) | |
| # Custom CSS for Styling | |
| st.markdown(""" | |
| <style> | |
| .main-title { | |
| color: #2E86C1; | |
| font-size: 36px; | |
| font-weight: bold; | |
| text-align: center; | |
| padding: 20px 0; | |
| } | |
| .section-header { | |
| color: #1A5276; | |
| font-size: 24px; | |
| padding: 10px 0; | |
| } | |
| .metric-card { | |
| background-color: #EAF2F8; | |
| padding: 15px; | |
| border-radius: 10px; | |
| text-align: center; | |
| box-shadow: 0 2px 5px rgba(0,0,0,0.1); | |
| margin: 5px; | |
| } | |
| .metric-card h3 { | |
| color: #1A5276; | |
| font-size: 18px; | |
| margin-bottom: 5px; | |
| } | |
| .metric-card p { | |
| color: #2E86C1; | |
| font-size: 24px; | |
| font-weight: bold; | |
| margin: 0; | |
| } | |
| </style> | |
| """, unsafe_allow_html=True) | |
| # Load Data | |
| batting_path = "Teams_batting.csv" | |
| bowling_path = "team_bowling.csv" | |
| if not os.path.exists(batting_path) or not os.path.exists(bowling_path): | |
| st.error("CSV files not found. Please check file paths.") | |
| st.stop() | |
| batting_df = pd.read_csv(batting_path) | |
| bowling_df = pd.read_csv(bowling_path) | |
| # Debugging: Print column names | |
| st.write("Batting DataFrame Columns:", batting_df.columns.tolist()) | |
| st.write("Bowling DataFrame Columns:", bowling_df.columns.tolist()) | |
| # Correct column names | |
| if "player_name" not in batting_df.columns: | |
| st.error("Column 'player_name' not found! Available columns: " + ", ".join(batting_df.columns)) | |
| st.stop() | |
| # Sidebar Team Selection | |
| teams = sorted(set(batting_df['Country'].unique()).union(bowling_df['Country'].unique())) | |
| selected_team = st.selectbox("Choose a Team", teams, format_func=lambda x: x.upper()) | |
| # Player Selection | |
| batting_players = batting_df[batting_df['Country'] == selected_team]['player_name'].unique() | |
| bowling_players = bowling_df[bowling_df['Country'] == selected_team]['player_name'].unique() | |
| players = sorted(set(batting_players).union(bowling_players)) | |
| selected_player = st.selectbox("Choose a Player", players) | |
| st.success("Code successfully executed!") | |
| # Filter Player Data | |
| player_batting = batting_df[(batting_df['player_name'] == selected_player) & | |
| (batting_df[team_column] == selected_team)] | |
| player_bowling = bowling_df[(bowling_df['player_name'] == selected_player) & | |
| (bowling_df[team_column] == selected_team)] | |
| # Main Dashboard | |
| st.markdown(f'<div class="main-title">{selected_player}\'s Cricket Analytics</div>', unsafe_allow_html=True) | |
| # Key Metrics Section | |
| st.markdown('<div class="section-header">Key Performance Metrics</div>', unsafe_allow_html=True) | |
| if not player_batting.empty: | |
| col1, col2, col3 = st.columns(3) | |
| with col1: | |
| total_runs = player_batting['runs'].sum() | |
| st.markdown(f'<div class="metric-card"><h3>Total Runs</h3><p>{total_runs}</p></div>', unsafe_allow_html=True) | |
| with col2: | |
| avg_sr = player_batting['sr'].mean().round(2) | |
| st.markdown(f'<div class="metric-card"><h3>Avg Strike Rate</h3><p>{avg_sr}</p></div>', unsafe_allow_html=True) | |
| with col3: | |
| matches = len(player_batting) | |
| st.markdown(f'<div class="metric-card"><h3>Matches</h3><p>{matches}</p></div>', unsafe_allow_html=True) | |
| else: | |
| st.warning("No batting data available to display key metrics.") | |
| # Visualization Section | |
| tab1, tab2 = st.tabs(["Batting Analysis", "Bowling Analysis"]) | |
| with tab1: | |
| if not player_batting.empty: | |
| st.markdown('<div class="section-header">Batting Performance</div>', unsafe_allow_html=True) | |
| col1, col2 = st.columns(2) | |
| with col1: | |
| fig_runs = px.pie(player_batting, values='runs', names='format', | |
| title='Runs Distribution by Format', | |
| color_discrete_sequence=px.colors.sequential.Blues) | |
| fig_runs.update_layout(title_x=0.5) | |
| st.plotly_chart(fig_runs, use_container_width=True) | |
| with col2: | |
| fig_sr = px.scatter(player_batting, x='format', y='sr', | |
| size='runs', color='format', | |
| title='Strike Rate Analysis', | |
| hover_data=['runs']) | |
| fig_sr.update_layout(title_x=0.5) | |
| st.plotly_chart(fig_sr, use_container_width=True) | |
| else: | |
| st.info("No batting statistics available for this player.") | |
| with tab2: | |
| if not player_bowling.empty: | |
| st.markdown('<div class="section-header">Bowling Performance</div>', unsafe_allow_html=True) | |
| col3, col4 = st.columns(2) | |
| with col3: | |
| fig_wickets = px.bar(player_bowling, x='format', y='wickets', | |
| color='format', | |
| title='Wickets by Format', | |
| color_discrete_sequence=px.colors.sequential.Reds) | |
| fig_wickets.update_layout(title_x=0.5) | |
| st.plotly_chart(fig_wickets, use_container_width=True) | |
| with col4: | |
| fig_eco = px.area(player_bowling, x='format', y='eco', | |
| title='Economy Rate Trend', | |
| color_discrete_sequence=['#2ECC71']) | |
| fig_eco.update_layout(title_x=0.5) | |
| st.plotly_chart(fig_eco, use_container_width=True) | |
| else: | |
| st.info("No bowling statistics available for this player.") | |
| # Raw Data Expander | |
| with st.expander("View Raw Data"): | |
| if not player_batting.empty: | |
| st.write("### Batting Statistics") | |
| st.dataframe(player_batting.iloc[:, :17].style.set_properties(**{'background-color': '#F8F9F9'})) | |
| if not player_bowling.empty: | |
| st.write("### Bowling Statistics") | |
| st.dataframe(player_bowling.iloc[:, :15].style.set_properties(**{'background-color': '#F8F9F9'})) | |