-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
106 lines (85 loc) · 3.33 KB
/
main.py
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
import base64
import streamlit as st
import pickle
# from sklearn.metrics import accuracy_score
import pandas as pd
@st.cache_data
def get_img_as_base64(file):
with open(file, "rb") as f:
data = f.read()
return base64.b64encode(data).decode()
img = get_img_as_base64("background.jpg")
# data:image/png;base64,{img}
page_bg_img = f"""
<style>
[data-testid="stAppViewContainer"] > .main {{
background-image: url("data:image/png;base64,{img}");
width: 100%;
height:100%
background-repeat: no-repeat;
background-attachment: fixed;
background-size: cover;
}}
[data-testid="stSidebar"] > div:first-child {{
background-image: url("data:image/png;base64,{img}");
background-position: center;
background-repeat: no-repeat;
background-attachment: fixed;
}}
[data-testid="stHeader"] {{
background: rgba(0,0,0,0);
}}
[data-testid="stToolbar"] {{
right: 2rem;
}}
</style>
"""
cities = ['Mumbai', 'Delhi', 'Chennai', 'Abu Dhabi', 'Visakhapatnam', 'Hyderabad', 'Chandigarh',
'Ahmedabad', 'Bangalore', 'Jaipur', 'Kolkata', 'Port Elizabeth', 'Cuttack', 'Navi Mumbai',
'Centurion', 'Bengaluru', 'Pune', 'Johannesburg', 'Dubai', 'Cape Town', 'Lucknow', 'Durban',
'Dharamsala', 'Indore', 'East London', 'Sharjah', 'Guwahati', 'Raipur', 'Ranchi', 'Nagpur',
'Kimberley', 'Bloemfontein']
teams = ['Kolkata Knight Riders', 'Chennai Super Kings', 'Punjab Kings', 'Rajasthan Royals', 'Mumbai Indians',
'Delhi Capitals', 'Royal Challengers Bangalore', 'Sunrisers Hyderabad', 'Lucknow Super Giants',
'Gujarat Titans']
pipe = pickle.load(open('pipe.pkl','rb'))
st.markdown(page_bg_img, unsafe_allow_html=True)
st.markdown("""
# **IPL VICTORY PREDICTOR**
""")
# st.title("IPL Victory Predictor")
col1, col2 = st.columns(2)
with col1:
batting_team = st.selectbox('Select Batting Team',teams)
with col2:
if batting_team == '--- select ---':
bowling_team = st.selectbox('Select Bowling Team', teams)
else:
filtered_teams = [team for team in teams if team != batting_team]
bowling_team = st.selectbox('Select Bowling Team', filtered_teams)
seleted_city = st.selectbox('Select Venue',cities)
target = st.number_input('Target')
col1,col2,col3 = st.columns(3)
with col1:
score = st.number_input('Score')
with col2:
overs = st.number_input("Over Completed")
with col3:
wickets = st.number_input("wicktes down")
if st.button('Predict Winning Probability'):
try:
runs_left = target - score
balls_left = 120 - (overs*6)
wickets = 10-wickets
crr = score/overs
rrr = runs_left/(balls_left/6)
input_data = pd.DataFrame({'batting_team':[batting_team],'bowling_team':[bowling_team],
'city':[seleted_city],'runs_left':[runs_left],'balls_left':[balls_left],
'wickets_remaining':[wickets],'total_runs_x':[target],'crr':[crr],'rrr':[rrr]})
result = pipe.predict_proba(input_data)
loss = result[0][0]
win = result[0][1]
st.header(batting_team + " = "+str(round(win*100)) + "%")
st.header(bowling_team + " = "+str(round(loss*100)) + "%")
except:
st.header("Some error occured.. Please check you inputs !!")