Cricket_playground / pages /winner_predictor.py
zoya23's picture
Update pages/winner_predictor.py
8e36782 verified
import streamlit as st
import numpy as np
import joblib
# Load your trained winner prediction model
model = joblib.load("winner_prediction_model.pkl") # Update with your actual model file
st.title("Cricket Match Winner Prediction")
st.markdown("Enter team stats below to predict which team will win the match.")
# Team names (example teams)
teams = ['India', 'Australia', 'England', 'Pakistan', 'Afghanistan',
'South Africa', 'New Zealand', 'Sri Lanka', 'West Indies', 'Bangladesh']
# Select teams
team1 = st.selectbox("Select Team 1", teams)
team2 = st.selectbox("Select Team 2", [t for t in teams if t != team1])
st.subheader("๐Ÿ“ฅ Enter Stats for Team 1")
team1_batting = st.number_input("Team 1 Batting Score (e.g. total runs, or batting rating)", 0, 10000, 500)
team1_bowling = st.number_input("Team 1 Bowling Score (e.g. wickets or bowling rating)", 0, 500, 100)
st.subheader("๐Ÿ“ฅ Enter Stats for Team 2")
team2_batting = st.number_input("Team 2 Batting Score", 0, 10000, 480)
team2_bowling = st.number_input("Team 2 Bowling Score", 0, 500, 90)
# Calculate combined score (you can change the weight if needed)
def combined_score(batting, bowling, weight=10):
return batting + (bowling * weight)
team1_combined = combined_score(team1_batting, team1_bowling)
team2_combined = combined_score(team2_batting, team2_bowling)
# Prepare input features for the model
features = np.array([[team1_batting, team1_bowling, team1_combined,
team2_batting, team2_bowling, team2_combined]])
# Predict button
if st.button("๐Ÿ”ฎ Predict Winner"):
prediction = model.predict(features)[0]
st.success(f"๐Ÿ **Predicted Winner: {team1 if prediction == 1 else team2}**")
st.subheader("๐Ÿ“Š Team Comparison")
st.write({
f"{team1} - Batting": team1_batting,
f"{team1} - Bowling": team1_bowling,
f"{team1} - Combined": team1_combined,
f"{team2} - Batting": team2_batting,
f"{team2} - Bowling": team2_bowling,
f"{team2} - Combined": team2_combined,
})
# Footer
st.markdown("---")