SQLGPT is a web app that converts plain English into SQL queries using Google Gemini API, with a FastAPI backend and a lightweight HTML/CSS/JS frontend.
SQL-GPT/
βββ app/
β βββ main.py # FastAPI backend
β βββ model.py # Gemini integration logic
βββ frontend/
β βββ index.html # UI layout
β βββ script.js # Frontend logic
β βββ style.css # Styling
βββ .env # API key config
βββ README.md # Project docs
βββ requirements.txt # Python dependencies
- β Convert natural language to SQL
- β Syntax-highlighted output (via Prism.js)
- β Multi-tab chat interface
- β Copy and download SQL results
- β Light/dark mode support
- β Handles irrelevant or off-topic questions gracefully
| Layer | Technology |
|---|---|
| Backend | Python, FastAPI |
| Frontend | HTML, CSS, JavaScript |
| LLM | Google Gemini API |
| Highlight | Prism.js |
- Python 3.9 or higher
pipinstalled- Gemini API key from Google Cloud Console
# 1. Clone the repository
git clone https://github.com/your-user/sqlgpt.git
cd sqlgpt
# 2. Create virtual environment
python -m venv venv
# 3. Activate environment
# macOS/Linux
source venv/bin/activate
# Windows
venv\Scripts\activate
# 4. Install dependencies
pip install -r requirements.txtTo use Googleβs Gemini API, you need to get an API key from your Google Cloud Console.
- Go to: https://console.cloud.google.com
- Click on the project dropdown β βNew Projectβ
- Name it (e.g.,
SQLGPT) and click Create
- Inside your new project, go to APIs & Services β Library
- Search for βGemini APIβ
- Click on it, then click Enable
- Go to APIs & Services β Credentials
- Click β+ Create Credentialsβ β choose API Key
- Copy the generated key
In your project root (SQLGPT/), create a new file named .env:
GEMINI_API_KEY=your_actual_gemini_api_key_hereπ Important: Never commit this file to GitHub or share your key publicly.
Here's how to run the backend and frontend of SQLGPT locally:
git clone https://github.com/your-user/sqlgpt.git
cd sqlgptpython -m venv venv-
macOS/Linux:
source venv/bin/activate -
Windows:
venv\Scripts\activate
pip install -r requirements.txtThis installs FastAPI, the Gemini API client, and other required packages.
Make sure your .env file (created earlier) is in the project root like this:
SQLGPT/
βββ app/
β βββ main.py
β βββ model.py
βββ frontend/
β βββ ...
βββ .env π HERE
The file should contain:
GEMINI_API_KEY=your_actual_gemini_api_key_hereFrom the root directory, run:
uvicorn app.main:app --reloadYou should see output like:
Uvicorn running on http://127.0.0.1:8000
Your backend is now live at: π http://localhost:8000
In a new terminal window (or tab):
cd frontend
python -m http.server 5500This serves the frontend at: π http://localhost:5500
β Open it in your browser and start typing questions like: βGet employees in HR with salary above 50000β
- Keep both backend and frontend terminals open while developing.
- If
.envchanges, restart the backend to reload your API key. - Any change to
main.pyormodel.pywill auto-reload the FastAPI server in development mode (--reload).
Try asking:
List employees in the HR department with salary over 50000Get average sales per regionCreate a table for student enrollmentsInsert 5 rows into orders tableUpdate salary of employee with ID 102 to 80000
pip install -r requirements.txt-
Make sure you start it via:
cd frontend python -m http.server 5500
-
Check that the FastAPI backend is running:
uvicorn app.main:app --reload
- Confirm
.envis correctly set - Restart backend after editing
.env
- Use
.envfor local dev β never expose API keys - Use environment variables in production
- Add rate limiting, CORS restrictions, and error handling in production environments
This project is intended for educational and personal use. Feel free to fork and modify it to suit your needs.