Skip to content

About

Local tool to query CSV files using natural language, no APIs, full privacy. Optimized for Apple Silicon with interactive dashboard and advanced AI analysis.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

6 Commits

Folders and files

Repository files navigation

πŸ€– CSV AI Agent

Python Streamlit LangChain License: MIT

Local AI Agent for intelligent CSV data analysis using LM Studio and Qwen3 4B

A complete project demonstrating integration of modern AI technologies for data analysis, optimized for MacBook Pro M4 and fully local (privacy-first approach).

CSV AI Agent Demo

🌟 Features

✨ Core Capabilities

  • 🧠 Conversational AI Agent: Query your data using natural language
  • 🏠 Fully Local: No external APIs, privacy guaranteed
  • ⚑ M4 Optimized: Performance tuning specific for Apple Silicon
  • πŸ“Š Complete Dashboard: Overview, automatic insights, visualizations
  • πŸ’Ύ Smart Memory Management: Intelligent handling of large datasets
  • πŸ”„ Real-time Feedback: Progress tracking for long operations

πŸ›‘οΈ Privacy & Security

  • Zero Cloud: All data stays on your computer
  • No API Keys: No external paid services required
  • Open Source: Fully transparent and auditable code

πŸ“ˆ Supported Analysis

  • Advanced descriptive statistics
  • Correlation and pattern analysis
  • Outlier and anomaly identification
  • Data quality assessment
  • Interactive visualizations
  • Intelligent analysis suggestions

πŸ› οΈ Tech Stack

Component Technology Version Role
AI Framework LangChain 0.2+ AI agent orchestration
LLM Backend LM Studio + Qwen3 4B Latest Local language model
Interface Streamlit 1.38+ Interactive web UI
Data Processing Pandas 2.2+ Data manipulation
Visualizations Plotly 5.24+ Interactive charts
Memory Monitoring psutil Latest System resource monitoring

πŸš€ Quick Start

Prerequisites

  • Hardware: MacBook Pro M4 (16GB+ RAM recommended)
  • Software: Python 3.8+, LM Studio installed
  • AI Model: Qwen3 4B 2507 (downloadable from LM Studio)

5-Minute Setup

# 1. Clone repository
git clone https://github.com/simones99/csv_ai_agent.git
cd csv_ai_agent

# 2. Create virtual environment
python -m venv venv
source venv/bin/activate  # On macOS/Linux

# 3. Install dependencies
pip install -r requirements.txt

# 4. Configure LM Studio (see detailed section)
# - Download Qwen3 4B 2507
# - Start local server on port 1234

# 5. Launch application
streamlit run main.py

πŸŽ‰ Your AI agent is ready! Open browser at http://localhost:8501

πŸ“‹ Detailed Installation

1. Python Environment Setup

# Check Python version (3.8+ required)
python --version

# Clone repository
git clone https://github.com/simones99/csv_ai_agent.git
cd csv_ai_agent

# Create isolated virtual environment
python -m venv venv

# Activate virtual environment
source venv/bin/activate  # macOS/Linux
# or
venv\Scripts\activate  # Windows

# Upgrade pip
pip install --upgrade pip

# Install project dependencies
pip install -r requirements.txt

2. LM Studio Setup

Download & Installation

  1. Download LM Studio: lmstudio.ai
  2. Install following macOS instructions
  3. Launch LM Studio

Model Configuration

  1. Search "Qwen3 4B 2507" in Models section
  2. Download the Q4_K_M version (~2.5GB)
  3. Load model in Chat section
  4. Start Local Server:
    • Go to "Local Server"
    • Click "Start Server"
    • Verify URL: http://localhost:1234

Connection Test

# Quick connection test
curl http://localhost:1234/v1/models

# Should return loaded model information

πŸ’» Usage

Typical Workflow

1. System Check

  • Check LM Studio status in sidebar
  • Verify available RAM
  • Test AI model connection

2. Load Dataset

πŸ“ "Load Data" tab β†’ Upload CSV or use sample dataset

3. Explore Data

πŸ“Š "Overview" tab β†’ View statistics and data quality

4. Interactive Analysis

πŸ’¬ "Chat Analysis" tab β†’ Ask questions in natural language

5. Automatic Insights

🎯 "Insights" tab β†’ Generate advanced automatic analysis

Example Queries

Basic Queries

- "How many rows does the dataset have?"
- "Are there any null values?"
- "Show statistics for numeric columns"

Analytical Queries

- "What's the correlation between price and sales?"
- "Identify outliers in the revenue column"
- "Group by category and calculate averages"

