Vysakhan commited on
Commit
f7aad3b
1 Parent(s): 01abd58

Upload 3 files

Browse files
Files changed (3) hide show
  1. app.py +63 -0
  2. random_forest_model (2).joblib +3 -0
  3. requirements.txt +5 -0
app.py ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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_mapping = {
8
+ "MCG": 0,
9
+ "Eden Gardens": 1,
10
+ "Lords": 2
11
+ }
12
+
13
+ match_type_mapping = {
14
+ "ODI": 0,
15
+ "T20": 1,
16
+ "Test": 2
17
+ }
18
+
19
+ team_mapping = {
20
+ "India": 0,
21
+ "Australia": 1,
22
+ "England": 2,
23
+ "Pakistan": 3
24
+ }
25
+
26
+ def predict_score(venue, match_type, team_batting, team_bowling):
27
+
28
+ # Use the mappings to convert categorical values to numbers
29
+ venue_encoded = venue_mapping[venue]
30
+ match_type_encoded = match_type_mapping[match_type]
31
+ team_batting_encoded = team_mapping[team_batting]
32
+ team_bowling_encoded = team_mapping[team_bowling]
33
+
34
+ # Prepare the input data for prediction
35
+ new_match = pd.DataFrame({
36
+ 'Venue': [venue_encoded],
37
+ 'Match_Type': [match_type_encoded],
38
+ 'Team_Batting': [team_batting_encoded],
39
+ 'Team_Bowling': [team_bowling_encoded]
40
+ })
41
+
42
+ # Make prediction
43
+ predicted_score = model.predict(new_match)
44
+ return round(predicted_score[0])
45
+
46
+
47
+ # Create Gradio interface
48
+ interface = gr.Interface(
49
+ fn=predict_score,
50
+ inputs=[
51
+ gr.Dropdown(['MCG', 'Eden Gardens', 'Wankhede'], label='Venue'),
52
+ gr.Dropdown(['ODI', 'T20'], label='Match Type'),
53
+ gr.Dropdown(['India', 'Australia', 'England'], label='Team Batting'),
54
+ gr.Dropdown(['Australia', 'India', 'England'], label='Team Bowling')
55
+ ],
56
+ outputs=gr.Textbox(label="Predicted Score"),
57
+ title="Cricket Match Score Predictor",
58
+ description="Enter match details to predict the final score."
59
+ )
60
+
61
+ # Launch the interface
62
+ if __name__ == "__main__":
63
+ interface.launch()
random_forest_model (2).joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:88251fed428a09f471a79da8191caf9595d752b087a11e084f7ce8715570a498
3
+ size 3121681
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ gradio
2
+ pandas
3
+ scikit-learn
4
+ joblib
5
+ numpy