import streamlit as st import pickle import pandas as pd from PIL import Image import os # Define teams and cities teams = [ 'Sunrisers Hyderabad', 'Mumbai Indians', 'Royal Challengers Bangalore', 'Kolkata Knight Riders', 'Kings XI Punjab', 'Chennai Super Kings', 'Rajasthan Royals', 'Delhi Capitals' ] cities = [ 'Hyderabad', 'Bangalore', 'Mumbai', 'Indore', 'Kolkata', 'Delhi', 'Chandigarh', 'Jaipur', 'Chennai', 'Cape Town', 'Port Elizabeth', 'Durban', 'Centurion', 'East London', 'Johannesburg', 'Kimberley', 'Bloemfontein', 'Ahmedabad', 'Cuttack', 'Nagpur', 'Dharamsala', 'Visakhapatnam', 'Pune', 'Raipur', 'Ranchi', 'Abu Dhabi', 'Sharjah', 'Mohali', 'Bengaluru' ] # Load the fitted model with open('pipe.pkl', 'rb') as file: pipe = pickle.load(file) # Ensure the loaded object is a pipeline with the 'predict_proba' method if not hasattr(pipe, 'predict_proba'): st.error("The loaded model is not a valid pipeline object.") else: st.title('IPL Win Predictor') # Create columns for inputs col1, col2 = st.columns(2) with col1: batting_team = st.selectbox('Select the batting team', sorted(teams)) with col2: bowling_team = st.selectbox('Select the bowling team', sorted(teams)) # Select host city selected_city = st.selectbox('Select host city', sorted(cities)) # Input for target score target = st.number_input('Target') # Create columns for score, overs, and wickets col3, col4, col5 = st.columns(3) with col3: score = st.number_input('Score') with col4: overs = st.number_input('Overs completed') with col5: wickets = st.number_input('Wickets out') # Button to predict probability if st.button('Predict Probability'): runs_left = target - score balls_left = 120 - (overs * 6) wickets_left = 10 - wickets crr = score / overs if overs > 0 else 0 rrr = (runs_left * 6) / balls_left if balls_left > 0 else 0 input_df = pd.DataFrame({ 'batting_team': [batting_team], 'bowling_team': [bowling_team], 'city': [selected_city], 'runs_left': [runs_left], 'balls_left': [balls_left], 'wickets': [wickets_left], 'total_runs_x': [target], 'crr': [crr], 'rrr': [rrr] }) result = pipe.predict_proba(input_df) loss = result[0][0] win = result[0][1] st.header(f"{batting_team} - {win*100:.2f}%") st.header(f"{bowling_team} - {loss*100:.2f}%") # Show image of the team with the highest probability winning_team = batting_team if win > loss else bowling_team image_path = f'team_images/{winning_team}.jpg' if os.path.exists(image_path): image = Image.open(image_path) st.image(image, caption=winning_team, use_column_width=True) else: st.warning(f"No image found for {winning_team}") import time import os from PIL import Image import threading # ... (rest of the code remains the same) # Autoplay team images st.markdown("