--- 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