Made by Harsh Gidwani
🚀 Live Demo Available Here - Try the application without any setup!
A powerful Streamlit application that allows you to chat with SQL databases using natural language queries powered by LangChain and Groq's Llama model.
- Multiple Database Support:
- SQLite Student Database
- SQLite Customer Transactions Database (100+ records)
- MySQL Database Connection
- Natural Language Queries: Ask questions in plain English
- Real-time Chat Interface: Interactive chat experience with streaming responses
- Secure API Key Handling: Protected API key input
- Database Schema Discovery: Automatic table and column detection
- Transaction History: Maintains chat history with clear option
Pre-built SQLite database containing student information.
Contains 100+ realistic customer transaction records with:
- 50 unique customers with complete profiles
- 100 transactions across multiple categories
- Various payment methods and transaction types
- Realistic date ranges and amounts
Connect to your own MySQL database by providing:
- Host address
- Username and password
- Database name
-
Clone the repository
git clone <repository-url> cd "6-Chat SQL"
-
Install dependencies
pip install streamlit langchain langchain-groq sqlalchemy sqlite3 mysql-connector-python faker pathlib
-
Generate Customer Database (if not already present)
python create_customer_db.py
-
Get Groq API Key
- Sign up at Groq Console
- Generate an API key
- Keep it secure for use in the application
-
Start the application
streamlit run app.py
-
Configure the application
- Select your preferred database from the sidebar
- Enter your Groq API key
- For MySQL: provide connection details
-
Start chatting
- Ask questions like:
- "Show me all students with grades above 90"
- "What's the total sales amount by category?"
- "Which customers made the most purchases?"
- "Show me all transactions from last month"
- Ask questions like:
- "How many students are in the database?"
- "Show me students from a specific city"
- "What's the average age of students?"
- "Show me all transactions above $500"
- "Which payment method is most popular?"
- "What's the total revenue by product category?"
- "Show me all refunded transactions"
- "Who are the top 5 customers by transaction amount?"
- Ask any question relevant to your database schema
6-Chat SQL/
├── app.py # Main Streamlit application
├── create_customer_db.py # Script to generate customer database
├── student.db # Student database (SQLite)
├── customer_transactions.db # Customer transactions database (SQLite)
├── assets/
│ └── image.png # Demo screenshot
├── .gitignore # Git ignore file
└── README.md # This file
- Streamlit: Web application framework
- LangChain: LLM application framework
- Groq: Fast LLM inference
- SQLAlchemy: Database toolkit
- SQLite: Embedded database
- MySQL: Relational database
- Faker: Generate realistic test data
You can set your Groq API key as an environment variable:
export GROQ_API_KEY=your_api_key_here
- Ensure
student.db
andcustomer_transactions.db
are in the project root - For MySQL connections, ensure the database server is accessible
-
API Key Error
- Ensure you've entered a valid Groq API key
- Check if the API key has proper permissions
-
Database Connection Failed
- Verify database files exist in the correct location
- For MySQL: check connection details and network access
-
Query Errors
- The AI might need clarification for complex queries
- Try rephrasing your question
- Check if the requested data exists in the database
The api_key client option must be set
: Enter your Groq API keyPlease provide all MySQL connection details
: Fill in all MySQL fields- Database connection errors: Check file paths and permissions
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
This project is open source and available under the MIT License.
If you encounter any issues or have questions:
- Check the troubleshooting section
- Review the error messages carefully
- Ensure all dependencies are installed correctly
- Verify your API key is valid
- Support for PostgreSQL databases
- Query result visualization
- Export chat history
- Multiple AI model options
- Database schema visualization
- Query performance metrics
Made by Harsh Gidwani