Update app.py
Browse files
app.py
CHANGED
|
@@ -1,55 +1,42 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
| 3 |
import base64
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
-
#
|
| 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 |
-
|
|
|
|
| 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(
|
|
|
|
| 31 |
|
| 32 |
-
#
|
| 33 |
-
st.title("
|
| 34 |
|
| 35 |
-
#
|
| 36 |
-
st.
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
-
|
| 42 |
-
- **
|
| 43 |
-
- **
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 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 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
|
| 65 |
st.markdown("---")
|
| 66 |
|
| 67 |
-
#
|
| 68 |
-
st.
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
|
| 78 |
st.markdown("---")
|
| 79 |
|
| 80 |
-
#
|
| 81 |
st.sidebar.markdown("### π Author Details")
|
| 82 |
st.sidebar.markdown("**π€ Name:** Shweta Singh")
|
| 83 |
-
st.sidebar.markdown("**π§ Email:** singhshwet05@gmail.com")
|
| 84 |
|
| 85 |
-
|
|
|
|
|
|
| 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")
|