|
import gradio as gr |
|
import joblib |
|
import pandas as pd |
|
|
|
|
|
model = joblib.load('random_forest_model.joblib') |
|
venue_mapping = { |
|
"MCG": 0, |
|
"Eden Gardens": 1, |
|
"Lords": 2 |
|
} |
|
|
|
match_type_mapping = { |
|
"ODI": 0, |
|
"T20": 1, |
|
"Test": 2 |
|
} |
|
|
|
team_mapping = { |
|
"India": 0, |
|
"Australia": 1, |
|
"England": 2, |
|
"Pakistan": 3 |
|
} |
|
|
|
def predict_score(venue, match_type, team_batting, team_bowling): |
|
|
|
|
|
venue_encoded = venue_mapping[venue] |
|
match_type_encoded = match_type_mapping[match_type] |
|
team_batting_encoded = team_mapping[team_batting] |
|
team_bowling_encoded = team_mapping[team_bowling] |
|
|
|
|
|
new_match = pd.DataFrame({ |
|
'Venue': [venue_encoded], |
|
'Match_Type': [match_type_encoded], |
|
'Team_Batting': [team_batting_encoded], |
|
'Team_Bowling': [team_bowling_encoded] |
|
}) |
|
|
|
|
|
predicted_score = model.predict(new_match) |
|
return round(predicted_score[0]) |
|
|
|
|
|
|
|
interface = gr.Interface( |
|
fn=predict_score, |
|
inputs=[ |
|
gr.Dropdown(['MCG', 'Eden Gardens', 'Wankhede'], label='Venue'), |
|
gr.Dropdown(['ODI', 'T20'], label='Match Type'), |
|
gr.Dropdown(['India', 'Australia', 'England'], label='Team Batting'), |
|
gr.Dropdown(['Australia', 'India', 'England'], label='Team Bowling') |
|
], |
|
outputs=gr.Textbox(label="Predicted Score"), |
|
title="Cricket Match Score Predictor", |
|
description="Enter match details to predict the final score." |
|
) |
|
|
|
|
|
if __name__ == "__main__": |
|
interface.launch() |
|
|