Exploratory Queries

- "Find interesting patterns in the data"
- "Suggest 3 useful analyses for this dataset"
- "Are there any anomalies I should investigate?"

πŸ“ Project Structure

csv-ai-agent/
β”œβ”€β”€ πŸ“„ README.md                    # Main documentation
β”œβ”€β”€ πŸ“„ requirements.txt             # Python dependencies
β”œβ”€β”€ πŸ“„ config.py                   # Central configuration
β”œβ”€β”€ πŸ“„ main.py                     # Main Streamlit app
β”‚
β”œβ”€β”€ 🧠 agents/                     # Core AI Agent
β”‚   β”œβ”€β”€ πŸ“„ __init__.py
β”‚   β”œβ”€β”€ πŸ“„ csv_agent.py            # Main agent logic
β”‚   β”œβ”€β”€ πŸ“„ tools.py                # Custom tools
β”‚   └── πŸ“„ prompts.py              # Prompt templates
β”‚
β”œβ”€β”€ πŸ› οΈ utils/                      # Utilities and helpers
β”‚   β”œβ”€β”€ πŸ“„ __init__.py
β”‚   β”œβ”€β”€ πŸ“„ data_optimizer.py       # DataFrame optimization
β”‚   β”œβ”€β”€ πŸ“„ validation.py           # Data validation
β”‚   └── πŸ“„ memory_monitor.py       # Memory monitoring
β”‚
β”œβ”€β”€ πŸ“Š data/                       # Data management
β”‚   β”œβ”€β”€ πŸ“ samples/                # Sample datasets
β”‚   └── πŸ“ uploads/                # User files (auto-created)
β”‚
β”œβ”€β”€ 🎨 assets/                     # Graphic resources
β”‚   β”œβ”€β”€ πŸ“„ logo.png               # Application logo
β”‚   └── πŸ“ screenshots/           # README screenshots
β”‚
└── πŸ§ͺ tests/                      # Automated tests
    β”œβ”€β”€ πŸ“„ __init__.py
    β”œβ”€β”€ πŸ“„ test_agent.py          # AI agent tests
    └── πŸ“„ test_utils.py          # Utility tests

βš™οΈ Configuration

Hardware Limits (MacBook M4 16GB)

  • CSV Files: Maximum 500MB
  • Dataset Memory: Max 200MB after optimization
  • Conversations: Limit 10 in history

Performance Tips

  • Close other apps during heavy analysis
  • Use sample datasets for quick testing
  • Monitor RAM in sidebar
  • Restart LM Studio if memory leak occurs

πŸ”§ Troubleshooting

Common Issues

❌ "LM Studio not connected"

Solutions:

# 1. Verify LM Studio is open
# 2. Go to "Local Server" β†’ "Start Server"
# 3. Verify model loaded in "Chat"
# 4. Test connection:
curl http://localhost:1234/v1/models

❌ "Insufficient memory"

Solutions:

# 1. Close other applications
# 2. Restart LM Studio
# 3. Use smaller CSV files (<100MB)
# 4. Restart Streamlit app

❌ "Model loading error"

Solutions:

# 1. Re-download Qwen3 4B model
# 2. Update LM Studio to latest version
# 3. Verify 10GB+ free disk space

🀝 Contributing

Contributions welcome! This project is open-source and aims to grow with the community.

Development Setup

# Fork on GitHub and clone your fork
git clone https://github.com/simones99/csv_ai_agent.git
cd csv_ai_agent

# Create feature branch
git checkout -b feature/feature-name

# Setup environment
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt

Future Features Ideas

  • Multi-agent Architecture: Specialized agents for specific tasks
  • Advanced Visualizations: ML plots, heatmaps, 3D charts
  • Database Integration: PostgreSQL, SQLite, MongoDB support
  • Report Generation: Automatic PDF exports with insights
  • API REST: Endpoints for external integrations

πŸ“„ License

This project is released under MIT License.

Commercial Use

βœ… Permitted: Use this code in your commercial projects βœ… Modify: Adapt the code to your needs βœ… Distribute: Redistribute with attribution βœ… Sell: Include in paid products

πŸ™ Acknowledgments

Open Source Technologies

AI Models


Made with ❀️ | Optimized for 🍎 Apple Silicon

GitHub stars

πŸ’‘ Tip: Join GitHub Discussions for questions, ideas and showcase!

About

Local tool to query CSV files using natural language, no APIs, full privacy. Optimized for Apple Silicon with interactive dashboard and advanced AI analysis.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages