Skip to content

About

AI-powered Text-to-SQL Analytics Engine using LangChain, Gemini, MySQL, and Streamlit.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

InsightSQL

An AI-powered Text-to-SQL Analytics Engine that converts natural language into SQL, executes it on a MySQL database, visualizes results with interactive dashboards, and automatically generates AI-powered business insights.

Python Streamlit Gemini LangChain MySQL Plotly RAGAS


Overview

InsightSQL enables users to interact with relational databases using natural language instead of writing SQL manually.

Users simply ask questions such as:

"Show the top 10 states by total sales revenue."

The system automatically:

  • Understands the question using Gemini 2.5 Flash
  • Generates optimized SQL
  • Executes the query on MySQL
  • Displays the results as an interactive table
  • Creates dynamic visualizations
  • Produces AI-generated business insights
  • Evaluates SQL quality using RAGAS

Key Features

AI-Powered SQL Generation

  • Natural Language → SQL
  • Powered by Gemini 2.5 Flash
  • LangChain prompt engineering
  • Automatic SQL cleaning & validation

Database Integration

  • MySQL backend
  • SQLAlchemy engine
  • Automatic schema discovery
  • Dynamic table explorer

Interactive Analytics

  • Interactive Data Tables
  • Plotly Visualizations
  • Bar Charts
  • Line Charts
  • Area Charts
  • Automatic chart selection

AI Business Insights

After executing a query, the application automatically generates:

  • Executive summary
  • Key trends
  • Business observations
  • Actionable insights

Evaluation Dashboard

  • RAGAS Metrics
  • SQL correctness
  • Answer relevance
  • Semantic evaluation
  • LLM-as-a-Judge (Llama-3 via Groq)

System Architecture

                   Natural Language Query
                           │
                           ▼
                  Streamlit User Interface
                           │
                           ▼
                LangChain Prompt Pipeline
                           │
                           ▼
               Database Schema Retrieval
                           │
                           ▼
                  Gemini 2.5 Flash LLM
                           │
                           ▼
                  SQL Query Generation
                           │
                           ▼
                 SQL Validation & Cleaning
                           │
                           ▼
                 SQLAlchemy + MySQL Engine
                           │
                           ▼
                    Pandas DataFrame
                           │
          ┌────────────────┴────────────────┐
          ▼                                 ▼
   Interactive Data Table          Plotly Visualizations
          │                                 │
          └────────────────┬────────────────┘
                           ▼
                 AI Business Insights
                           │
                           ▼
                    RAGAS Evaluation

Application Screenshots

Home Page

Home


SQL Generation & Execution

Execution


Interactive Dashboard

Visualization


Evaluation Dashboard

Evaluation


Tech Stack

Category Technology
Programming Language Python
Frontend Streamlit
LLM Gemini 2.5 Flash
AI Framework LangChain
Database MySQL
ORM SQLAlchemy
Data Processing Pandas
Visualization Plotly
Evaluation RAGAS
Judge Model Llama-3 (Groq)

Project Structure

InsightSQL
│
├── Data/
│   ├── Customers.csv
│   ├── Products.csv
│   ├── Regions.csv
│   ├── sales_order.csv
│   ├── State_Regions.csv
│   └── 2017_Budgets.csv
│
├── images/
│
├── notebooks/
│
├── app.py
├── sql_engine.py
├── requirements.txt
├── README.md
├── .env.example
└── docker-compose.yml

Installation

Clone Repository

git clone https://github.com/VisheshJain28/InsightSQL.git

Navigate to Project

cd InsightSQL

Install Dependencies

pip install -r requirements.txt

Configure Environment Variables

Create a .env file.

GOOGLE_API_KEY=YOUR_GOOGLE_API_KEY

DB_HOST=localhost
DB_PORT=3306
DB_USER=root
DB_PASSWORD=your_password
DB_NAME=your_database

Run the Application

streamlit run app.py

Example Queries

  • Show the top 7 states by total sales revenue.
  • Find the products with the highest sales.
  • Display total revenue generated by each region.
  • Which customers generated the highest revenue?
  • Compare state-wise sales.
  • Show the monthly sales trend.
  • List all available products.
  • Find the budget allocated to Product 12.

Future Improvements

  • Query History
  • Download Results as CSV/Excel
  • User Authentication
  • Dashboard Customization
  • Conversational Memory
  • Voice-to-SQL
  • Multi-turn Analytics

About

AI-powered Text-to-SQL Analytics Engine using LangChain, Gemini, MySQL, and Streamlit.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages