A conversational AI-powered application that allows you to interact with your MySQL database using natural language. Ask questions about your data in plain English, and get intelligent responses with SQL query generation and execution powered by Google's Gemini AI.
- Natural Language Querying: Ask questions about your database in plain English
- AI-Powered SQL Generation: Automatically generates SQL queries based on your questions
- Conversational Interface: Maintains chat history for context-aware responses
- Interactive UI: Built with Streamlit for a smooth user experience
- Real-time Database Connection: Connect to any MySQL database with custom credentials
- Table Formatting: Responses include formatted tables when applicable
- Safety Features: Prevents execution of dangerous SQL operations (DELETE, DROP, UPDATE, ALTER)
- Context-Aware: Uses conversation history to provide better responses
- Python 3.8+
- Streamlit: Web application framework
- LangChain: Framework for building LLM applications
- Google Gemini AI: Large language model (gemini-2.5-flash-lite)
- MySQL: Database system
- PyMySQL: MySQL database connector
- SQLAlchemy: SQL toolkit and ORM
Before running this project, make sure you have:
- Python 3.8 or higher installed
- MySQL database access (host, port, username, password, database name)
- Google API key for Gemini AI
-
Clone the repository
git clone https://github.com/yourusername/DataTalk-Pro.git cd DataTalk-Pro -
Create a virtual environment (recommended)
python -m venv venv venv\Scripts\activate # On Windows # source venv/bin/activate # On macOS/Linux
-
Install dependencies
pip install -r requirements.txt
-
Set up environment variables
Create a
.envfile in the root directory:GOOGLE_API_KEY=your_google_api_key_here
To get a Google API key:
- Visit Google AI Studio
- Sign in with your Google account
- Create a new API key
- Copy and paste it into your
.envfile
-
Start the application
streamlit run src/app.py
-
Connect to your database
- The app will open in your browser (typically at
http://localhost:8501) - In the sidebar, enter your MySQL database credentials:
- Host (e.g.,
localhostorsql8.freesqldatabase.com) - Port (default:
3306) - Username
- Password
- Database name
- Host (e.g.,
- Click the "Connect" button
- The app will open in your browser (typically at
-
Start chatting
- Once connected, type your questions in the chat input
- Examples:
- "How many employees are there in each department?"
- "Show me the top 5 highest paid employees"
- "What is the average salary by department?"
- "List all employees hired in 2023"
User: How many employees are in the database?
AI: Generates and executes SQL, then responds with the count
User: Show me the top 3 departments with the most employees
AI: Returns a formatted table with department names and employee counts
User: What's the average salary in the IT department?
AI: Calculates and presents the average salary
DataTalk-Pro/
│
├── src/
│ └── app.py # Main application file
│
├── .env # Environment variables (create this)
├── requirements.txt # Project dependencies
└── README.md # Project documentation
- Dangerous Query Prevention: The application blocks execution of potentially harmful SQL operations:
- DELETE
- DROP
- UPDATE
- ALTER
- Password Protection: Database passwords are masked in the UI
- Environment Variables: API keys are stored securely in
.envfile
The application comes with some default database credentials in the sidebar for quick testing. Remove or change these before deploying to production.
You can change the Gemini model by modifying the model parameter in app.py:
llm = ChatGoogleGenerativeAI(model="gemini-2.5-flash-lite")Available models:
gemini-2.5-flash-lite(faster, lightweight)gemini-pro(more powerful)gemini-pro-vision(for image support)
- Verify your database credentials
- Ensure your database server is running
- Check if the port is correct (default MySQL port is 3306)
- Verify firewall settings allow connections
- Ensure your
.envfile is in the root directory - Verify the API key is valid and active
- Check if you have remaining API quota
# If you encounter MySQLdb errors, install:
pip install pymysql
# If streamlit doesn't start:
pip install --upgrade streamlitContributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
Your Name
- GitHub: @AbraraliS
- Email: your.email@example.com
- Google Gemini AI for powering the natural language understanding
- LangChain for the excellent LLM framework
- Streamlit for the intuitive web framework
- The open-source community
If you encounter any issues or have questions:
- Open an issue on GitHub
- Contact: sunasaraabrarali@gmail.com
- Support for PostgreSQL and other databases
- Query history and export functionality
- Multi-user authentication
- Advanced data visualization
- Query optimization suggestions
- Support for complex joins and subqueries
- Database schema visualization
- Export results to CSV/Excel
Note: Always ensure you're connecting to databases you have permission to access, and never share your API keys or database credentials publicly.