🚀 SQL Chat App Query your SQLite or MySQL databases with natural language using this sleek Streamlit app, powered by LangChain 🗄️
Available Now ✅
-
🗄️ Connect to SQLite or MySQL databases.
-
💬 Query databases using natural language (e.g., "Show all customers").
-
📊 Visualize results with interactive bar charts (triggered by "visualize" or "chart").
-
📜 View and download query history as CSV.gz or JSON.
-
🖥️ User-friendly UI with database selection and query history sidebar.
-
📋 Query suggestions based on table names.
-
🔍 Advanced query validation (e.g., limit JOINs, subqueries).
-
⚡ Query caching for faster responses.
-
🧠 Context memory for follow-up queries.
-
💾 Session persistence (save history across sessions).
-
🧩 Modular codebase for easier maintenance.
- Clone the Repository
git clone https://github.com/anasskhannn/Chat-with-Database-SQL
cd Chat-with-Database-SQL
-
Install Dependencies pip install streamlit langchain langchain-groq sqlalchemy pymysql pandas plotly
-
Set Up a Database
-
SQLite 🗃️: Place
.db
,.sqlite
, or.sqlite3
files in database/local/. -
MySQL 🐬: Use a local MySQL server or run a Docker container:
docker run -d -p 3306:3306 --name mysql-container \
-e MYSQL_ROOT_PASSWORD=root \
-e MYSQL_DATABASE=mydb \
mysql:latest
Connection Details:
Host: localhost
User: root
Password: root
Database: mydb
- Get a Groq API Key 🔑
Sign up at GROQ CLoud for a Groq API key. Set it as GROQ_API_KEY or enter it in the app.
- Run the App 🎉
streamlit run app.py
- Open the app (http://localhost:8501).
- In the sidebar:
- Choose SQLite or MySQL.
- For SQLite, select a database file.
- For MySQL, enter host, user, password, and database.
- Input your Groq API key (if not set).
Type a query (e.g., "List all orders" or "Visualize sales"). View results, SQL code, and charts. Check query history or download as CSV.gz or JSON.
Ensure SQLite files are readable and MySQL credentials are valid.
Use "visualize" or "chart" for bar charts (requires numeric data).
Stop Docker MySQL with:
docker stop mysql-container
Python 🐍: Core language. Streamlit 🌐: Web app framework. LangChain 🔗: Natural language to SQL. Groq 🤖: Llama-3.3-70b model. SQLAlchemy 🗄️: Database connectivity. MySQL/SQLite 🗃️: Database engines. Pandas 📋: Data handling. Plotly 📊: Visualizations. Docker 🐳: MySQL containerization.
├── Chat-with-Database-SQL
| .env
| .gitignore
| api_key.py
| app.py
| docker-compose.yml
| README.md
| requirements.txt
| structure.txt
|
+---database
| |
| +---local
| | test.db
| +---my_sql
| | my_sql_databases.db
+---data_source
| | README.md
| | | local_source
| | | | test.sql
| | | mysql_source
| | | | test.sql
Made with Love ❤️ by Mohd Anas Khan