Skip to content

AI Agent that answer any question related to the data provided. Receive questions via API endpoints, query the data, and respond with accurate answers. visualize the results and provide streamed responses (like live typing effect).

License

Notifications You must be signed in to change notification settings

ashis2004/AI-Agent-to-Answer-E-commerce-Data-Questions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

14 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ›’ E-commerce AI Agent with Gemini 2.5 Integration

An advanced AI-powered agent that transforms natural language questions into SQL queries and provides comprehensive e-commerce insights with beautiful visualizations. Powered by Google's Gemini 2.5 Flash model for enhanced query generation.

E-commerce AI Agent FastAPI Python SQLite Gemini

✨ Key Features

🧠 Advanced AI Capabilities

  • Gemini 2.5 Flash integration for superior natural language understanding
  • Intelligent SQL Generation with context-aware query optimization
  • Multi-tier Fallback System (Gemini β†’ Ollama β†’ Pattern-based)
  • Real-time Query Analysis with transparent workflow display

🎨 Beautiful User Experience

  • Modern Web Interface with gradient styling and smooth animations
  • Complete Workflow Visualization: Question β†’ SQL Query β†’ Answer β†’ Chart
  • Streaming Responses with character-by-character typing effects
  • Interactive Charts using Plotly for data visualization
  • Mobile-responsive Design for cross-platform access

πŸ“Š Comprehensive Analytics

  • Total Sales Analysis with detailed breakdowns
  • RoAS (Return on Ad Spend) calculations and optimization insights
  • Product Performance Metrics across multiple dimensions
  • Advertising Campaign Analysis with cost efficiency tracking
  • Cross-table Data Relationships with intelligent JOIN operations

οΏ½ Real Business Data Integration

Dataset Overview

  • 4,381 Product Eligibility Records - Comprehensive product catalog
  • 3,696 Ad Sales Records - Detailed advertising performance data
  • 702 Total Sales Records - Complete sales transaction history
  • 337 Unique Products - Diverse product portfolio
  • $1,004,904.56 Total Sales - Substantial revenue dataset
  • 7.92 Average RoAS - Strong advertising performance

Data Tables

  1. product_eligibility - Product catalog and advertising eligibility
  2. product_ad_sales - Advertising campaigns and performance metrics
  3. product_total_sales - Complete sales data including organic sales

πŸš€ Live Demo

Quick Start

# Start the server
python main.py

# Access web interface
http://localhost:8000

# API Documentation
http://localhost:8000/docs

Sample Questions to Try:

  1. "What is my total sales?" - Revenue analysis with visualizations
  2. "Calculate the RoAS (Return on Ad Spend)" - Performance metrics
  3. "Which product had the highest CPC?" - Cost analysis
  4. "Show me products with high clicks but low conversion rates" - Optimization insights
  5. "Compare organic sales vs ad sales for each product" - Strategic analysis

πŸ“Έ Screenshots

🎨 Beautiful Web Interface

E-commerce AI Agent Interface Modern gradient design with demo questions and intuitive user interface

πŸ” Workflow Visualization

Workflow Display Live charts rendered using Plotly for business insights

Data Visualization

Server Console Real-time logs showing queries and AI interactions and Shows how questions are converted into SQL queries and answers

Project Structure

NapQueen/
β”œβ”€β”€ data/
β”‚   β”œβ”€β”€ raw/                    # Original datasets
β”‚   β”œβ”€β”€ processed/              # Cleaned datasets
β”‚   └── database.db            # SQLite database
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ database/
β”‚   β”‚   β”œβ”€β”€ __init__.py
β”‚   β”‚   β”œβ”€β”€ models.py          # Database models
β”‚   β”‚   └── setup.py           # Database initialization
β”‚   β”œβ”€β”€ ai/
β”‚   β”‚   β”œβ”€β”€ __init__.py
β”‚   β”‚   β”œβ”€β”€ llm_client.py      # LLM integration
β”‚   β”‚   └── query_processor.py # Query processing logic
β”‚   β”œβ”€β”€ api/
β”‚   β”‚   β”œβ”€β”€ __init__.py
β”‚   β”‚   β”œβ”€β”€ routes.py          # API endpoints
β”‚   β”‚   └── streaming.py       # Streaming responses
β”‚   β”œβ”€β”€ visualization/
β”‚   β”‚   β”œβ”€β”€ __init__.py
β”‚   β”‚   └── charts.py          # Chart generation
β”‚   └── utils/
β”‚       β”œβ”€β”€ __init__.py
β”‚       └── data_loader.py     # Data loading utilities
β”œβ”€β”€ tests/
β”œβ”€β”€ requirements.txt
β”œβ”€β”€ config.py
β”œβ”€β”€ main.py
└── README.md

