This project automates data analysis and narrative generation using a local Large Language Model (Qwen2.5 1.5B) downloaded from Kaggle.
- Automated Data Analysis: Reads data from Excel files using
openpyxl. - Chart Generation: Creates charts (Line, Bar, Scatter) using
matplotlib. - Local LLM Inference: Uses a locally downloaded Qwen2.5 1.5B model via
transformersto generate insightful narratives based on the data. - Kaggle Integration: Automatically downloads models from Kaggle using
kagglehub.
- Python 3.8+
- Kaggle Account (for model download)
-
Clone the repository:
git clone <repository_url> cd <repository_name>
-
Install dependencies:
pip install -r requirements.txt
-
Kaggle Credentials: You need to authenticate with Kaggle to download the model. You can do this in one of the following ways:
- Environment Variables: Set
KAGGLE_USERNAMEandKAGGLE_KEY. - Config File: Place your
kaggle.jsonkey in~/.kaggle/kaggle.json. - Script Configuration: Edit
llm_data_narrative3.pyand setKAGGLE_USERNAMEandKAGGLE_KEYvariables at the top.
- Environment Variables: Set
Run the main script:
python llm_data_narrative3.pyThe script will:
- Download the Qwen2.5 1.5B model from Kaggle (if not already present).
- Create a sample Excel file (
sample_data.xlsx) if one doesn't exist. - Analyze the data and generate a chart (
analysis_chart.png). - Generate a text narrative (
narrative.txt) describing the data and the chart.
You can configure the script by editing the variables at the top of llm_data_narrative3.py:
EXCEL_PATH: Path to your input Excel file.SHEET_NAME: Name of the sheet to analyze (defaults to active sheet).CHART_TYPE: Type of chart to generate ("line", "bar", "scatter").X_COL,Y_COL: Column indices for chart axes.
analysis_chart.png: The generated chart.narrative.txt: The AI-generated narrative explaining the data.llm_prompt.txt: The prompt sent to the LLM.