Skip to content

omsudhamsh/nl-sql

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

10 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ€– AI Data Analyst

Upload any CSV β†’ Ask questions in plain English β†’ Get SQL & results instantly

Live Demo GitHub Stars Fork License


AI Data Analyst


✨ Features

  • πŸ“‚ CSV Upload β€” Upload any .csv file as your dataset
  • 🧠 AI-Powered β€” Converts natural language to SQL using Groq's LLaMA 3.1
  • πŸ“Š Instant Results β€” See query results in a clean, interactive table
  • πŸ” Dynamic Schema β€” Auto-detects table structure from uploaded CSV
  • πŸ“‹ Copy SQL β€” One-click copy for generated queries
  • ⌨️ Keyboard Shortcut β€” Ctrl + Enter to submit
  • πŸŒ™ Premium Dark UI β€” Modern design with smooth animations
  • πŸ”’ Safe Queries β€” Only SELECT statements allowed

πŸ“Έ Screenshots

Upload Dataset Query Results
Upload Results

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    FRONTEND (Vercel)                     β”‚
β”‚                                                         β”‚
β”‚   React + Vite + Tailwind CSS                           β”‚
β”‚   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”‚
β”‚   β”‚  Step 1: Upload CSV file                  β”‚         β”‚
β”‚   β”‚  Step 2: Ask question in plain English    β”‚         β”‚
β”‚   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β”‚
β”‚              β”‚ POST /upload   β”‚ POST /query             β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
               β”‚                β”‚
               β–Ό                β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                   BACKEND (Render)                       β”‚
β”‚                                                         β”‚
β”‚   FastAPI + Python                                      β”‚
β”‚   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”       β”‚
β”‚   β”‚  /upload API    β”‚    β”‚  /query API          β”‚       β”‚
β”‚   β”‚  CSV β†’ SQLite   β”‚    β”‚  Question β†’ Groq LLM β”‚       β”‚
β”‚   β”‚  via Pandas     β”‚    β”‚  β†’ SQL β†’ Execute     β”‚       β”‚
β”‚   β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜       β”‚
β”‚            β”‚                        β”‚                   β”‚
β”‚            β–Ό                        β–Ό                   β”‚
β”‚   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”           β”‚
β”‚   β”‚   SQLite Database (uploaded_data.db)    β”‚           β”‚
β”‚   β”‚   Dynamic table from uploaded CSV       β”‚           β”‚
β”‚   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜           β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

How It Works

  1. Upload a CSV file β€” backend saves it to a SQLite database using Pandas
  2. Schema auto-detection β€” column names and types are extracted automatically
  3. Ask a question in natural language (e.g., "Show employees with salary > 50000")
  4. Groq AI (LLaMA 3.1-8B) generates a SELECT SQL query using the detected schema
  5. Backend executes the SQL on the SQLite database
  6. Results are returned as JSON and displayed in a styled table

πŸ› οΈ Tech Stack

Layer Technology Purpose
Frontend React 19, Vite 7, Tailwind CSS 4 UI & styling
Backend FastAPI, Python REST API
AI/LLM Groq Cloud, LLaMA 3.1-8B NL β†’ SQL conversion
Database SQLite, SQLAlchemy, Pandas Dynamic data storage
Deployment Vercel (frontend), Render (backend) Hosting

πŸš€ Getting Started

Prerequisites

  • Node.js β‰₯ 18
  • Python β‰₯ 3.9
  • Groq API Key β€” Get one free at console.groq.com

1. Clone the Repository

git clone https://github.com/omsudhamsh/nl-sql.git
cd nl-sql

2. Setup Backend

cd backend

# Create virtual environment
python -m venv venv

# Activate it
# Windows:
venv\Scripts\activate
# macOS/Linux:
source venv/bin/activate

# Install dependencies
pip install -r requirements.txt

# Create .env file
echo GROQ_API_KEY=your_groq_api_key_here > .env

# Run the backend
uvicorn app.main:app --reload

The API server will start at http://127.0.0.1:8000

3. Setup Frontend

cd frontend/nl-sql

# Install dependencies
npm install

# Run dev server
npm run dev

The app will be available at http://localhost:5173


πŸ“ Project Structure

nl-sql/
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ app/
β”‚   β”‚   β”œβ”€β”€ main.py          # FastAPI app, CORS, routes (/upload, /query)
β”‚   β”‚   β”œβ”€β”€ llm.py           # Groq LLM integration (dynamic schema)
β”‚   β”‚   β”œβ”€β”€ db.py            # SQLite database setup
β”‚   β”‚   β”œβ”€β”€ file_handler.py  # CSV β†’ SQLite via Pandas
β”‚   β”‚   └── utils.py         # SQL execution + safety checks
β”‚   β”œβ”€β”€ requirements.txt
β”‚   └── .env                 # API keys (not committed)
β”‚
β”œβ”€β”€ frontend/nl-sql/
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ App.jsx          # Main app (upload + query UI)
β”‚   β”‚   β”œβ”€β”€ index.css         # Premium dark theme styles
β”‚   β”‚   └── main.jsx         # React entry point
β”‚   β”œβ”€β”€ index.html
β”‚   β”œβ”€β”€ vite.config.js
β”‚   └── package.json
β”‚
β”œβ”€β”€ assets/                  # Screenshots for README
└── README.md

πŸ”’ Safety

  • Only SELECT queries are allowed β€” the backend rejects INSERT, UPDATE, DELETE, etc.
  • SQL output is sanitized to strip markdown formatting from LLM responses
  • CORS configured for secure cross-origin requests
  • API key stored in .env (never committed to repo)

πŸ“„ License

This project is licensed under the MIT License β€” see the LICENSE file for details.


Built with ❀️ by Om Sudhamsh Padma

⭐ Star this repo if you found it useful!

About

A web application built with JavaScript that translates natural language queries into SQL statements, hosted on Vercel for easy access.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors