Back to Portfolio

๐Ÿง  Natural Language to SQL Query

LLM App Streamlit 2025
Python LangChain Streamlit OpenAI GPT MySQL
Credit Card Dashboard Credit Card Dashboard

๐Ÿ”Ž 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

  1. Clone the Repository:
    git clone https://github.com/yourusername/nl-to-sql-streamlit.git
    cd nl-to-sql-streamlit
  2. Create and Activate a Virtual Environment:
    python -m venv venv
    source venv/bin/activate  # On Windows: venv\Scripts\activate
  3. Install Dependencies:
    pip install -r requirements.txt
  4. 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
  5. 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