Skip to content

naimulkarim/text-to-sql

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🗄️ Natural Language to SQL Generator

An AI-powered app that converts plain English questions into SQL queries and executes them against a SQLite database.

🚀 Features

  • Natural language to SQL using Groq (Llama 3.1)
  • Auto-executes queries against SQLite
  • Results shown as sortable table with CSV download
  • Plain English explanation of results
  • 10 example questions to try instantly
  • Query history panel

🛠️ Tech Stack

  • LLM: Llama 3.1 8B via Groq API (free)
  • Database: SQLite with SQLAlchemy
  • Backend: LangChain + Python
  • Frontend: Streamlit

⚙️ Setup

1. Clone the repo

git clone https://github.com/YOUR_USERNAME/text-to-sql.git
cd text-to-sql

2. Install dependencies

pip install -r requirements.txt

3. Get a free Groq API key

4. Create .env file

GROQ_API_KEY=gsk_xxxxxxxxxxxxxxxxxxxxxxxx

5. Create the sample database

python sample_db.py

6. Run the app

python -m streamlit run app.py

Open http://localhost:8501

💡 Example Questions

  • "Show me the top 5 most expensive products"
  • "Which customer has spent the most money?"
  • "What is the total revenue per product category?"
  • "Show me all orders placed in March 2024"

📁 Project Structure

text-to-sql/
├── app.py            # Streamlit frontend
├── sql_pipeline.py   # SQL generation + execution pipeline
├── sample_db.py      # Creates demo SQLite database
├── requirements.txt  # Dependencies
├── .env              # API keys (not committed)
└── README.md         # This file

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages