Chatbot Agent with SQL and Gemini Integration
A powerful chatbot agent that integrates Google's Gemini language model with SQL database connectivity, enabling natural language to SQL query conversion and data visualization.
π Features
- Natural Language to SQL: Convert natural language questions into SQL queries
- Database Integration: Connect to MySQL databases seamlessly
- Interactive Chat Interface: User-friendly Gradio-based web interface
- Data Visualization: Generate visualizations from query results
- Environment Configuration: Easy setup with environment variables
π Quick Start
Prerequisites
- Python 3.8 or higher
- MySQL database (or compatible database)
- Google API key for Gemini
Installation
Clone the repository:
git clone https://github.com/yourusername/chatbot-agent-sql-gemini.git cd chatbot-agent-sql-gemini
Install dependencies:
pip install -r requirements.txt
Create a
.env
file in the project root with your configuration:DB_USER=your_db_username DB_PASSWORD=your_db_password DB_HOST=your_db_host DB_NAME=your_database_name GOOGLE_API_KEY=your_google_api_key
Running the Application
Start the application:
python app.py
Open your web browser and navigate to
http://localhost:7860
π οΈ Configuration
The application can be configured using the following environment variables:
Variable | Description | Required |
---|---|---|
DB_USER |
Database username | β |
DB_PASSWORD |
Database password | β |
DB_HOST |
Database host | β |
DB_NAME |
Database name | β |
GOOGLE_API_KEY |
Google API key for Gemini | β |
π¦ Dependencies
- gradio >= 3.0.0
- langchain >= 0.1.0
- langchain-community >= 0.0.10
- langchain-google-genai >= 0.1.0
- langgraph >= 0.0.0
- matplotlib >= 3.7.0
- pandas >= 2.0.0
- sqlalchemy >= 2.0.0
- python-dotenv >= 1.0.0
π€ How It Works
- The application connects to your SQL database using the provided credentials
- Users input natural language questions through the Gradio interface
- The Gemini model converts these questions into SQL queries
- Queries are executed against the database
- Results are formatted and displayed to the user
- For appropriate data, visualizations are automatically generated
π Example Queries
- "Show me the top 10 customers by total purchases"
- "What were our total sales last month?"
- "List all products with stock below minimum levels"
- "Generate a bar chart of monthly sales for the past year"
π License
This project is licensed under the MIT License - see the LICENSE file for details.
π Acknowledgments
- Gradio for the web interface
- Google Gemini for the language model
- LangChain for the agent framework