from flask import Flask, request import joblib import numpy as np from flask_cors import CORS app = Flask(__name__) app.secret_key = "cricktech-abhi-2023" CORS(app) # Load the model model = joblib.load('cricket_world_cup_score_prediction_model.pkl') @app.route('/', methods=['GET']) def main(): return {'message': 'Welcome to CrickTech!!'} @app.route('/prediction', methods=['POST']) def prediction(): if request.method == 'POST': data = request.get_json() batting_team = data.get('batting_team') bowling_team = data.get('bowling_team') 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')) return {'success': True, 'prediction': str(score)} def score_predict(batting_team, bowling_team, runs, wickets, overs, runs_last_5_overs, wickets_last_5_overs): prediction_array = [] # Batting Team if batting_team == 'Afghanistan': prediction_array = prediction_array + [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] elif batting_team == 'Australia': prediction_array = prediction_array + [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] elif batting_team == 'Bangladesh': prediction_array = prediction_array + [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0] elif batting_team == 'England': prediction_array = prediction_array + [0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0] elif batting_team == 'India': prediction_array = prediction_array + [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0] elif batting_team == 'Ireland': prediction_array = prediction_array + [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0] elif batting_team == 'New Zealand': prediction_array = prediction_array + [0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0] elif batting_team == 'Pakistan': prediction_array = prediction_array + [0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0] elif batting_team == 'South Africa': prediction_array = prediction_array + [0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0] elif batting_team == 'Sri Lanka': prediction_array = prediction_array + [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0] elif batting_team == 'West Indies': prediction_array = prediction_array + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0] elif batting_team == 'Zimbabwe': prediction_array = prediction_array + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1] # Bowling Team if bowling_team == 'Afghanistan': prediction_array = prediction_array + [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] elif bowling_team == 'Australia': prediction_array = prediction_array + [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] elif bowling_team == 'Bangladesh': prediction_array = prediction_array + [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0] elif bowling_team == 'England': prediction_array = prediction_array + [0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0] elif bowling_team == 'India': prediction_array = prediction_array + [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0] elif bowling_team == 'Ireland': prediction_array = prediction_array + [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0] elif bowling_team == 'New Zealand': prediction_array = prediction_array + [0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0] elif bowling_team == 'Pakistan': prediction_array = prediction_array + [0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0] elif bowling_team == 'South Africa': prediction_array = prediction_array + [0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0] elif bowling_team == 'Sri Lanka': prediction_array = prediction_array + [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0] elif bowling_team == 'West Indies': prediction_array = prediction_array + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0] elif bowling_team == 'Zimbabwe': prediction_array = prediction_array + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1] prediction_array = prediction_array + [overs, runs, wickets, runs_last_5_overs, wickets_last_5_overs] prediction_array = np.array([prediction_array]) pred = model.predict(prediction_array) return int(round(pred[0])) if __name__ == '__main__': app.run()