nitinnyadavvv commited on
Commit
f78cdae
·
verified ·
1 Parent(s): 90a9006

Upload 4 files

Browse files
Files changed (4) hide show
  1. app.py +58 -0
  2. requirements.txt +5 -0
  3. scaler.pkl +3 -0
  4. xgb_model.pkl +3 -0
app.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import pickle
3
+ import gradio as gr
4
+ from huggingface_hub import hf_hub_download
5
+
6
+ # Load model and scaler from Hugging Face Hub
7
+ model_path = hf_hub_download(repo_id="nitinnyadavvv/cricpred", filename="xgb_model.pkl")
8
+ scaler_path = hf_hub_download(repo_id="nitinnyadavvv/cricpred", filename="scaler.pkl")
9
+
10
+ model = pickle.load(open(model_path, "rb"))
11
+ scaler = pickle.load(open(scaler_path, "rb"))
12
+
13
+ def predict_run(over_number, ball_number, total_runs_till_now, total_wickets, current_run_rate,
14
+ last_3_balls_runs, last_over_runs, partnership_runs, current_over_score):
15
+ # Create input array
16
+ features = np.array([[over_number, ball_number, total_runs_till_now, total_wickets,
17
+ current_run_rate, last_3_balls_runs, last_over_runs,
18
+ partnership_runs, current_over_score]])
19
+
20
+ # Scale features
21
+ scaled_features = scaler.transform(features)
22
+
23
+ # Make prediction
24
+ prediction = model.predict(scaled_features)
25
+
26
+ # Return rounded prediction
27
+ return round(float(prediction[0]), 2)
28
+
29
+ # Create Gradio interface
30
+ with gr.Blocks() as demo:
31
+ gr.Markdown("# Cricket Run Predictor")
32
+ gr.Markdown("Predict runs scored in the current over using match context.")
33
+
34
+ with gr.Row():
35
+ with gr.Column():
36
+ over_number = gr.Number(label="Over Number (0-50)", value=10)
37
+ ball_number = gr.Number(label="Ball Number (1-6)", value=3)
38
+ total_runs_till_now = gr.Number(label="Total Runs Till Now", value=80)
39
+ total_wickets = gr.Number(label="Total Wickets (0-10)", value=2)
40
+ current_run_rate = gr.Number(label="Current Run Rate", value=5.5)
41
+ with gr.Column():
42
+ last_3_balls_runs = gr.Number(label="Last 3 Balls Runs", value=6)
43
+ last_over_runs = gr.Number(label="Last Over Runs", value=9)
44
+ partnership_runs = gr.Number(label="Partnership Runs", value=45)
45
+ current_over_score = gr.Number(label="Current Over Score", value=8)
46
+
47
+ predict_btn = gr.Button("Predict Runs")
48
+ output = gr.Number(label="Predicted Runs in This Over")
49
+
50
+ predict_btn.click(
51
+ fn=predict_run,
52
+ inputs=[over_number, ball_number, total_runs_till_now, total_wickets,
53
+ current_run_rate, last_3_balls_runs, last_over_runs,
54
+ partnership_runs, current_over_score],
55
+ outputs=output
56
+ )
57
+
58
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ gradio>=3.0
2
+ numpy
3
+ scikit-learn
4
+ xgboost
5
+ huggingface-hub
scaler.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4a5da4e3bf9d0cc512cf288db42ea5b3363cc14d16e37d77be277e78dcd48919
3
+ size 913
xgb_model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9fcde55d867fd98e85728d1f33c1eae894a18d89c6f8174d45eccfe4cab2bd8f
3
+ size 1406291