CoolFace
Apppublic

saurabhanand/AI-Powered_SQL_Business_Intelligence_Assistant

sourceHugging Faceupdated 5mo agoView on Hugging Face
0likes
App README

๐Ÿค– AI-Powered SQL Business Intelligence Assistant

Ask business questions in plain English โ†’ AI generates SQL โ†’ results + charts + insights

![Python](https://python.org) ![Streamlit](https://streamlit.io) ![Gemini AI](https://ai.google.dev) ![SQLite](https://sqlite.org) ![GitHub](https://github.com/SaurabhAnand56) ![LinkedIn](https://www.linkedin.com/in/saurabhanand56)


๐Ÿ”ด Live Demo

DemoLink
๐Ÿš€ Streamlit App(add after deploying)

๐Ÿ“Œ What This Project Does

A user types: "Which region has the highest profit margin?"

The app:

  1. 1.Sends the question to Gemini AI API
  2. 2.AI generates a valid SQL query
  3. 3.Query runs on a SQLite database (9,994 orders)
  4. 4.Results displayed as table + auto chart
  5. 5.AI generates a plain English business insight

๐Ÿ—‚๏ธ Project Structure

AI-SQL-Business-Intelligence-Assistant/
โ”‚
โ”œโ”€โ”€ app.py              # Main Streamlit application (4 pages)
โ”œโ”€โ”€ superstore.csv      # Superstore sales dataset (9,994 rows)
โ”œโ”€โ”€ superstore.db       # SQLite database (auto-created from CSV)
โ”œโ”€โ”€ requirements.txt    # Python dependencies
โ””โ”€โ”€ README.md

๐Ÿ“ Dataset

PropertyValue
Rows9,994 orders
Columns16 features
Period2020 โ€“ 2023
SourceSuperstore Sales (Kaggle)

Columns

ColumnTypeDescription
order_idTEXTUnique order identifier
order_dateTEXTOrder date (YYYY-MM-DD)
ship_modeTEXTStandard / Second / First / Same Day
segmentTEXTConsumer / Corporate / Home Office
regionTEXTWest / East / Central / South
categoryTEXTTechnology / Furniture / Office Supplies
sub_categoryTEXTProduct sub-category
salesREALSales amount (USD)
quantityINTUnits ordered
discountREALDiscount rate (0.0โ€“0.5)
profitREALProfit amount (USD)

๐ŸŒ App Pages

PageDescription
๐Ÿ  HomeProject overview, key metrics, quick question launcher
๐Ÿค– AI Query AssistantNatural language โ†’ SQL โ†’ chart โ†’ AI insight
๐Ÿ“Š Sales DashboardPre-built interactive charts with region/category filters
๐Ÿ” SQL ExplorerWrite and run custom SQL with preset query library
๐Ÿ’ก AI InsightsAuto-generated full business intelligence report

๐Ÿ› ๏ธ Tech Stack

ToolPurpose
PythonCore language
Gemini AI APINatural language to SQL conversion + insight generation
SQLiteRelational database for all queries
SQLWindow functions, CTEs, GROUP BY, JOINs, aggregations
PandasData manipulation
Matplotlib / SeabornVisualisations
StreamlitWeb app + deployment

๐Ÿš€ Run Locally

bash
# 1. Clone the repo
git clone https://github.com/SaurabhAnand56/AI-SQL-Business-Intelligence-Assistant.git
cd AI-SQL-Business-Intelligence-Assistant

# 2. Install dependencies
pip install -r requirements.txt

# 3. Run the app
streamlit run app.py

Get a free Anthropic API key at console.anthropic.com and enter it in the app.


๐Ÿ” SQL Examples Used

sql
-- Year-over-year growth
SELECT strftime('%Y', order_date) as year,
  ROUND(SUM(sales), 2) as total_sales,
  COUNT(DISTINCT order_id) as orders
FROM sales
GROUP BY year ORDER BY year;

-- Profit margin by category
SELECT category,
  ROUND(SUM(profit)/SUM(sales)*100, 2) as margin_pct
FROM sales GROUP BY category;

-- Window function: running total
SELECT order_date,
  ROUND(SUM(SUM(sales)) OVER (ORDER BY order_date), 2) as running_total
FROM sales GROUP BY order_date ORDER BY order_date;

๐Ÿ“ฌ Connect

![GitHub](https://github.com/SaurabhAnand56) ![LinkedIn](https://www.linkedin.com/in/saurabhanand56)