Skip to content

Latest commit

Β 

History

History
121 lines (97 loc) Β· 2.23 KB

File metadata and controls

121 lines (97 loc) Β· 2.23 KB

NL2SQLX β€” Natural Language β†’ SQL Query Generator

Convert plain English questions into SQL queries and run them on any uploaded CSV dataset.
Backend powered by FastAPI + MySQL + RAG.
Frontend built using React/Next.js.


πŸš€ Features

πŸ”Ή Upload CSV β†’ Auto-Create SQL Table

  • Upload any .csv file
  • Backend automatically creates a SQL table in MySQL
  • Schema is extracted and piped into RAG

πŸ”Ή Ask Natural Language Questions

Examples:

  • β€œShow total revenue by category”
  • β€œList top 10 customers by spending”
  • β€œGive count of employees in each department”

Backend returns:

  • βœ” Generated SQL
  • βœ” Executed result
  • βœ” RAG-improved query understanding

πŸ”Ή Secure Session Cleanup

  • Clicking Finish drops all temporary uploaded tables
  • Keeps database clean for next user

πŸ—οΈ Tech Stack

Backend

  • Python 3.12
  • FastAPI
  • SQLAlchemy
  • MySQL (AlwaysData / free hosting)
  • OpenAI (or Groq) LLMs
  • ChromaDB (RAG embeddings)

Frontend

  • React / Next.js
  • Axios
  • Deployed on Vercel / Render

πŸ“Œ Project Structure

NL2SQLX/ β”œβ”€β”€ backend/ β”‚ β”œβ”€β”€ app.py β”‚ β”œβ”€β”€ db.py β”‚ β”œβ”€β”€ rag.py β”‚ β”œβ”€β”€ schema_extractor.py β”‚ β”œβ”€β”€ nl2sql.py β”‚ β”œβ”€β”€ requirements.txt β”œβ”€β”€ frontend/ β”‚ β”œβ”€β”€ app/ β”‚ β”œβ”€β”€ components/ β”‚ β”œβ”€β”€ public/ β”‚ β”œβ”€β”€ package.json β”œβ”€β”€ README.md


πŸ§ͺ Run Backend Locally

1️⃣ Create & activate venv

cd backend
python -m venv venv
venv/Scripts/activate   # Windows

πŸ› οΈ Run Backend Locally

2️⃣ Install requirements

pip install -r requirements.txt

###3️⃣ Create .env file inside backend

MYSQL_USER=root
MYSQL_PASSWORD=xxxx
MYSQL_HOST=localhost
MYSQL_PORT=3306
MYSQL_DB=mydb
OPENAI_API_KEY=your_key

###4️⃣ Run FastAPI uvicorn app:app --reload

###🎨 Run Frontend Locally (React/Next.js)
cd frontend
npm install
npm run dev

Frontend runs on:

http://localhost:3000

Backend runs on:

http://localhost:8000

Edit API_BASE inside frontend:

export const API_BASE = "http://localhost:8000";

###πŸ‘¨β€πŸ’» About the Developer

Prathamesh Shivaji Salokhe B.Tech Computer Engineering (Final Year)