Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- main.py +91 -0
- requirements.txt +6 -0
main.py
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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('cricket_world_cup_score_prediction_model.pkl')
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
@app.route('/', methods=['GET'])
|
| 17 |
+
def main():
|
| 18 |
+
return "Welcome to CrickTech!! This is the API endpoint for ICC World Cup Prediction Model. Due to its large size, and limited computational power on each space, I worked around to create an API endpoint that relays the prediction data to the main Gradio Interface. NOTE: Gradio Built was interfering with the models large chunks due to which it caused inncorrect predictions."
|
| 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 {'success': True, 'prediction': str(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__':
|
| 91 |
+
app.run()
|
requirements.txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
flask
|
| 2 |
+
flask-cors
|
| 3 |
+
gunicorn
|
| 4 |
+
numpy
|
| 5 |
+
joblib
|
| 6 |
+
scikit-learn
|