A powerful AI-driven web application that allows users to query e-commerce data using natural language. The system converts natural language questions into SQL queries, executes them against a database, and provides beautiful visualizations of the results.

📌 Tip: Want to see it in action? Check out the live demo GIF below!
- 🧠 Natural Language Processing: Ask questions in plain English about your e-commerce data
- 🪄 AI-Powered SQL Generation: Automatically converts questions to SQL queries using LLM (with fallback patterns)
- 🌈 Beautiful Web Interface: Modern, responsive React frontend with Tailwind and shadcn/ui
- 📊 Data Visualization: Auto-generates visual insights from query results
- 💬 Real-time Streaming: Typing animation for LLM responses
- 📂 Multiple Data Sources: Ad sales, total sales, eligibility data supported
- 🔗 RESTful API: Clean endpoints for integration into other systems
- Frontend: React (Vite) + Tailwind CSS + shadcn/ui
- Backend: Flask REST API with CORS support
- Database: SQLite with preloaded data
- AI Integration: Local LLM via Ollama (fallback logic included)
- Visualization: Matplotlib/Seaborn for charts

- Python 3.8+
- Node.js 16+
npm
orpnpm
# 1. Extract the zip file
cd ai_ecommerce_agent
# 2. Backend setup
pip install flask flask-cors pandas matplotlib seaborn
# Optional: Install Ollama for LLM
# https://ollama.com/download
# ollama pull llama2
# 3. Set up the database
python database.py
# 4. Frontend setup
cd frontend
npm install # or: pnpm install
# 1. Backend
cd ../ # Root directory
python api.py
# API will be at http://localhost:5000
# 2. Frontend (in new terminal)
cd frontend
npm run dev
# Frontend will be at http://localhost:5173
- Query Interface: Ask questions, visualize answers, get live responses
- Example Queries: One-click examples and schema info
- "What is the total sales?"
- "Calculate the RoAS (Return on Ad Spend)"
- "Which product had the highest CPC?"
- "Show me products not eligible for advertising"
- "Top 10 products by impressions"
Endpoint | Method | Description |
---|---|---|
/ |
GET | API home |
/health |
GET | Health check |
/query |
POST | Submit a natural language query |
/stream_query |
POST | Real-time typing stream query |
/schema |
GET | Get DB schema |
curl -X POST -H "Content-Type: application/json" \
-d '{"question": "What is the total sales?", "visualize": true}' \
http://localhost:5000/query
date
,item_id
,ad_sales
,impressions
,ad_spend
,clicks
,units_sold
date
,item_id
,total_sales
,total_units_ordered
eligibility_datetime_utc
,item_id
,eligibility
,message
Issue | Fix |
---|---|
Module not found | pip install -r requirements.txt |
DB not found | Run python database.py |
API not connecting | Ensure Flask is running at :5000 with CORS |
Frontend crashes | rm -rf node_modules && npm install |
Ollama memory issue | Use fallback mode (see terminal logs) |
ai_ecommerce_agent/
├── data/ # CSV data files
├── frontend/ # React UI
│ ├── src/components/ # UI Components
│ ├── App.jsx # Main App
│ └── App.css # Styling
├── database.py # DB init
├── llm_interface.py # AI logic
├── api.py # Flask API
├── requirements.txt # Python deps
├── README.md # You're here ✨
- Add new fallback prompts →
llm_interface.py
- Add API routes →
api.py
- Add UI components →
frontend/src/components
- Add new data →
database.py
anddata/
This project is open-source and available for educational/demo purposes.
- Star the repo ⭐ if it helped you!
- PRs welcome for new features or bugfixes 🙌
- For issues, open GitHub Issues or reach out!