shwetashweta05 commited on
Commit
f923e24
Β·
verified Β·
1 Parent(s): d1f641f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +82 -55
app.py CHANGED
@@ -1,55 +1,42 @@
1
  import streamlit as st
2
  import pandas as pd
3
  import base64
 
 
 
4
 
5
- # 🎨 Set Custom Background
6
- def set_bg(image_file):
7
- with open(image_file, "rb") as f:
8
- img_data = f.read()
9
- img_str = base64.b64encode(img_data).decode()
10
 
11
- bg_style = f"""
 
12
  <style>
13
- .stApp {{
14
  background: linear-gradient(to right, #eef2ff, #c7d2fe);
15
  color: white;
16
- }}
17
- .text-box {{
18
- background-color: rgba(0, 0, 0, 0.6);
19
- padding: 20px;
20
- border-radius: 10px;
21
- }}
22
- h1, h2, h4 {{
23
- text-align: center;
24
- color: orange;
25
- }}
26
  </style>
27
  """
28
  st.markdown(bg_style, unsafe_allow_html=True)
29
 
30
- set_bg("11837165.png")
 
31
 
32
- # πŸ† Title Section
33
- st.title("🏏 Cricket Team Players")
34
 
35
- # πŸ“Œ Introduction
36
- st.markdown("""
37
- ## πŸ† Introduction to Team Players
38
- Every successful cricket team is built on a strong foundation of talented players who contribute with their unique skills.
39
-
40
- ### **Player Categories:**
41
- - **🏏 Batsmen:** Focus on scoring runs, anchoring innings, or aggressive hitting.
42
- - **🎯 Bowlers:** Control opposition with pace or spin, aiming for wickets.
43
- - **πŸ”„ All-Rounders:** Contribute both with bat and ball for team balance.
44
- - **🧀 Wicketkeepers:** Handle fielding behind the stumps while supporting batting.
45
-
46
- With a mix of experience and young talent, teams thrive on strategy, teamwork, and passion!
47
- """)
48
-
49
- # πŸŽ₯ Animated Cricket Graphic
50
- st.markdown(
51
- """
52
- <div style="text-align: center;">
53
  <dotlottie-player
54
  src="https://lottie.host/04bff734-847b-4421-a180-197324166081/7WyVLEBZMa.lottie"
55
  background="transparent"
@@ -57,29 +44,69 @@ st.markdown(
57
  style="width: 200px; height: 200px;"
58
  loop autoplay>
59
  </dotlottie-player>
60
- </div>
61
- """,
62
- unsafe_allow_html=True
63
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64
 
65
  st.markdown("---")
66
 
67
- # πŸ“Š **Dashboard Summary**
68
- st.subheader("πŸ“Š Dashboard Summary")
69
- st.markdown("""
70
- This interactive dashboard presents career statistics with **modern visuals**:
71
- - **Batting & Bowling Summaries:** Runs, wickets, strike rates, economy rates.
72
- - **Smart Charts:** Bar graphs, pie charts, and trend analysis for easy insights.
73
- - **Career Progression:** Track performance over different formats and years.
74
- - **Compare Players:** Side-by-side performance comparison with key statistics.
75
- - **Dynamic UI:** Dark theme charts and interactive filters for analysis.
76
- """)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77
 
78
  st.markdown("---")
79
 
80
- # πŸ‘¨β€πŸ’» **About the Author**
81
  st.sidebar.markdown("### πŸ“Œ Author Details")
82
  st.sidebar.markdown("**πŸ‘€ Name:** Shweta Singh")
83
- st.sidebar.markdown("**πŸ“§ Email:** singhshwet05@gmail.com")
84
 
85
- st.markdown("πŸš€ **Made with ❀️ using Streamlit**")
 
 
1
  import streamlit as st
2
  import pandas as pd
3
  import base64
4
+ import plotly.express as px
5
+ import plotly.graph_objects as go
6
+ import streamlit.components.v1 as components
7
 
8
+ # Function to Set Background
 
 
 
 
9
 
10
+ def set_bg():
11
+ bg_style = """
12
  <style>
13
+ .stApp {
14
  background: linear-gradient(to right, #eef2ff, #c7d2fe);
15
  color: white;
16
+ }
 
 
 
 
 
 
 
 
 
17
  </style>
18
  """
19
  st.markdown(bg_style, unsafe_allow_html=True)
20
 
21
+ # Apply background set_bg()
22
+ set_bg()
23
 
24
+ # Page Title
25
+ st.title("πŸ† The Stats Pitch - Cricket Dashboard")
26
 
27
+ # About Cricket Section
28
+ col1, col2 = st.columns([2, 1])
29
+ with col1:
30
+ st.subheader("🏏 About Cricket")
31
+ st.markdown("""
32
+ - Cricket is a globally celebrated sport, cherished for its thrilling matches and historic rivalries.
33
+ - Originating in England, the game has evolved into a passion for millions. 🌍
34
+ - Whether it's a nail-biting **T20 finish** or the endurance of a **Test match**, cricket brings together skill, strategy, and teamwork.
35
+ - With formats ranging from **ODIs** to innovative leagues, cricket continues to captivate audiences and redefine sportsmanship.
36
+ """)
37
+ with col2:
38
+ components.html(
39
+ """
 
 
 
 
 
40
  <dotlottie-player
41
  src="https://lottie.host/04bff734-847b-4421-a180-197324166081/7WyVLEBZMa.lottie"
42
  background="transparent"
 
44
  style="width: 200px; height: 200px;"
45
  loop autoplay>
46
  </dotlottie-player>
47
+ """,
48
+ height=200,
49
+ width=200
50
+ )
51
+ st.markdown("---")
52
+
53
+ # Load Data (Ensure CSV files exist in the correct path)
54
+ batting_df = pd.read_csv("Teams_batting.csv")
55
+ bowling_df = pd.read_csv("team_bowling.csv")
56
+
57
+ # Select Team and Player
58
+ selected_team = st.selectbox("Select a Team:", batting_df["Team"].unique())
59
+ selected_player = st.selectbox("Select a Player:", batting_df[batting_df["Team"] == selected_team]["Player"].unique())
60
+
61
+ # Filter Data
62
+ player_batting = batting_df[batting_df["Player"] == selected_player]
63
+ player_bowling = bowling_df[bowling_df["Player"] == selected_player]
64
+
65
+ # Display Player Stats
66
+ st.markdown(f"## {selected_player} - Batting Performance")
67
+ st.dataframe(player_batting)
68
+
69
+ st.markdown(f"## {selected_player} - Bowling Performance")
70
+ st.dataframe(player_bowling)
71
 
72
  st.markdown("---")
73
 
74
+ # Visualizations
75
+ st.markdown("## πŸ“Š Performance Insights")
76
+
77
+ # Batting Performance Charts
78
+ if not player_batting.empty:
79
+ fig_scores = px.bar(
80
+ player_batting, x="Cricket Matches", y=["Runs", "Balls"],
81
+ title=f"{selected_player} - Runs & Balls Faced", barmode="group", text_auto=True,
82
+ color_discrete_sequence=["#FFA500"]
83
+ )
84
+ st.plotly_chart(fig_scores)
85
+
86
+ fig_centuries = px.pie(
87
+ names=["50s", "100s", "200s", "300s", "400s"],
88
+ values=[player_batting["50s"].sum(), player_batting["100s"].sum(), player_batting["200s"].sum(),
89
+ player_batting["300s"].sum(), player_batting["400s"].sum()],
90
+ title=f"{selected_player} - Milestone Contributions",
91
+ hole=0.3, color_discrete_sequence=["#5DADEC", "#FFB6C1", "#FFD700", "#BA55D3", "#FFA07A"]
92
+ )
93
+ st.plotly_chart(fig_centuries)
94
+
95
+ # Bowling Performance Charts
96
+ if not player_bowling.empty:
97
+ fig_wickets = px.bar(
98
+ player_bowling, x="Cricket Matches", y=["Balls", "Maidens", "Wickets", "4w", "5w", "10w"],
99
+ title=f"{selected_player} - Bowling Statistics", barmode="group", text_auto=True,
100
+ color_discrete_sequence=["#FF4500"]
101
+ )
102
+ st.plotly_chart(fig_wickets)
103
 
104
  st.markdown("---")
105
 
106
+ # Sidebar Author Section
107
  st.sidebar.markdown("### πŸ“Œ Author Details")
108
  st.sidebar.markdown("**πŸ‘€ Name:** Shweta Singh")
109
+ st.sidebar.markdown("**πŸ“§ Email:** singhshwet05@gmail.com")
110
 
111
+ # Footer
112
+ st.markdown("Made with ❀️ using Streamlit")