This project focuses on building an AI agent designed to answer e-commerce data questions. The agent is capable of interpreting natural language questions, generating and executing SQL queries on provided datasets, and responding with accurate answers.
This ANARIX AI Agent provides a powerful and intuitive way to interact with your e-commerce data:
-
Natural Language Querying: The AI agent can understand and answer any question related to the provided e-commerce data.
-
API-Driven Interaction: Questions are received via API endpoints, and the agent processes them to return accurate responses.
-
SQL Conversion & Execution: The agent includes logic to convert natural language questions into SQL queries, fetch answers from the database, and return them in a human-readable format.
- User Input β Ask a question at the
/askAPI endpoint. - Gemini Processing β Generates a SQL query or chart instruction.
- SQL Execution β FastAPI runs the SQL on the connected MySQL database.
- Chart Generation β If requested, Matplotlib generates a chart and saves it as an image file in
assets/screenshots/.
The API response includes the path to the chart image (e.g.,"chart_path": "assets/screenshots/chart.png"), which can be viewed or served via your web server. - Response β The agent returns the answer, SQL query, query result, and chart path (if applicable).
πANARIX-AI-AGENT
βββ πpycache
βββ πassets
β βββ πscreenshots (has imgs)
βββ πdatasets
β βββ π(Excel files or raw datasets)
βββ πdb
β βββ π(MySQL config or helpers)
βββ πenv (excluded by .gitignore)
βββ πllm
β βββ πagent.py (Gemini + SQL + chart logic)
βββ π.env (holds GEMINI_API_KEY)
βββ π.gitignore (ignores env(virtual environment)/, pycache/, .env, api_check.py, cmds.txt.)
βββ πmain.py (FastAPI entry point with /ask endpoint)
βββ πrequirements.txt (all required pip packages)
βββ πTASK DESCRIPTION.md (provided use-case or brief)
βββ πREADME.md _(project documentation you're reading)_
python -m venv env
source env/Scripts/activate pip install -r requirements.txtCreate a .env file:
GEMINI_API_KEY=your_gemini_api_key_hereGet your key from: https://makersuite.google.com/app/apikey
Ensure MySQL is running, and update the DB connection in db/session.py if needed:
DATABASE_URL = f"mysql+mysqlconnector://{DB_USER}:{DB_PASSWORD}@{DB_HOST}:{DB_PORT}/{DB_NAME}"Make sure your database and tables are already created and populated.
uvicorn main:app --reloadAccess Swagger UI at: http://127.0.0.1:8000/docs
π Data Queries "What is the total ad spend?"
"How many clicks did item 101 get?"
"Show me all metrics for item 21"
π Business Metrics "What is the Return on Ad Spend (RoAS)?"
"Which item had the highest CPC?"
π Chart Requests "Generate a pie chart of sales by item"
"Show a bar chart of revenue per product"
π οΈ Data Updates "Delete entry where item_id is 99"
Python 3.8+
FastAPI
SQLAlchemy
pandas
matplotlib
python-dotenv
sse-starlette
MySQL (local or hosted)
Google Generative AI client (google-generativeai)
User Input β Ask a question at the /ask API endpoint.
Gemini Processing β Generates a SQL query or chart instruction.
SQL Execution β FastAPI runs the SQL on the connected MySQL database.
Chart (Optional) β If requested, Matplotlib opens a popup with a chart.
.env is excluded by .gitignore for security
Matplotlib is used to pop up chart windows (no frontend)
Error-handling and Gemini fallback are supported
- Chart images are saved automatically in
assets/screenshots/whenever a chart is requested. - The API response includes the chart image path for easy access and integration.
- Example response:
{ "question": "Show me a bar chart of total sales by product", "sql_generated": "SELECT product, SUM(total_sales) FROM total_sales_metrics GROUP BY product", "query_result": [...], "answer": "Query executed successfully with chart", "chart_path": "assets/screenshots/chart.png", "type": "select" }
FastAPI
Google Gemini
SQLAlchemy
Matplotlib
Pandas
Nitish B
Final Year Student | Software Developer & AI Enthusiast
π« GitHub β’ LinkedIn
If you found this project helpful, consider starring β it on GitHub to support future development!





