Spaces:
Configuration error

File size: 4,076 Bytes
8144fe4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
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("<h2 style='text-align: center;'>Team Images</h2>", unsafe_allow_html=True)

col1, col2 = st.columns(2)

teams = sorted(teams)

if 'index' not in st.session_state:
    st.session_state.index = 0

def autoplay_teams():
    while True:
        team = teams[st.session_state.index]
        image_path = f'team_images/{team}.jpg'
        if os.path.exists(image_path):
            image = Image.open(image_path)
            col1.image(image, caption=team, use_column_width=True)
            col2.image(image, caption=team, use_column_width=True)
        st.session_state.index = (st.session_state.index + 1) % len(teams)
        time.sleep(2)  # wait for 2 seconds

autoplay_thread = threading.Thread(target=autoplay_teams)
autoplay_thread.daemon = True
autoplay_thread.start()