|
import gradio as gr |
|
import joblib |
|
import numpy as np |
|
|
|
|
|
model = joblib.load('cricket_score_prediction_model.pkl') |
|
|
|
|
|
inputs = [ |
|
gr.Dropdown( |
|
choices=['Afghanistan', 'Australia', 'Bangladesh', 'England', 'India', 'Ireland', 'New Zealand', 'Pakistan', |
|
'South Africa', 'Sri Lanka', 'West Indies', 'Zimbabwe'], |
|
label="Batting Team" |
|
), |
|
gr.Dropdown( |
|
choices=['Afghanistan', 'Australia', 'Bangladesh', 'England', 'India', 'Ireland', 'New Zealand', 'Pakistan', |
|
'South Africa', 'Sri Lanka', 'West Indies', 'Zimbabwe'], |
|
label="Bowling Team" |
|
), |
|
gr.Slider(minimum=0, maximum=400, step=1, label="Total Runs"), |
|
gr.Slider(minimum=0, maximum=11, step=1, label="Total Wickets"), |
|
gr.Slider(minimum=0.0, maximum=19.6, step=0.1, label="Overs"), |
|
gr.Slider(minimum=0, maximum=200, step=1, label="Runs last 5 overs"), |
|
gr.Slider(minimum=0, maximum=11,step=1, label="Wickets last 5 overs"), |
|
] |
|
|
|
|
|
|
|
def predict_accident( |
|
batting_team, |
|
bowling_team, |
|
total_runs, |
|
total_wickets, |
|
overs, |
|
runs_last_5_overs, |
|
wickets_last_5_overs |
|
): |
|
|
|
prediction_array = [] |
|
|
|
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] |
|
|
|
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 + [total_runs, total_wickets, overs, runs_last_5_overs, wickets_last_5_overs] |
|
prediction_array = np.array([prediction_array]) |
|
prediction = model.predict(prediction_array) |
|
|
|
label = f"Score Prediction: {(prediction[0])}" |
|
return label |
|
|
|
|
|
|
|
title = "T20i Score Prediction" |
|
description = "Predict the score of a T20i match." |
|
output_label = [gr.Label(num_top_classes=4)] |
|
gr.Interface( |
|
fn=predict_accident, |
|
inputs=inputs, |
|
outputs=output_label, |
|
title=title, |
|
description=description, |
|
).launch() |