Spaces:
Sleeping
Sleeping
| license: mit | |
| title: Cricket AI Predictor | |
| sdk: docker | |
| app_file: app.py | |
| emoji: π | |
| colorFrom: blue | |
| colorTo: purple | |
| pinned: false | |
| # π Cricket AI Predictor | |
| A full-stack IPL ball-by-ball prediction system powered by 4 pre-trained XGBoost models. | |
| ## Features | |
| | Page | Description | | |
| |------|-------------| | |
| | **Predict** | Input match data β get dot ball %, boundary %, run distribution, expected runs, and win probability | | |
| | **Simulate** | Ball-by-ball T20 innings simulation with live ML predictions and win probability chart | | |
| | **Model Info** | Technical details, feature tables, label encodings, and API reference | | |
| --- | |
| ## Quick Start in VS Code | |
| ### Step 1 β Open the project | |
| ``` | |
| File β Open Folder β select cricket_predictor/ | |
| ``` | |
| ### Step 2 β Create a virtual environment | |
| Open the **VS Code Terminal** (`Ctrl+\``) and run: | |
| **Windows:** | |
| ```bash | |
| python -m venv venv | |
| venv\Scripts\activate | |
| ``` | |
| **Mac / Linux:** | |
| ```bash | |
| python3 -m venv venv | |
| source venv/bin/activate | |
| ``` | |
| ### Step 3 β Install dependencies | |
| ```bash | |
| pip install -r requirements.txt | |
| ``` | |
| ### Step 4 β Run the app | |
| **Option A β VS Code Debugger (recommended):** | |
| - Press `F5` or go to **Run β Start Debugging** | |
| - Select **"Run Flask App"** configuration | |
| **Option B β Terminal:** | |
| ```bash | |
| python app.py | |
| ``` | |
| ### Step 5 β Open in browser | |
| ``` | |
| http://127.0.0.1:5000 | |
| ``` | |
| --- | |
| ## Project Structure | |
| ``` | |
| cricket_predictor/ | |
| β | |
| βββ app.py # Flask application & routes | |
| β | |
| βββ models/ # Pre-trained XGBoost model files | |
| β βββ DotBall.pkl | |
| β βββ BoundaryModel.pkl | |
| β βββ RunPrediction.pkl | |
| β βββ IPLchasingTeamWin.pkl | |
| β | |
| βββ utils/ | |
| β βββ __init__.py | |
| β βββ predictor.py # CricketPredictor class (loads + runs all 4 models) | |
| β βββ encoders.py # Team/venue label encoding maps + phase logic | |
| β | |
| βββ templates/ | |
| β βββ base.html # Shared navbar & layout | |
| β βββ index.html # Prediction dashboard | |
| β βββ simulate.html # Match simulation page | |
| β βββ model_info.html # Model details & API docs | |
| β | |
| βββ static/ | |
| β βββ css/ | |
| β βββ style.css # Full application stylesheet | |
| β | |
| βββ .vscode/ | |
| β βββ launch.json # F5 debugger config | |
| β βββ settings.json # Editor & Python settings | |
| β βββ extensions.json # Recommended extensions | |
| β | |
| βββ requirements.txt | |
| βββ README.md | |
| ``` | |
| --- | |
| ## Models | |
| | File | Task | Input Features | Classes | | |
| |------|------|---------------|---------| | |
| | `DotBall.pkl` | Dot ball probability | 18 | Binary (0/1) | | |
| | `BoundaryModel.pkl` | Boundary probability | 18 | Binary (0/1) | | |
| | `RunPrediction.pkl` | Run distribution | 18 | Multi-class (0β5) | | |
| | `IPLchasingTeamWin.pkl` | Win probability (2nd inn.) | 8 | Binary (0/1) | | |
| ### Ball model features (18) | |
| `striker_enc` Β· `bowler_enc` Β· `batting_team_enc` Β· `bowling_team_enc` Β· `venue_enc` Β· `over` Β· `ball_in_over` Β· `phase` Β· `current_score` Β· `wickets_fallen` Β· `run_rate` Β· `prev_runs` Β· `prev_wicket` Β· `last_6_runs` Β· `last_12_runs` Β· `last_6_wickets` Β· `batter_sr` Β· `bowler_eco` | |
| ### Win model features (8) | |
| `batting_team` Β· `bowling_team` Β· `venue` Β· `innings` Β· `current_score` Β· `wickets_fallen` Β· `balls_remaining` Β· `run_rate` | |
| --- | |
| ## API Endpoints | |
| ### `POST /api/predict` | |
| ```json | |
| { | |
| "batting_team": "Mumbai Indians", | |
| "bowling_team": "Chennai Super Kings", | |
| "venue": "Wankhede Stadium", | |
| "innings": 1, | |
| "over": 14, | |
| "ball_in_over": 3, | |
| "current_score": 110, | |
| "wickets_fallen": 2, | |
| "batter_sr": 148, | |
| "bowler_eco": 7.4, | |
| "last_6_runs": 11, | |
| "last_12_runs": 19 | |
| } | |
| ``` | |
| **Response:** | |
| ```json | |
| { | |
| "dot_ball_prob": 24.3, | |
| "boundary_prob": 38.7, | |
| "expected_runs": 2.41, | |
| "run_distribution": [0.24, 0.22, 0.08, 0.06, 0.28, 0.12], | |
| "win_probability": null, | |
| "phase": "Middle Overs (Ov 7-15)", | |
| "run_rate": 7.86 | |
| } | |
| ``` | |
| ### `GET /api/meta` | |
| Returns available teams and venues. | |
| ### `GET /api/health` | |
| Returns loaded model names and status. | |
| --- | |
| ## IPL Teams Supported | |
| Chennai Super Kings Β· Delhi Capitals Β· Gujarat Titans Β· Kolkata Knight Riders Β· | |
| Lucknow Super Giants Β· Mumbai Indians Β· Punjab Kings Β· Rajasthan Royals Β· | |
| Royal Challengers Bangalore Β· Sunrisers Hyderabad | |
| ## Venues Supported | |
| Arun Jaitley Stadium Β· Brabourne Stadium Β· DY Patil Stadium Β· Eden Gardens Β· | |
| Feroz Shah Kotla Β· MA Chidambaram Stadium Β· MCA Stadium Β· | |
| Maharashtra Cricket Association Stadium Β· Narendra Modi Stadium Β· | |
| Punjab Cricket Association Stadium Β· Rajiv Gandhi International Stadium Β· | |
| Sawai Mansingh Stadium Β· Wankhede Stadium |