RAG-Based Cricket Analysis and Player Comparison
CricketAnalytica is a RAG-based cricket analysis and player comparison platform that combines API-based data retrieval with LLM-based analysis to compare player performances.
The application dynamically retrieves relevant player statistics through the ESPN API based on the comparison requested by the user. The retrieved data is then used as contextual information for the Google Gemini API, which generates a written statistical comparison from the available player data.
The current version focuses on comparing the batting performances of two players and presents their statistics in a simple and interactive interface.
CricketAnalytica is being developed as a broader cricket analysis platform, with the current implementation serving as the first version and providing a foundation for expanding into additional formats, bowling, fielding, advanced analysis, and improved models.
- Compare two cricket players
- Search for player information and statistics
- Compare batting performances
- View overall player statistics
- View home performance
- View overseas performance
- Compare runs, batting average, strike rate, hundreds, fifties, and highest score
- Highlight better statistical values between players
- Generate a written statistical comparison
- Responsive and interactive web interface
- Loading animation while player data and analysis are being retrieved
The system is divided into a frontend, backend, data retrieval layer, and analysis component.
CricketAnalytica
|
+-----------------------+-----------------------+
| | |
v v v
Frontend Flask Backend External Services
| | |
| | +--------+--------+
| | | |
v v v v
HTML/CSS/JS app.py ESPN API Gemini API
|
v
Retrieval Layer
|
v
Relevant Player Data
|
v
Retrieved Context
|
v
gemini_analysis.py
|
v
Gemini LLM Analysis
|
v
Statistical Analysis
|
v
Comparison Result
|
v
Frontend
The frontend is implemented using HTML, CSS, JavaScript, and Jinja2 templates. It handles the user interface, player input, comparison tables, tabs, loading animation, and presentation of the analysis.
app.py acts as the main application controller. It receives the player's names from the frontend, requests player data, sends the retrieved information for analysis, and returns the results to the webpage.
cricket_data.py handles player searching and retrieval of player statistics through the ESPN data source. It prepares the information required by the application for comparison.
gemini_analysis.py prepares the relevant player statistics and sends them to the Gemini API. The returned response is used to generate the written statistical comparison.
The application currently uses an ESPN data source for player information and statistics and the Google Gemini API for the written statistical analysis.
The current application follows this workflow:
User enters two player names
|
v
Flask receives request
|
v
Player search
|
v
ESPN API retrieves data
|
v
Retrieval Layer
|
v
Relevant player data
|
v
Retrieved context
|
v
Relevant context sent to Gemini
|
v
Gemini LLM generates
statistical analysis
|
v
Analysis displayed to user
When the user enters two player names, the application first searches for the players and retrieves their available information and statistics.
The retrieved statistics are organized into categories such as:
- Overall performance
- Home performance
- Overseas performance
The application then displays the relevant statistics side by side.
For comparable statistics, JavaScript checks the values of both players and highlights the higher value.
The application also sends the relevant player statistics to the Gemini API. Gemini generates a written comparison based on the statistics provided by the application.
The analysis is instructed to use the available statistics rather than inventing additional information or making unsupported claims.
- Python
- Flask
- HTML
- CSS
- JavaScript
- Jinja2
- ESPN API / ESPN cricket data
- Google Gemini API
- Git
- GitHub
- Python virtual environment
The application uses two external services as part of its current implementation.
The application retrieves player information and statistics from the ESPN cricket data source.
The retrieved statistics are passed to the Gemini API to generate a written comparison between the selected players.
The Gemini analysis is based on the statistics supplied by the application.
The current version of CricketAnalytica is the first implementation of the project.
At this stage, the main focus is player comparison and batting analysis. The platform is designed so that additional cricket analysis features can be added as development continues.
- Player data depends on the availability of the external ESPN data source.
- API requests may take some time depending on network conditions and external server response times.
- Player searches depend on the names recognized by the underlying data source.
- Gemini analysis depends on the availability and usage limits of the Gemini API.
- The current version does not yet provide complete cricket analysis across all aspects of the game.
The project will gradually be expanded into a more complete cricket analysis platform.
Planned improvements include:
-
Support for additional cricket formats
-
Bowling analysis
-
Fielding analysis
-
More complete player performance analysis
-
Improved statistical models
-
Better machine learning models
-
More detailed player comparisons
-
Performance trends and historical analysis
-
Interactive graphs and visualizations
-
Improved player search and selection
-
More advanced comparison features
-
A more refined and feature-rich user interface
CricketAnalytica/
│
├── app.py
├── cricket_data.py
├── gemini_analysis.py
├── compare_test.py
├── espn_test.py
├── gemini_test.py
├── test_api.py
├── requirements.txt
│
├── templates/
│ └── index.html
│
├── .gitignore
├── README.md
└── LICENSE
app.py
Main Flask application. Handles requests from the user, retrieves player data, calls the analysis function, and renders the results.
cricket_data.py
Handles player searching and retrieval of player information and statistics from the ESPN data source.
gemini_analysis.py
Prepares the player statistics and sends them to the Gemini API to generate the written comparison.
templates/index.html
Contains the main user interface, including player input fields, player cards, statistics tables, comparison tabs, loading animation, and JavaScript functionality.
requirements.txt
Contains the Python dependencies required to run the project.
.gitignore
Prevents files such as the virtual environment, Python cache files, and environment variables from being uploaded to GitHub.
git clone https://github.com/JaspreetSingh33/CricketAnalytica.git
cd CricketAnalyticaOn Windows:
python -m venv .venvActivate the environment:
.venv\Scripts\activatepip install -r requirements.txtThe application requires a Gemini API key.
Create a .env file in the project directory:
GEMINI_API_KEY=your_api_key_here
Do not upload the .env file to GitHub.
The .gitignore file already excludes .env from version control.
Start the Flask application:
python app.pyThe application will run locally at:
http://127.0.0.1:5000
Open the address in a web browser to use CricketAnalytica.
This project is licensed under the MIT License.