๐ Project Overview
This project is a Streamlit-powered web app that allows users to ask questions in plain English, which are then converted into executable SQL queries using OpenAI's GPT model via LangChain. The results are executed on a connected SQL database and displayed in a conversational chat interface.
๐ฝ๏ธ Demo
๐ฅ Watch the app in action: View Demo
๐ Features
- ๐ Secure login to your own SQL database
- ๐ฌ Ask questions in natural language
- ๐ง LLM (GPT-3.5 Turbo via LangChain) generates SQL queries
- ๐ Dynamically fetches relevant table and column names
- โ Executes SQL queries and returns results instantly
- ๐ Chat history with question, generated SQL, and result
- ๐จ Custom styled UI with a smooth user experience
๐ ๏ธ Tech Stack
Component | Tool/Library |
---|---|
Frontend | Streamlit |
Language Model | OpenAI GPT-3.5 Turbo |
LLM Framework | LangChain |
Database | MySQL (or any SQL) |
Environment | dotenv |
Backend Language | Python |
Styling | Custom CSS in Streamlit |
๐ง Setup Instructions
- Clone the Repository:
git clone https://github.com/yourusername/nl-to-sql-streamlit.git cd nl-to-sql-streamlit
- Create and Activate a Virtual Environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
- Install Dependencies:
pip install -r requirements.txt
- Set Environment Variables:
Create a
.env
file in the project root:OPENAI_API_KEY=your_openai_key LANGSMITH_API_KEY=your_langsmith_key LANGSMITH_PROJECT=your_project_name
- Run the App:
streamlit run app.py
๐งพ File Structure
.
โโโ app.py # Main Streamlit app
โโโ sql.py # SQL connection utility
โโโ .env # API keys (not included in repo)
โโโ requirements.txt # Python dependencies
โโโ README.md # You're reading it