Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

6 Commits

Folders and files

Repository files navigation

🧠 E-commerce AI Assistant

Developed by: 21MID0038 - Rayavarapu Venkata Subramanyam Nithin

This project is an intelligent E-commerce assistant that helps you analyze your product ad performance and sales data using natural language questions. It uses the power of Google's Gemini AI to generate SQL queries, human-readable explanations, and visualizations based on your SQLite product ads database.

Watch Demo Here


📁 Project Structure

Ecommerce-Data-Analysis-Agent/
├── app.py                 # Streamlit frontend
├── main.py                # FastAPI backend
├── .env                   # Environment variables (GEMINI_API_KEY)
├── requirements.txt       # Python dependencies
├── setup.py               # Placeholder for setup (DB creation not implemented yet)
├── data/
│   ├── csv_files/         # Placeholder for any CSV data
│   └── product_ads.db     # SQLite database file
├── src/
│   └── handlers/
│       ├── database_handler.py  # Handles SQLite operations
│       └── llm.py               # Handles Gemini LLM interactions

🚀 Features

  • ✅ Natural language to SQL translation using Gemini
  • ✅ Execution of dynamic SQL queries on sqlite database
  • ✅ Explanation generation for SQL query results
  • ✅ Intelligent chart generation (line, bar, scatter) based on query output
  • ✅ Web-based UI built with Streamlit
  • ✅ API backend using FastAPI

🔧 Setup Instructions

1. Clone the repository

git clone https://github.com/nithinrvs/Ecommerce-Data-Analysis-Agent.git

2. Install dependencies

pip install -r requirements.txt

3. Set up your environment

Create a .env file in the root directory:

GEMINI_API_KEY=your_gemini_api_key_here

4. Make sure the database exists

Ensure the file data/product_ads.db exists. If not, you must create it and populate the following tables:

  • product_eligibility
  • daily_ad_metrics
  • daily_total_sales

⚠️ Note: setup.py creates the database. It should be executed once after cloning the project


▶️ How to Run

1. Start the backend server (FastAPI)

uvicorn main:app --reload

By default, this runs at: http://localhost:8000

2. Start the frontend app (Streamlit)

streamlit run app.py

This will open a web interface in your browser.


📊 Database Schema Used

product_eligibility

Column Type
eligibility_datetime_utc TEXT
item_id INTEGER
eligibility BOOLEAN
message TEXT

daily_ad_metrics

Column Type
date TEXT
item_id INTEGER
ad_sales REAL
impressions INTEGER
ad_spend REAL
clicks INTEGER
units_sold INTEGER

daily_total_sales

Column Type
date TEXT
item_id INTEGER
total_sales REAL
total_units_ordered INTEGER

🌐 API Endpoint

POST /ask

Request JSON:

{
  "question": "Which item had the highest ad spend last week?"
}

Response JSON:

{
  "sql": "...",              // Generated SQL query
  "results": [...],          // List of rows (dictionaries)
  "explanation": "...",      // Natural language summary
  "chart": "base64string"    // Optional base64 PNG chart (if applicable)
}

🧪 Example Questions

  • "Which item had the highest ad spend last week?"
  • "Show total sales and units ordered per item"
  • "What were the daily ad impressions for item 101?"

📎 Dependencies

  • streamlit
  • requests
  • fastapi
  • uvicorn
  • python-dotenv
  • pydantic
  • google-generativeai
  • matplotlib
  • seaborn
  • pandas

📌 Notes

  • You must have an active Google Gemini API Key to use this app.
  • Streamlit and FastAPI are separate processes — ensure both are running concurrently.
  • Charts are auto-generated only if Gemini suggests one based on the result data.

📬 License & Credits

  • Built with ❤️ using Python, Gemini, Streamlit, and FastAPI
  • For educational or internal usage only — production hardening needed

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages