Skip to main content
Glama
README.md
# ⚑ AI Sales Analytics β€” MCP Automation System

> **No Power BI Login. No Manual Work. Just drop a CSV and AI does everything.**

---

## 🎯 What This Does

| You Do | System Does Automatically |
|--------|--------------------------|
| Drop a `.csv` file | Detects it instantly |
| Nothing | Cleans & validates data |
| Nothing | AI generates business insights |
| Nothing | Creates interactive HTML dashboard |
| Nothing | Exports professional PDF report |
| Nothing | Emails report to anyone |

---

## πŸ€– Multi-Model AI Fallback Chain

The system automatically tries each AI provider and falls back if unavailable:

```
1. 🟒 NVIDIA NIM   β†’ Free, 1000 credits (nvapi-...)
2. 🟒 Groq         β†’ Free, no credit card (gsk_...)
3. 🟑 DeepSeek     β†’ Near-free credits (sk-...)
4. πŸ”΅ Rule-Based   β†’ 100% offline, always works
```

**No internet? No API keys? β†’ Rule-based insights still work perfectly!**

---

## πŸš€ Quick Start (5 Minutes)

### Step 1 β€” Install Dependencies
```bash
pip install -r requirements.txt
```

### Step 2 β€” Generate Sample Data (or use your own CSV)
```bash
python generate_sample_data.py
```

### Step 3 β€” Add API Keys (Optional but recommended)
Copy `.env.example` β†’ `.env` and fill in your keys:
```bash
copy .env.example .env
# Edit .env with your keys
```

### Step 4 β€” Run the Pipeline!
```bash
# Option A: Run once on existing data
python main.py

# Option B: Watch folder (auto-trigger on CSV drop)
python watcher.py

# Option C: Chat with AI agent
python agent.py
```

---

## πŸ”‘ How to Get FREE API Keys

### NVIDIA NIM (Recommended β€” Best free models)
1. Go to β†’ **https://build.nvidia.com**
2. Click **Login / Sign Up** (free account)
3. Go to **API Keys** β†’ **Create API Key**
4. Copy key (starts with `nvapi-`)
5. Add to `.env`: `NVIDIA_API_KEY=nvapi-xxxxx`

> **Free tier**: 1000 inference credits. Model: `meta/llama-3.3-70b-instruct`

### Groq (Fastest β€” No credit card)
1. Go to β†’ **https://console.groq.com**
2. Sign up with Gmail or GitHub
3. Go to **API Keys** β†’ **Create API Key**
4. Copy key (starts with `gsk_`)
5. Add to `.env`: `GROQ_API_KEY=gsk_xxxxx`

> **Free tier**: Generous rate limits, no card needed. Model: `llama-3.3-70b-versatile`

### DeepSeek (Very cheap)
1. Go to β†’ **https://platform.deepseek.com**
2. Sign up β†’ Go to **API Keys** β†’ Create
3. Add to `.env`: `DEEPSEEK_API_KEY=sk-xxxxx`

---

## πŸ“§ Email Setup (Gmail)

1. Go to **myaccount.google.com**
2. Security β†’ **2-Step Verification** (enable)
3. Security β†’ **App passwords** β†’ Select "Mail" β†’ **Generate**
4. Copy 16-char password (e.g. `abcd efgh ijkl mnop`)
5. Add to `.env`:
   ```
   EMAIL_SENDER=you@gmail.com
   EMAIL_PASSWORD=abcdefghijklmnop
   EMAIL_RECEIVER=boss@company.com
   ```

---

## πŸ“ Project Structure

```
AI-PowerBI-MCP-Automation/
β”‚
β”œβ”€β”€ πŸ“‚ data/
β”‚   β”œβ”€β”€ sales.csv              ← Your input CSV
β”‚   └── cleaned_sales.csv      ← Auto-generated
β”‚
β”œβ”€β”€ πŸ“‚ reports/                ← All outputs here
β”‚   β”œβ”€β”€ dashboard.html         ← 🌐 Open in browser!
β”‚   β”œβ”€β”€ report.pdf             ← πŸ“„ Professional report
β”‚   └── insights.json          ← Raw KPI data
β”‚
β”œβ”€β”€ πŸ“‚ incoming/               ← DROP CSV HERE for auto-trigger
β”‚
β”œβ”€β”€ πŸ“‚ src/
β”‚   β”œβ”€β”€ ai_engine.py           ← Multi-model AI fallback
β”‚   β”œβ”€β”€ clean_data.py          ← Data cleaning
β”‚   β”œβ”€β”€ insights.py            ← KPI + AI insights
β”‚   β”œβ”€β”€ dashboard.py           ← HTML dashboard (replaces Power BI)
β”‚   β”œβ”€β”€ export_pdf.py          ← PDF report
β”‚   └── send_email.py          ← Email automation
β”‚
β”œβ”€β”€ πŸ“‚ mcp_server/
β”‚   └── server.py              ← MCP server (AI agent tools)
β”‚
β”œβ”€β”€ main.py                    ← Run full pipeline
β”œβ”€β”€ watcher.py                 ← Folder auto-watcher
β”œβ”€β”€ agent.py                   ← Chat interface
β”œβ”€β”€ generate_sample_data.py    ← Generate test data
β”œβ”€β”€ config.py                  ← All settings & API keys
β”œβ”€β”€ .env.example               ← Key template
└── requirements.txt
```