πŸ—οΈ Setup & Installation

Prerequisites

  • Python 3.8 or higher
  • Git
  • Google Gemini API key (for enhanced AI capabilities)

Installation Steps

  1. Clone the Repository
git clone https://github.com/ashis2004/ecommerce-ai-agent.git
cd ecommerce-ai-agent
  1. Install Dependencies
pip install -r requirements.txt
  1. Configure API Keys Edit config.py and add your Gemini API key:
GEMINI_API_KEY = "your-gemini-api-key-here"
  1. Initialize Database
python setup_real_db.py
  1. Start the Application
python main.py

Chart Generation

Charts are automatically generated and saved to static/charts/ with timestamp-based filenames.

πŸ“‘ API Endpoints

Core Endpoints

  • GET / - Web interface
  • POST /ask - Ask questions (returns complete response)
  • POST /ask/stream - Ask questions (streaming response)
  • GET /health - System health check
  • GET /stats - Database statistics
  • GET /charts/{filename} - Serve generated charts

🎯 Advanced Features

Workflow Transparency

The system shows the complete analytical process:

  1. πŸ€” Question Processing - User's natural language input
  2. πŸ” SQL Generation - AI-generated query using Gemini 2.5
  3. πŸ’‘ Answer Formation - Natural language response
  4. πŸ“Š Visualization - Interactive charts when applicable

AI Integration Hierarchy

  1. Primary: Gemini 2.5 Flash (Google's latest model)
  2. Secondary: Ollama (Local LLM fallback)
  3. Tertiary: Pattern-based SQL generation

Smart Query Optimization

  • Context-aware SQL generation
  • Automatic table relationship detection
  • Performance-optimized queries
  • Error handling and validation

πŸ“Š Sample Analytics

Business Metrics Available

  • Revenue Analysis: Total sales, average order value, sales trends
  • Advertising Performance: RoAS, CPC, CTR, conversion rates
  • Product Insights: Top performers, category analysis, inventory optimization
  • Cost Efficiency: Ad spend optimization, ACOS analysis
  • Customer Behavior: Session analysis, conversion funnels

Advanced Queries Supported

  • Multi-table JOIN operations
  • Complex aggregations and calculations
  • Time-series analysis capabilities
  • Statistical functions and ratios
  • Custom business logic implementation

Technology Stack

  • Backend: FastAPI, SQLAlchemy, SQLite
  • AI/ML: Google Generative AI (Gemini 2.5), Ollama
  • Frontend: HTML5, CSS3, JavaScript (Vanilla)
  • Visualization: Plotly
  • Data Processing: Pandas, NumPy

πŸ” Testing

Sample Test Questions

Run these questions to verify all features:

Basic Analytics:

  • "What is my total sales?"
  • "How many total orders have I received?"
  • "What's my total advertising spend?"

Advanced Analytics:

  • "Calculate the RoAS (Return on Ad Spend)"
  • "Which products have the highest conversion rates?"
  • "Show me products with high clicks but low conversion rates"

Complex Queries:

  • "Compare organic sales vs ad-driven sales for each product"
  • "Find products with high page views but low sales"
  • "Which eligible products aren't running ads yet?"

πŸš€ Deployment

Local Development

python main.py

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ“ž Support

For support, email [email protected] or create an issue on GitHub.

Built with ❀️ by Ashis Kumar

Transform your e-commerce data into actionable insights with AI-powered analytics!

Prerequisites

  • Python 3.8+
  • Git

Quick Start

  1. Install dependencies:
pip install -r requirements.txt
  1. Open your browser: http://localhost:8000

πŸ“Š API Endpoints

Endpoint Method Description
/ GET Web interface
/ask POST Ask questions (JSON response)
/ask/stream POST Ask questions (streaming response)
/health GET Health check
/stats GET Database statistics
/charts/{filename} GET Serve chart files

πŸ“œ License

This project is licensed under the MIT License.

About

AI Agent that answer any question related to the data provided. Receive questions via API endpoints, query the data, and respond with accurate answers. visualize the results and provide streamed responses (like live typing effect).

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published