Spaces:
Running
Running
import streamlit as st | |
import pandas as pd | |
import matplotlib.pyplot as plt | |
import seaborn as sns | |
# Set page configuration | |
st.set_page_config(page_title="Career Insights", layout="wide") | |
# Light-Themed Background with Light Blue Color | |
page_bg = """ | |
<style> | |
body { | |
background-color: #E3F2FD; | |
} | |
[data-testid="stAppViewContainer"] { | |
background-color: #E3F2FD; | |
} | |
[data-testid="stSidebar"] { | |
background-color: #ffffff; | |
border-right: 1px solid #ddd; | |
} | |
h1, h2, h3, h4, h5, h6 { | |
color: #333333 !important; | |
} | |
.stTextInput>div>div>input { | |
background-color: white; | |
color: black; | |
border-radius: 5px; | |
padding: 10px; | |
border: 1px solid #ccc; | |
} | |
</style> | |
""" | |
st.markdown(page_bg, unsafe_allow_html=True) | |
# App Title | |
st.title("🏏Career Insights") | |
# Load data | |
file_path = "Final.csv" # Ensure this file exists in your working directory | |
df = pd.read_csv(file_path) | |
# Enter Player Name | |
player_input = st.text_input("Enter Player Name:") | |
if player_input: | |
selected_player = player_input.strip() | |
if selected_player in df["Player"].values: | |
player_data = df[df["Player"] == selected_player].iloc[0] | |
# Pie Chart - Matches Played Across Formats | |
matches = [ | |
player_data["Matches_Test"], | |
player_data["Matches_ODI"], | |
player_data["Matches_T20"], | |
player_data["Matches_IPL"] | |
] | |
labels = ["Test", "ODI", "T20", "IPL"] | |
fig, ax = plt.subplots() | |
ax.pie(matches, labels=labels, autopct="%1.1f%%", startangle=90, | |
colors=["#87CEEB", "#90EE90", "#FFA07A", "#9370DB"]) | |
ax.set_title(f"Matches Played by {selected_player}", fontsize=14) | |
st.pyplot(fig) | |
# Bar Chart - Runs Scored in Different Formats | |
batting_runs = [ | |
player_data["batting_Runs_Test"], | |
player_data["batting_Runs_ODI"], | |
player_data["batting_Runs_T20"], | |
player_data["batting_Runs_IPL"] | |
] | |
fig, ax = plt.subplots() | |
ax.bar(labels, batting_runs, color=["#FFD700", "#008000", "#1E90FF", "#FF4500"]) | |
ax.set_ylabel("Runs Scored", fontsize=12) | |
ax.set_title(f"Runs Scored by {selected_player}", fontsize=14) | |
st.pyplot(fig) | |
# Line Chart - Batting Average Over Formats | |
batting_average = [ | |
player_data["batting_Runs_Test"] / max(1, player_data["batting_Innings_Test"]), | |
player_data["batting_Runs_ODI"] / max(1, player_data["batting_Innings_ODI"]), | |
player_data["batting_Runs_T20"] / max(1, player_data["batting_Innings_T20"]), | |
player_data["batting_Runs_IPL"] / max(1, player_data["batting_Innings_IPL"]) | |
] | |
fig, ax = plt.subplots() | |
ax.plot(labels, batting_average, marker='o', linestyle='-', color='#FFA500', linewidth=2) | |
ax.set_ylabel("Batting Average", fontsize=12) | |
ax.set_title(f"Batting Average of {selected_player}", fontsize=14) | |
st.pyplot(fig) | |
else: | |
st.error("🚨 Player not found! Please enter a valid player name.") | |