📊 Sales Dashboard Agent

Natural language-to-code AI agent for business analytics with automated visualizations

Google Colab Gemini 2.0 Flash Code-as-Plan TinyDB Auto-Viz

📋 Project Overview & Problem Statement

Challenge: Business analysts spend hours writing SQL queries and Python code to extract insights from sales data. Non-technical stakeholders struggle to get timely answers without developer support. Traditional BI dashboards are rigid, require upfront configuration, and don't adapt to ad-hoc questions.

Solution: Sales Dashboard Agent converts natural language business questions into executable Python analytics code. Ask questions in plain English like "What were our top 5 products by revenue in Q4?" and get instant answers with automated visualizations. The "code-as-plan" pattern provides full transparency - you can see and verify the exact analytics code generated by the AI.

Key Benefits

🤖 Code-as-Plan Architecture

💬 Natural Language Processing

Gemini 2.0 Flash analyzes business questions and understands intent: filtering, aggregation, grouping, visualization requests.

🔧 Code Generation

AI generates executable Python code with TinyDB queries dynamically based on your data schema and question context.

🔒 Safe Execution

Code runs in sandboxed environment with read-only access. Only safe operations allowed (aggregations, filtering, visualization).

📊 Auto-Visualization

When you request charts, AI generates complete Matplotlib/Seaborn code with proper labels, titles, and formatting.

How It Works

User Question → AI Code Generation → Safe Execution → Results

📖 Sample Queries & Capabilities

Query Category Example Questions
Revenue & Profit "What were total sales in November 2024?"
"Which region generated the most profit?"
"Show revenue trends by month in a line chart"
Product Analysis "Top 5 best-selling products by revenue"
"Which products have profit margins above 30%?"
"Show product performance in a bar chart"
Customer Insights "Which customer spent the most in electronics?"
"Top 10 customers by quantity ordered"
"Show customer distribution by region"
Category Performance "Average order value for each category"
"Revenue breakdown by product category"
"Which category has the lowest margin?"
Margin Analysis "What products have margins below 10%?"
"Calculate profit margin by region"
"Show margin distribution in table format"

🛠️ Technical Architecture

AI & Processing Stack

Gemini 2.0 Flash Experimental TinyDB Python 3.8+ Google Colab Pandas

Data Visualization

Matplotlib Seaborn HTML Output Color-Coded Logs

Code Execution Workflow

Prompt Engineering & Safe Execution:

Data Schema Support

Sales Order Schema (Customizable):

📖 Usage Examples & Code Generation

Example 1: Simple Query

# User asks: "What were our total sales in November 2024?" # AI generates this code: Item = Query() nov_orders = orders_tbl.search( (Item.Order_Date >= '2024-11-01') & (Item.Order_Date <= '2024-11-30') ) nov_revenue = sum(o['Revenue'] for o in nov_orders) answer_text = f"November 2024: ${nov_revenue:,.2f} from {len(nov_orders)} orders." # Result: "November 2024: $1,234,567.89 from 2,845 orders."

Example 2: Top Products with Aggregation

# User asks: "Show me the top 5 products by profit" # AI generates this code: from collections import defaultdict product_profit = defaultdict(float) for order in orders_tbl.all(): product_profit[order['Product_Name']] += order['Profit'] top_5 = sorted(product_profit.items(), key=lambda x: x[1], reverse=True)[:5] answer_text = f"Top product: {top_5[0][0]} with ${top_5[0][1]:,.2f} profit." # Result: "Top product: MacBook Pro 16\" with $45,230.50 profit."

Example 3: Visualization Request

# User asks: "Show me a bar chart of total revenue by region" # AI generates this code: import matplotlib.pyplot as plt region_revenue = {} for order in orders_tbl.all(): region = order['Region'] revenue = order['Revenue'] region_revenue[region] = region_revenue.get(region, 0) + revenue plt.figure(figsize=(10, 6)) plt.bar(region_revenue.keys(), region_revenue.values()) plt.title('Total Revenue by Region', fontsize=14, fontweight='bold') plt.xlabel('Region') plt.ylabel('Revenue ($)') plt.show() answer_text = f"West region leads with ${max(region_revenue.values()):,.2f}" # Result: Bar chart displayed + summary text

🚀 Getting Started with Google Colab

Quick Start (3 Steps)

Interactive Query Interface

How to use the agent:

📊 Performance & Security Metrics

1-3s
Query Response Time
95%+
Code Generation Accuracy
100K+
Supported Order Records
100%
Read-Only Safety

Security Features

Supported Chart Types

🎯 Business Use Cases

Sales Analytics

Product Performance

Customer Insights

Operational Intelligence