-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
180 lines (153 loc) · 7.32 KB
/
app.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# Importing essential libraries
from flask import Flask, render_template, request
import joblib
import numpy as np
# Load the Random Forest CLassifier model
filename = "./products/pickle_files/XGB_deploy.joblib"
with open(filename, "rb") as f:
classifier = joblib.load(f)
# classifier = pickle.load(open(filename, "rb"))
app = Flask(__name__)
@app.route("/")
def home():
return render_template("index.html")
@app.route("/predict", methods=["POST"])
def predict():
temp_array = list()
if request.method == "POST":
overs = float(request.form["Overs"])
temp_array = temp_array + [overs]
wickets = int(request.form["Wickets-Fallen"])
temp_array = temp_array + [wickets]
runs = int(request.form["Runs-Scored"])
temp_array = temp_array + [runs]
runs_left = int(request.form["Runs-Left"])
temp_array = temp_array + [runs_left]
match_type = request.form["Match-Type"]
if match_type == "playoffs":
temp_array = temp_array + [1, 0]
elif match_type == "round-robin":
temp_array = temp_array + [0, 1]
venue = request.form["Venue"]
if venue == "Ahmedabad":
temp_array = temp_array + [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
elif venue == "Bangalore":
temp_array = temp_array + [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
elif venue == "Chennai":
temp_array = temp_array + [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
elif venue == "Cuttack":
temp_array = temp_array + [0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
elif venue == "Delhi":
temp_array = temp_array + [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
elif venue == "Dharamsala":
temp_array = temp_array + [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
elif venue == "Hyderabad":
temp_array = temp_array + [0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
elif venue == "Indore":
temp_array = temp_array + [0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0]
elif venue == "Kolkata":
temp_array = temp_array + [0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0]
elif venue == "Mohali":
temp_array = temp_array + [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0]
elif venue == "Mumbai":
temp_array = temp_array + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0]
elif venue == "Nagpur":
temp_array = temp_array + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0]
elif venue == "Pune":
temp_array = temp_array + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0]
elif venue == "Raipur":
temp_array = temp_array + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0]
elif venue == "Rajasthan":
temp_array = temp_array + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0]
elif venue == "Ranchi":
temp_array = temp_array + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0]
elif venue == "Visakhapatnam":
temp_array = temp_array + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]
inning = int(request.form["Inning"])
if inning == 1:
temp_array = temp_array + [1, 0]
elif inning == 2:
temp_array = temp_array + [0, 1]
batting_team = request.form["batting-team"]
if batting_team == "Chennai Super Kings":
temp_array = temp_array + [1, 0, 0, 0, 0, 0, 0, 0]
elif batting_team == "Delhi Capitals":
temp_array = temp_array + [0, 1, 0, 0, 0, 0, 0, 0]
elif batting_team == "Kings XI Punjab":
temp_array = temp_array + [0, 0, 1, 0, 0, 0, 0, 0]
elif batting_team == "Kolkata Knight Riders":
temp_array = temp_array + [0, 0, 0, 1, 0, 0, 0, 0]
elif batting_team == "Mumbai Indians":
temp_array = temp_array + [0, 0, 0, 0, 1, 0, 0, 0]
elif batting_team == "Rajasthan Royals":
temp_array = temp_array + [0, 0, 0, 0, 0, 1, 0, 0]
elif batting_team == "Royal Challengers Bangalore":
temp_array = temp_array + [0, 0, 0, 0, 0, 0, 1, 0]
elif batting_team == "Sunrisers Hyderabad":
temp_array = temp_array + [0, 0, 0, 0, 0, 0, 0, 1]
bowling_team = request.form["bowling-team"]
if bowling_team == "Chennai Super Kings":
temp_array = temp_array + [1, 0, 0, 0, 0, 0, 0, 0]
elif bowling_team == "Delhi Capitals":
temp_array = temp_array + [0, 1, 0, 0, 0, 0, 0, 0]
elif bowling_team == "Kings XI Punjab":
temp_array = temp_array + [0, 0, 1, 0, 0, 0, 0, 0]
elif bowling_team == "Kolkata Knight Riders":
temp_array = temp_array + [0, 0, 0, 1, 0, 0, 0, 0]
elif bowling_team == "Mumbai Indians":
temp_array = temp_array + [0, 0, 0, 0, 1, 0, 0, 0]
elif bowling_team == "Rajasthan Royals":
temp_array = temp_array + [0, 0, 0, 0, 0, 1, 0, 0]
elif bowling_team == "Royal Challengers Bangalore":
temp_array = temp_array + [0, 0, 0, 0, 0, 0, 1, 0]
elif bowling_team == "Sunrisers Hyderabad":
temp_array = temp_array + [0, 0, 0, 0, 0, 0, 0, 1]
batsman_type = request.form["Batsman-Type"]
if batsman_type == "Top":
temp_array = temp_array + [1, 0, 0]
elif batsman_type == "Middle":
temp_array = temp_array + [0, 1, 0]
elif batsman_type == "Tail":
temp_array = temp_array + [0, 0, 1]
nonstriker_type = request.form["Nonstriker-Type"]
if nonstriker_type == "Top":
temp_array = temp_array + [1, 0, 0]
elif nonstriker_type == "Middle":
temp_array = temp_array + [0, 1, 0]
elif nonstriker_type == "Tail":
temp_array = temp_array + [0, 0, 1]
bowler_type = request.form["Bowler-Type"]
if bowler_type == "Pacer":
temp_array = temp_array + [1, 0]
elif bowler_type == "Spinner":
temp_array = temp_array + [0, 1]
ball_length = request.form["Ball-Length"]
if ball_length == "Random":
temp_array = temp_array + [1, 0, 0, 0, 0, 0]
elif ball_length == "Full":
temp_array = temp_array + [0, 1, 0, 0, 0, 0]
elif ball_length == "Full-Toss":
temp_array = temp_array + [0, 0, 1, 0, 0, 0]
elif ball_length == "Good":
temp_array = temp_array + [0, 0, 0, 1, 0, 0]
elif ball_length == "Short":
temp_array = temp_array + [0, 0, 0, 0, 1, 0]
elif ball_length == "Yorker":
temp_array = temp_array + [0, 0, 0, 0, 0, 1]
data = np.array([temp_array])
my_prediction = int(classifier.predict(data)[0]) # classifier.predict_proba(data)
# map my_prediction to string value
if my_prediction == 0:
my_prediction = "Extras (Wide, No Ball, Bye, Leg Bye)"
elif my_prediction == 1:
my_prediction = "Dot Ball"
elif my_prediction == 2:
my_prediction = "Runs from the bat!"
elif my_prediction == 3:
my_prediction = "WICKET!"
return render_template(
"result.html",
my_prediction=my_prediction
)
if __name__ == "__main__":
app.run(debug=True)