Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

About

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.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

7 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DataTalk Pro 💬

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.

🌟 Features

  • 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

🚀 Technologies Used

  • 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

📋 Prerequisites

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

🛠️ Installation

  1. Clone the repository

    git clone https://github.com/yourusername/DataTalk-Pro.git
    cd DataTalk-Pro
  2. Create a virtual environment (recommended)

    python -m venv venv
    venv\Scripts\activate  # On Windows
    # source venv/bin/activate  # On macOS/Linux
  3. Install dependencies

    pip install -r requirements.txt
  4. Set up environment variables

    Create a .env file 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 .env file

🎯 Usage

  1. Start the application

    streamlit run src/app.py
  2. 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., localhost or sql8.freesqldatabase.com)
      • Port (default: 3306)
      • Username
      • Password
      • Database name
    • Click the "Connect" button
  3. 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"

💡 Example Queries

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

📁 Project Structure

DataTalk-Pro/
│
├── src/
│   └── app.py              # Main application file
│
├── .env                    # Environment variables (create this)
├── requirements.txt        # Project dependencies
└── README.md              # Project documentation

🔒 Security Features

  • 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 .env file

⚙️ Configuration

Default Settings

The application comes with some default database credentials in the sidebar for quick testing. Remove or change these before deploying to production.

Customizing the AI Model

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)

🐛 Troubleshooting

Connection Issues

  • 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

API Key Issues

  • Ensure your .env file is in the root directory
  • Verify the API key is valid and active
  • Check if you have remaining API quota

Installation Issues

# If you encounter MySQLdb errors, install:
pip install pymysql

# If streamlit doesn't start:
pip install --upgrade streamlit

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

📝 License

This project is licensed under the MIT License - see the LICENSE file for details.

👨‍💻 Author

Your Name

🙏 Acknowledgments

  • 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

📞 Support

If you encounter any issues or have questions:

🔮 Future Enhancements

  • 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.

About

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.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages