This project processes all CSV and Excel files in the input/ folder, groups and enriches the data using OpenAI embeddings and fast KMeans clustering, and generates reports and visualizations. Output is saved in the same format as the input (CSV or XLSX) with group labels.
- Place one or more input files in the
input/folder. Each file must have at least these columns:- Address: contains URLs
- Content Type: specifies the MIME type of the content
- (Optional) Page Title, Meta Description, Main Text: if available, these will be used for better grouping.
- Batch Data Filtering & Grouping
- For each file, filter rows where
Content Type=text/html. - Combine available metadata for each row.
- Use OpenAI embeddings (batched) to represent each row semantically.
- Use KMeans clustering for fast, scalable grouping.
- Assign a semantic group label to each row.
- For each file, filter rows where
- Export Results
- Export enriched and grouped data to the
output/folder, in the same format as the input (CSV or XLSX).
- Export enriched and grouped data to the
- Visualization & Reporting
- Visualize all semantic groups using a bar chart (one per input file).
- The report includes:
- Total URLs processed
- Group sizes by code
- Explanation: Grouping is based on OpenAI semantic similarity of available metadata.
- Place your input files in the
input/folder. - Set your OpenAI API key in your terminal:
export OPENAI_API_KEY=sk-<your-key-here>
- (Optional) Create and activate a Python virtual environment:
python3 -m venv .venv source .venv/bin/activate - Install dependencies:
pip install -r requirements.txt
- Run the main enrichment script:
python scripts/semantic_enrich.py
- Find results in the
output/folder, with one enriched file and one bar chart per input file.
- Python 3.8+
- pandas
- openpyxl
- requests
- matplotlib
- numpy
- scikit-learn
- openai
- Processes all CSV and XLSX files in the input folder
- Groups URLs by semantic similarity using OpenAI embeddings + KMeans
- Exports grouped data in the same format as input
- Visualizes group sizes as a bar chart (PNG)
- Fast, scalable, and works with large datasets