Vysakhan commited on
Commit
6022449
1 Parent(s): cfb16a7

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -0
app.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import joblib
3
+ import pandas as pd
4
+
5
+ # Load the model and encoders
6
+ model = joblib.load('random_forest_model.joblib')
7
+ venue_encoder = joblib.load('venue_encoder.joblib')
8
+ match_type_encoder = joblib.load('match_type_encoder.joblib')
9
+ team_batting_encoder = joblib.load('team_batting_encoder.joblib')
10
+ team_bowling_encoder = joblib.load('team_bowling_encoder.joblib')
11
+
12
+ def predict_score(venue, match_type, team_batting, team_bowling):
13
+ # Preprocess inputs
14
+ venue_encoded = venue_encoder.transform([venue])[0]
15
+ match_type_encoded = match_type_encoder.transform([match_type])[0]
16
+ team_batting_encoded = team_batting_encoder.transform([team_batting])[0]
17
+ team_bowling_encoded = team_bowling_encoder.transform([team_bowling])[0]
18
+
19
+ # Prepare input for the model
20
+ input_data = pd.DataFrame({
21
+ 'Venue': [venue_encoded],
22
+ 'Match_Type': [match_type_encoded],
23
+ 'Team_Batting': [team_batting_encoded],
24
+ 'Team_Bowling': [team_bowling_encoded]
25
+ })
26
+
27
+ # Predict and return score
28
+ predicted_score = model.predict(input_data)[0]
29
+ return round(predicted_score)
30
+
31
+ # Create Gradio interface
32
+ interface = gr.Interface(
33
+ fn=predict_score,
34
+ inputs=[
35
+ gr.inputs.Dropdown(['MCG', 'Eden Gardens', 'Wankhede'], label='Venue'),
36
+ gr.inputs.Dropdown(['ODI', 'T20'], label='Match Type'),
37
+ gr.inputs.Dropdown(['India', 'Australia', 'England'], label='Team Batting'),
38
+ gr.inputs.Dropdown(['Australia', 'India', 'England'], label='Team Bowling')
39
+ ],
40
+ outputs=gr.outputs.Textbox(label="Predicted Score"),
41
+ title="Cricket Match Score Predictor",
42
+ description="Enter match details to predict the final score."
43
+ )
44
+
45
+ # Launch the interface
46
+ if __name__ == "__main__":
47
+ interface.launch()