---

## πŸ’¬ Agent Chat Examples

```bash
python agent.py
```
```
You β†’ analyze today's sales
πŸ€–  β†’ Running FULL PIPELINE...
     βœ… Data cleaned (1200 rows)
     βœ… AI insights via NVIDIA NIM
     βœ… Dashboard created
     βœ… PDF exported
     βœ… Email sent

You β†’ show dashboard
πŸ€–  β†’ Opening dashboard in browser...

You β†’ status
πŸ€–  β†’ Total Sales: β‚Ή45,23,400  |  Profit: 18.3%
     Top Product: Laptop Pro X  |  Region: West

You β†’ send report
πŸ€–  β†’ Email delivered to boss@company.com βœ“
```

---

## πŸ”Œ MCP Server (For AI Agents like Claude)

Add to your Claude Desktop `mcp_settings.json`:
```json
{
  "mcpServers": {
    "ai-sales-analytics": {
      "command": "python",
      "args": ["C:/path/to/mcp_server/server.py"]
    }
  }
}
```

**Available MCP Tools:**
| Tool | Description |
|------|-------------|
| `run_full_pipeline` | Run everything end-to-end |
| `clean_data` | Clean CSV file |
| `generate_insights` | Get AI insights + KPIs |
| `create_dashboard` | Build HTML dashboard |
| `export_pdf` | Generate PDF report |
| `send_email` | Email the report |
| `get_status` | Check system status |

---

## πŸ“Š Dashboard Preview

The HTML dashboard includes:
- πŸ’° KPI Cards (Sales, Profit, Orders, Avg Order Value)
- πŸ“ˆ Monthly Sales Trend (interactive line chart)
- πŸ… Top 10 Products (horizontal bar chart)
- πŸ—ΊοΈ Region-wise Sales (donut chart)
- πŸ“¦ Category Breakdown (bar chart)
- 🧠 AI-Generated Insights Panel

**Opens in Chrome/Edge/Firefox β€” NO Power BI, NO Microsoft login!**

---

## πŸŽ“ Resume Description

```
AI-Powered Sales Analytics Automation using MCP Server

β€’ Built an end-to-end agentic AI pipeline using Python, MCP Server, and multi-model AI
β€’ Implemented intelligent fallback: NVIDIA NIM β†’ Groq β†’ DeepSeek β†’ Rule-based insights
β€’ Automated CSV ingestion, data cleaning, KPI generation, and interactive dashboard creation
β€’ Replaced Power BI with custom Plotly HTML dashboards (no login required)
β€’ Integrated watchdog folder monitoring for zero-touch automation
β€’ Delivered PDF reports and email notifications via SMTP automation
β€’ Exposed pipeline as MCP tools enabling AI agents to analyze data through natural language
```

---

## πŸ“ž Tech Stack

| Layer | Technology |
|-------|-----------|
| Data | Python + Pandas |
| AI | NVIDIA NIM / Groq / DeepSeek / Rule-based |
| Dashboard | Plotly (interactive HTML) |
| PDF | ReportLab |
| Email | SMTP (Gmail) |
| Automation | Watchdog |
| AI Protocol | MCP (Model Context Protocol) |

---

*Built with ❀️ β€” No Power BI login required. Works 100% locally.*

---

## 🌐 Web Interface (Addon)

A new interactive web interface is available!

1. Run python app.py
2. Open http://localhost:8000
3. Enjoy **Drag & Drop** uploads, **Multi-Domain** support (Sales, Health, Trading), and automatic saving of API keys.

---

## 🟑 Power BI Integration (.pbids)

The pipeline now automatically generates an optimized .pbids file. Double-clicking this file opens Power BI instantly connected to your clean data, allowing you to bypass Power Query entirely.

---

## πŸ‘¨β€πŸ’» About the Developers

- **Abhishek Maheshwari (Developer)**: Engineered this pipeline to showcase advanced AI agentic workflows, multi-model LLMs, and Python data engineering.
- **Harshit Varshney (Mentor)**: Google, IBM, and HubSpot Certified. [LinkedIn Profile](https://www.linkedin.com/in/harshit-varshney-google-ibm-and-hubspot-certified-28b78818b/)