Transform natural language into optimized SQL queries with AI-driven intelligence. NaturalQuery combines the power of GPT-4, FastAPI, and Streamlit to make database querying accessible to everyone.
Input: "Show me all customers who purchased more than $1000 worth of products last month"
Output: Optimized SQL query + execution results + performance recommendations
🤖 AI-Powered Translation - Convert plain English to optimized SQL using GPT-4
⚡ Smart Query Execution - Run queries safely with built-in validation
🔍 Performance Analysis - Get execution plans and indexing recommendations
🎨 Interactive Web UI - User-friendly Streamlit interface
🚀 REST API Ready - FastAPI backend for integration
📊 Multi-Database Support - MySQL, PostgreSQL, SQL Server ready
🛡️ Query Validation - Syntax checking before execution
- Python 3.8+
- MySQL 8.0+
- OpenAI API Key
git clone https://github.com/yourusername/naturalquery.git
cd naturalquery
# Create virtual environment
python -m venv venv
source venv/bin/activate # Linux/macOS
# venv\Scripts\activate # Windows
# Install dependencies
pip install -r requirements.txt
Create a .env
file in the project root:
# Database Configuration
MYSQL_HOST=localhost
MYSQL_USER=root
MYSQL_PASSWORD=your_password
MYSQL_DATABASE=your_database
MYSQL_PORT=3306
# OpenAI Configuration
OPENAI_API_KEY=your_openai_api_key_here
# 1. Install updated requirements
pip install -r requirements.txt
# 2. Start FastAPI (Terminal 1)
python -m uvicorn app:app --reload --host 127.0.0.1 --port 8000
# 3. Start Streamlit (Terminal 2)
python -m streamlit run ui.py
- Web Interface: http://localhost:8501
- API Documentation: http://localhost:8000/docs
✅ "Find all orders placed in the last 30 days"
✅ "Show me the top 5 customers by total purchase amount"
✅ "List products that are running low on inventory"
✅ "Get monthly revenue trends for this year"
naturalquery/
├── app.py # FastAPI application
├── query_generator.py # Core AI logic
├── database.py # Database connection & schema
├── ui.py # Streamlit interface
├── requirements.txt # Python dependencies
├── .env.example # Environment template
├── .gitignore # Git ignore rules
└── README.md # This file
- MySQL (default)
- PostgreSQL
- SQL Server
- Snowflake
- GPT-4 (recommended)
- GPT-3.5-turbo (faster, cost-effective)
Made with ❤️ by Ovi