This repository contains a Streamlit-based application that allows users to interact with an SQL database using a chatbot interface. The application takes natural language queries as input, creates SQL using LLMs executes them against an SQLite database, and displays the results in a readable format.
- User-Friendly Interface: Simple and intuitive UI with a title bar, input box for SQL queries, and a display box for the LLM responses.
- SQL Execution: Executes natural language queries against an SQLite database.
- Readable Output: Formats and displays the SQL response in a readable format.
- Python 3.10
- Streamlit
- ctransformers
- LLM model file (Downloaded and stored in /models folder)
- I am using GGUF based model with ctransformers library.
- Hugging Face Model card - TheBloke/nsql-llama-2-7B-GGUF
- Model Download Link - Download Link
- Tried new model from HF - omeryentur/phi-3-sql
- Model download Link - Download Link
-
Clone the repository:
git clone <Repo URL> cd sql-chatbot-interface
-
Create a virtual environment (optional but recommended):
python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`
-
Install the required packages:
pip install -r requirements.txt
-
Setup the SQLite Database and Load Data:
- Edit script 'load_sql_database.py' with required table creation and data insertion queries.
- Then run below command.
python load_sql_database.py
-
Setup the Configuration JSON File: Edit 'config.json' which contains all details for LLM model path and prompts to run the app.
-
Run the Streamlit app:
streamlit run app.py
- Open your web browser and go to
http://localhost:8501
. - You will see a title bar with the text "SQL Chatbot Interface".
- Type your SQL query in the "Query Input" box.
- Click the "Submit" button.
- The SQL response will be displayed in a formatted manner in the "Response Output" box.
- 13 July 2024: added multi table sample database and support for related queries.
This project is licensed under the MIT License.