Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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.

License

Notifications You must be signed in to change notification settings

sultanul-ovi/NaturalQuery-AI-Powered-SQL-Generator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🧠 NaturalQuery: AI-Powered SQL Generator

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.

Python FastAPI OpenAI MySQL


🎯 What NaturalQuery Does

Input: "Show me all customers who purchased more than $1000 worth of products last month"

Output: Optimized SQL query + execution results + performance recommendations


✨ Key Features

🤖 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


Screenshots of Work

UI

Application Screenshot

Query Generation

Application Screenshot

Query Execution

Application Screenshot

🚀 Quick Start

Prerequisites

  • Python 3.8+
  • MySQL 8.0+
  • OpenAI API Key

1️⃣ Installation

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

2️⃣ Configuration

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

3️⃣ Launch Application

# 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

4️⃣ Access the Application


💡 Usage Examples

Natural Language Queries

✅ "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"

📁 Project Structure

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

🔧 Configuration Options

Database Support

  • MySQL (default)
  • PostgreSQL
  • SQL Server
  • Snowflake

AI Models

  • GPT-4 (recommended)
  • GPT-3.5-turbo (faster, cost-effective)

Made with ❤️ by Ovi

About

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.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages