💼 Business Intelligence Agent

General-purpose AI analytics agent that converts any question into executable code with automatic visualizations

Python 3.9+ Gemini 2.0 Flash Pandas & NumPy Zero Coding Google Colab

📋 Project Overview & Problem Statement

Challenge: Business analysts spend hours writing repetitive Pandas code to answer ad-hoc questions from stakeholders. Each new question requires custom scripts, leading to slow insights, bottlenecks, and dependency on technical teams for simple data exploration.

Solution: Business Intelligence Agent uses Google Gemini 2.0 Flash to convert any natural language question into executable Pandas/NumPy/Matplotlib code. It auto-detects dataset schema, generates production-ready analytics code, and creates visualizations automatically - enabling business users to explore data without coding expertise.

Key Benefits

🤖 AI Capabilities & Technical Innovation

🧠 Schema Intelligence

Auto-detects column types, unique values, statistical ranges, and sample data. No manual configuration needed.

📊 Automatic Code Generation

Gemini 2.0 Flash writes production-ready Pandas code with filtering, grouping, aggregations, and visualizations.

🎨 Smart Visualizations

Generates bar charts, pie charts, scatter plots with proper labels, titles, legends, and color schemes automatically.

🔒 Safe Execution

Works on DataFrame copy with sandboxed execution. Try-except error handling in all generated code.

Analysis Types Supported

AI Processing Pipeline

🛠️ Technical Architecture & Implementation

AI & Code Generation

Google Gemini 2.0 Flash Code-as-Plan Pattern Natural Language Processing Schema Auto-Detection Safe Code Execution

Data Analytics Stack

Pandas DataFrames NumPy Calculations Matplotlib Charts Seaborn Styling Statistical Analysis

Deployment Platform

Google Colab Jupyter Notebook Cloud Storage Secrets Management

Code Generation Pattern

# All generated code follows this structure: STATUS = "success" try: # 1. Filter data with conditions filtered_df = df[(df['category'] == 'Electronics') & (df['discount'] > 0)] # 2. Perform calculations avg_profit = filtered_df['profit_margin'].mean() # 3. Create visualization (if requested) plt.figure(figsize=(10, 6)) filtered_df.groupby('product')['profit'].sum().plot(kind='bar') plt.title('Profit by Product') plt.show() # 4. Set answer answer_text = f"Found {len(filtered_df):,} orders with {avg_profit:.2f}% avg profit" except Exception as e: STATUS = "error" answer_text = f"Error: {str(e)}"

💬 Sample Questions & Use Cases

Analysis Type Sample Question Output
Discount Impact "Which product category is making a loss because of discount?" Filtered results + profitability comparison
Returns Analysis "Which factor is more likely to cause returns: shipping cost, delivery time, or payment method?" Correlation analysis + insights
Customer LTV "Please group ages into ranges and calculate lifetime value for each age group" Grouped table with LTV calculations
Product Performance "Which products are cash cows that have consistent profit? Show in bar chart" Filtered products + bar chart visualization
Logistics "Can you compare how likely a product will be returned when delivery time is more than 4 vs 5 days?" Comparative return rate analysis

Advanced Analysis Examples

📖 Development Setup & Installation Guide

Quick Start with Google Colab (Recommended)

  1. Open Colab Notebook: Click "Launch in Google Colab" button above
  2. Add API Key: Click 🔑 icon in left sidebar → Add Secret → Name: GEMINI_API_KEY
  3. Run Setup Cells: Install dependencies (Gemini, Pandas, Matplotlib)
  4. Upload CSV: Upload your e-commerce or business dataset
  5. Ask Questions: Use filter_agent() function with natural language queries

Dataset Requirements

Works with any CSV containing e-commerce or business data. Common columns:

Local Installation (Alternative)

# Clone the repository git clone https://github.com/lyven81/ai-project.git cd ai-project/projects/business-intelligence-agent # Create virtual environment python -m venv venv source venv/bin/activate # Windows: venv\Scripts\activate # Install dependencies pip install -r requirements.txt # Set up environment variables cp .env.example .env # Add your Gemini API key to .env # Run in Jupyter jupyter notebook business_intelligent_agent.py

Environment Configuration

# Required API Configuration GEMINI_API_KEY=your_gemini_api_key_here # Optional Model Settings MODEL_NAME=gemini-2.0-flash-exp TEMPERATURE=0.2

🚀 Deployment Options & Usage Workflow

Google Colab Usage Example

# 1. Upload dataset CSV from google.colab import files uploaded = files.upload() df_original = pd.read_csv('dataset.csv') # 2. Auto-generate schema SCHEMA = build_schema_block(df_original) # Shows: column types, unique values, ranges, samples # 3. Ask questions in natural language result = filter_agent( query="Which product category is making a loss because of discount?", df=df_original, schema=SCHEMA ) # 4. View results # - Shows generated Python code # - Executes safely on DataFrame copy # - Returns STATUS + answer_text # - Displays visualizations if requested

Workflow Steps

Transparency Features

📊 Performance Metrics & Business Impact

3-5s
Code Generation Time
1-3s
Analysis Execution Time
100,000+
Max Rows Supported
100%
Code Accuracy

Business Value Demonstration

Technical Performance