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.
- 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
- 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
- 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
- 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
product_eligibility
- Product catalog and advertising eligibilityproduct_ad_sales
- Advertising campaigns and performance metricsproduct_total_sales
- Complete sales data including organic sales
# Start the server
python main.py
# Access web interface
http://localhost:8000
# API Documentation
http://localhost:8000/docs
- "What is my total sales?" - Revenue analysis with visualizations
- "Calculate the RoAS (Return on Ad Spend)" - Performance metrics
- "Which product had the highest CPC?" - Cost analysis
- "Show me products with high clicks but low conversion rates" - Optimization insights
- "Compare organic sales vs ad sales for each product" - Strategic analysis
Modern gradient design with demo questions and intuitive user interface
Live charts rendered using Plotly for business insights
Real-time logs showing queries and AI interactions and Shows how questions are converted into SQL queries and answers
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
- Python 3.8 or higher
- Git
- Google Gemini API key (for enhanced AI capabilities)
- Clone the Repository
git clone https://github.com/ashis2004/ecommerce-ai-agent.git
cd ecommerce-ai-agent
- Install Dependencies
pip install -r requirements.txt
- Configure API Keys
Edit
config.py
and add your Gemini API key:
GEMINI_API_KEY = "your-gemini-api-key-here"
- Initialize Database
python setup_real_db.py
- Start the Application
python main.py
Charts are automatically generated and saved to static/charts/
with timestamp-based filenames.
GET /
- Web interfacePOST /ask
- Ask questions (returns complete response)POST /ask/stream
- Ask questions (streaming response)GET /health
- System health checkGET /stats
- Database statisticsGET /charts/{filename}
- Serve generated charts
The system shows the complete analytical process:
- π€ Question Processing - User's natural language input
- π SQL Generation - AI-generated query using Gemini 2.5
- π‘ Answer Formation - Natural language response
- π Visualization - Interactive charts when applicable
- Primary: Gemini 2.5 Flash (Google's latest model)
- Secondary: Ollama (Local LLM fallback)
- Tertiary: Pattern-based SQL generation
- Context-aware SQL generation
- Automatic table relationship detection
- Performance-optimized queries
- Error handling and validation
- 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
- Multi-table JOIN operations
- Complex aggregations and calculations
- Time-series analysis capabilities
- Statistical functions and ratios
- Custom business logic implementation
- Backend: FastAPI, SQLAlchemy, SQLite
- AI/ML: Google Generative AI (Gemini 2.5), Ollama
- Frontend: HTML5, CSS3, JavaScript (Vanilla)
- Visualization: Plotly
- Data Processing: Pandas, NumPy
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?"
python main.py
This project is licensed under the MIT License - see the LICENSE file for details.
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!
- Python 3.8+
- Git
- Install dependencies:
pip install -r requirements.txt
- Open your browser: http://localhost:8000
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 |
This project is licensed under the MIT License.