|
# Chatbot Agent with SQL and Gemini Integration |
|
|
|
[](https://opensource.org/licenses/MIT) |
|
[](https://www.python.org/downloads/) |
|
[](https://gradio.app/) |
|
|
|
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 |
|
|
|
1. Clone the repository: |
|
```bash |
|
git clone https://github.com/yourusername/chatbot-agent-sql-gemini.git |
|
cd chatbot-agent-sql-gemini |
|
``` |
|
|
|
2. Install dependencies: |
|
```bash |
|
pip install -r requirements.txt |
|
``` |
|
|
|
3. Create a `.env` file in the project root with your configuration: |
|
```env |
|
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 |
|
|
|
1. Start the application: |
|
```bash |
|
python app.py |
|
``` |
|
|
|
2. 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 |
|
|
|
1. The application connects to your SQL database using the provided credentials |
|
2. Users input natural language questions through the Gradio interface |
|
3. The Gemini model converts these questions into SQL queries |
|
4. Queries are executed against the database |
|
5. Results are formatted and displayed to the user |
|
6. 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](LICENSE) file for details. |
|
|
|
## π Acknowledgments |
|
|
|
- [Gradio](https://gradio.app/) for the web interface |
|
- [Google Gemini](https://ai.google.dev/) for the language model |
|
- [LangChain](https://www.langchain.com/) for the agent framework |
|
|