Convert plain English into executable SQL queries — instantly.
| Feature | Description |
|---|---|
| 🤖 AI Generation | OpenAI gpt-4o-mini converts English → SQL |
| ⚙️ Offline Fallback | Rule-based engine when no API key is set |
| 🎨 Syntax Highlighting | Color-coded SQL output |
| ✅ SQL Validation | Checks keywords, semicolons, clauses |
| 📋 Copy Button | One-click clipboard copy |
| 🕑 History | Last 8 queries saved in localStorage |
| 📱 Responsive | Works on desktop & mobile |
| ⌨️ Keyboard Shortcut | Ctrl+Enter to generate instantly |
git clone https://github.com/invo-coder19/AI_SQL_Assistant.git
cd AI_SQL_Assistant
python -m venv venv
venv\Scripts\activate # Windows
# source venv/bin/activate # macOS / Linux
pip install -r requirements.txtcopy .env.example .env # Windows
# cp .env.example .env # macOS / LinuxOpen .env and set your key (optional — rule-based fallback works without it):
OPENAI_API_KEY=sk-your-key-here
OPENAI_MODEL=gpt-4o-mini # optional; change to any supported model
FLASK_DEBUG=false
PORT=5000
Note: The app uses
python-dotenvto load.envautomatically at startup.
python app.pyOpen http://localhost:5000 in your browser.
AI_SQL_Assistant/
├── app.py # Flask app & API routes
├── requirements.txt
├── .env.example
├── services/
│ └── sql_generator.py # AI + rule-based SQL engine
├── templates/
│ └── index.html # Main UI
└── static/
├── style.css # Refined dark-mode styles
└── script.js # Frontend logic
// Request
{ "query": "show all customers from Pune" }
// Response
{ "sql": "SELECT *\n FROM customers\n WHERE city = 'Pune';", "method": "openai" }{ "status": "ok", "service": "AI SQL Assistant" }Show all employees with salary greater than 50000
Find customers from Mumbai
Count total orders placed this month
Show top 10 products by sales
List students who scored above 80 marks
Find average salary by department
- Backend: Python · Flask · Flask-CORS · python-dotenv
- AI: OpenAI
gpt-4o-mini· Rule-based NLP fallback - Frontend: Vanilla HTML · CSS · JavaScript
- Design: Refined dark theme · Green / Grey / Black · JetBrains Mono · Inter
