MySQL-Database-Chatbot is a Streamlit based application that allows users to interact with a MySQL database through natural language queries. It uses the langchain
and langchain_groq
libraries to convert user queries into SQL, execute them on the database, and return results in natural language.
- Connect to a MySQL database
- Ask natural language questions about the database
- Get SQL queries generated and executed based on your questions
- Receive results in natural language
-
Clone the repository:
git clone https://github.com/yourusername/mysql-chatbot.git cd mysql-chatbot
-
Create and activate a virtual environment:
python -m venv venv source venv/bin/activate # On Windows, use `venv\Scripts\activate`
-
Install the dependencies:
pip install -r requirements.txt
-
Create a
.env
file in the root directory of your project and add yourgroq
api key:GROQ_API_KEY=<your_groq_api_key>
-
Run the Streamlit application:
streamlit run app.py
-
Open your web browser and go to
http://localhost:8501
. -
In the sidebar, enter your MySQL database connection details and click
Connect
. -
Once connected, you can start asking questions about your database.
This is the main file of the application. It contains the following key functions:
init_database
: Initializes the database connection using provided credentials.get_sql_chain
: Sets up the SQL query generation chain usinglangchain
.get_response
: Generates a natural language response based on the SQL query and its result.
The main Streamlit application interface is also defined in this file, including the sidebar for database connection and the main chat interface.
dotenv
: For loading environment variables from a.env
file.langchain_core
,langchain_community
,langchain_groq
: For setting up the language model and processing natural language queries.streamlit
: For creating the web interface.