Spaces:
Sleeping
Sleeping
ParthCodes
commited on
Commit
•
b4d716b
1
Parent(s):
7515e94
Update main.py
Browse files
main.py
CHANGED
@@ -1,58 +1,90 @@
|
|
1 |
from flask import Flask, request
|
2 |
import joblib
|
3 |
-
import
|
4 |
from flask_cors import CORS
|
5 |
|
6 |
-
|
7 |
app = Flask(__name__)
|
8 |
-
app.static_folder = 'static'
|
9 |
-
app.static_url_path = '/static'
|
10 |
|
11 |
-
app.secret_key = "
|
12 |
|
13 |
CORS(app)
|
14 |
|
15 |
-
|
16 |
# Load the model
|
17 |
-
model = joblib.load('
|
18 |
|
19 |
-
# Load the encoder
|
20 |
-
encoder = joblib.load('encoder.pkl')
|
21 |
|
22 |
@app.route('/', methods=['GET'])
|
23 |
def main():
|
24 |
-
return {'message': '
|
25 |
|
26 |
|
27 |
@app.route('/prediction', methods=['POST'])
|
28 |
def prediction():
|
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 |
if __name__ == '__main__':
|
|
|
1 |
from flask import Flask, request
|
2 |
import joblib
|
3 |
+
import numpy as np
|
4 |
from flask_cors import CORS
|
5 |
|
|
|
6 |
app = Flask(__name__)
|
|
|
|
|
7 |
|
8 |
+
app.secret_key = "cricktech-abhi-2023"
|
9 |
|
10 |
CORS(app)
|
11 |
|
|
|
12 |
# Load the model
|
13 |
+
model = joblib.load('dataset/world/cricket_world_cup_score_prediction_model.pkl')
|
14 |
|
|
|
|
|
15 |
|
16 |
@app.route('/', methods=['GET'])
|
17 |
def main():
|
18 |
+
return {'message': 'Welcome to CrickTech!!'}
|
19 |
|
20 |
|
21 |
@app.route('/prediction', methods=['POST'])
|
22 |
def prediction():
|
23 |
+
if request.method == 'POST':
|
24 |
+
data = request.get_json()
|
25 |
+
batting_team = data.get('batting_team')
|
26 |
+
bowling_team = data.get('bowling_team')
|
27 |
+
score = score_predict(batting_team, bowling_team, runs=data.get('total_runs'), wickets=data.get('total_wickets'), overs=data.get('overs'), runs_last_5_overs=data.get('runs_last_5_overs'), wickets_last_5_overs=data.get('wickets_last_5_overs'))
|
28 |
+
return score
|
29 |
+
|
30 |
+
|
31 |
+
def score_predict(batting_team, bowling_team, runs, wickets, overs, runs_last_5_overs, wickets_last_5_overs):
|
32 |
+
prediction_array = []
|
33 |
+
# Batting Team
|
34 |
+
if batting_team == 'Afghanistan':
|
35 |
+
prediction_array = prediction_array + [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
|
36 |
+
elif batting_team == 'Australia':
|
37 |
+
prediction_array = prediction_array + [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
|
38 |
+
elif batting_team == 'Bangladesh':
|
39 |
+
prediction_array = prediction_array + [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0]
|
40 |
+
elif batting_team == 'England':
|
41 |
+
prediction_array = prediction_array + [0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0]
|
42 |
+
elif batting_team == 'India':
|
43 |
+
prediction_array = prediction_array + [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0]
|
44 |
+
elif batting_team == 'Ireland':
|
45 |
+
prediction_array = prediction_array + [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0]
|
46 |
+
elif batting_team == 'New Zealand':
|
47 |
+
prediction_array = prediction_array + [0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0]
|
48 |
+
elif batting_team == 'Pakistan':
|
49 |
+
prediction_array = prediction_array + [0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0]
|
50 |
+
elif batting_team == 'South Africa':
|
51 |
+
prediction_array = prediction_array + [0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0]
|
52 |
+
elif batting_team == 'Sri Lanka':
|
53 |
+
prediction_array = prediction_array + [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0]
|
54 |
+
elif batting_team == 'West Indies':
|
55 |
+
prediction_array = prediction_array + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0]
|
56 |
+
elif batting_team == 'Zimbabwe':
|
57 |
+
prediction_array = prediction_array + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]
|
58 |
+
# Bowling Team
|
59 |
+
if bowling_team == 'Afghanistan':
|
60 |
+
prediction_array = prediction_array + [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
|
61 |
+
elif bowling_team == 'Australia':
|
62 |
+
prediction_array = prediction_array + [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
|
63 |
+
elif bowling_team == 'Bangladesh':
|
64 |
+
prediction_array = prediction_array + [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0]
|
65 |
+
elif bowling_team == 'England':
|
66 |
+
prediction_array = prediction_array + [0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0]
|
67 |
+
elif bowling_team == 'India':
|
68 |
+
prediction_array = prediction_array + [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0]
|
69 |
+
elif bowling_team == 'Ireland':
|
70 |
+
prediction_array = prediction_array + [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0]
|
71 |
+
elif bowling_team == 'New Zealand':
|
72 |
+
prediction_array = prediction_array + [0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0]
|
73 |
+
elif bowling_team == 'Pakistan':
|
74 |
+
prediction_array = prediction_array + [0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0]
|
75 |
+
elif bowling_team == 'South Africa':
|
76 |
+
prediction_array = prediction_array + [0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0]
|
77 |
+
elif bowling_team == 'Sri Lanka':
|
78 |
+
prediction_array = prediction_array + [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0]
|
79 |
+
elif bowling_team == 'West Indies':
|
80 |
+
prediction_array = prediction_array + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0]
|
81 |
+
elif bowling_team == 'Zimbabwe':
|
82 |
+
prediction_array = prediction_array + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]
|
83 |
+
|
84 |
+
prediction_array = prediction_array + [overs, runs, wickets, runs_last_5_overs, wickets_last_5_overs]
|
85 |
+
prediction_array = np.array([prediction_array])
|
86 |
+
pred = model.predict(prediction_array)
|
87 |
+
return int(round(pred[0]))
|
88 |
|
89 |
|
90 |
if __name__ == '__main__':
|