Skip to content

Text2SQL Demo

This demo showcases an AI-powered interface that converts natural language questions into SQL queries and executes them against TiDB. Built with PyTiDB, OpenAI GPT, and Streamlit, it provides a seamless way to interact with your database using plain English.

Prerequisites

How to run

Step 1: Clone the repository

git clone https://github.com/pingcap/pytidb.git
cd pytidb/examples/text2sql/;

Step 2: Install the required packages

python -m venv .venv
source .venv/bin/activate
pip install -r reqs.txt

Step 3: Run the Streamlit app

streamlit run app.py

Step 4: Run streamlit app

Open the browser and visit http://localhost:8501

  • Input OpenAI API key in left sidebar
  • Input the TiDB Cloud connection string in left sidebar, the format is mysql+pymysql://root@localhost:4000/test

  • Source Code: View on GitHub
  • Category: Ai-Apps

  • Description: Convert natural language queries into SQL statements using AI models.

🏠 Back to Demo Gallery