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).
- π§ 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
- Zero Cloud: All data stays on your computer
- No API Keys: No external paid services required
- Open Source: Fully transparent and auditable code
- Advanced descriptive statistics
- Correlation and pattern analysis
- Outlier and anomaly identification
- Data quality assessment
- Interactive visualizations
- Intelligent analysis suggestions
| 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 |
- Hardware: MacBook Pro M4 (16GB+ RAM recommended)
- Software: Python 3.8+, LM Studio installed
- AI Model: Qwen3 4B 2507 (downloadable from LM Studio)
# 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
# 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- Download LM Studio: lmstudio.ai
- Install following macOS instructions
- Launch LM Studio
- Search "Qwen3 4B 2507" in Models section
- Download the
Q4_K_Mversion (~2.5GB) - Load model in Chat section
- Start Local Server:
- Go to "Local Server"
- Click "Start Server"
- Verify URL:
http://localhost:1234
# Quick connection test
curl http://localhost:1234/v1/models
# Should return loaded model information- Check LM Studio status in sidebar
- Verify available RAM
- Test AI model connection
π "Load Data" tab β Upload CSV or use sample dataset
π "Overview" tab β View statistics and data quality
π¬ "Chat Analysis" tab β Ask questions in natural language
π― "Insights" tab β Generate advanced automatic analysis
- "How many rows does the dataset have?"
- "Are there any null values?"
- "Show statistics for numeric columns"
- "What's the correlation between price and sales?"
- "Identify outliers in the revenue column"
- "Group by category and calculate averages"
- "Find interesting patterns in the data"
- "Suggest 3 useful analyses for this dataset"
- "Are there any anomalies I should investigate?"
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
- CSV Files: Maximum 500MB
- Dataset Memory: Max 200MB after optimization
- Conversations: Limit 10 in history
- Close other apps during heavy analysis
- Use sample datasets for quick testing
- Monitor RAM in sidebar
- Restart LM Studio if memory leak occurs
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/modelsSolutions:
# 1. Close other applications
# 2. Restart LM Studio
# 3. Use smaller CSV files (<100MB)
# 4. Restart Streamlit appSolutions:
# 1. Re-download Qwen3 4B model
# 2. Update LM Studio to latest version
# 3. Verify 10GB+ free disk spaceContributions welcome! This project is open-source and aims to grow with the community.
# 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- 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
This project is released under MIT License.
β Permitted: Use this code in your commercial projects β Modify: Adapt the code to your needs β Distribute: Redistribute with attribution β Sell: Include in paid products
- LangChain: Framework for LLM applications
- Streamlit: Rapid web app prototyping
- Pandas: Data manipulation library
- Plotly: Interactive visualizations
Made with β€οΈ | Optimized for π Apple Silicon
π‘ Tip: Join GitHub Discussions for questions, ideas and showcase!
