AIWorld / app.py
Vysakhan's picture
Update app.py
4217a01 verified
import gradio as gr
import joblib
import pandas as pd
# Load the model and encoders
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):
# Use the mappings to convert categorical values to numbers
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]
# Prepare the input data for prediction
new_match = pd.DataFrame({
'Venue': [venue_encoded],
'Match_Type': [match_type_encoded],
'Team_Batting': [team_batting_encoded],
'Team_Bowling': [team_bowling_encoded]
})
# Make prediction
predicted_score = model.predict(new_match)
return round(predicted_score[0])
# Create Gradio interface
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."
)
# Launch the interface
if __name__ == "__main__":
interface.launch()