A powerful AI-powered database query tool that translates natural language questions into SQL queries using Nebius AI. This application allows users to interact with their MySQL databases using plain English, making database operations accessible to non-technical users.
- 🗄️ Natural Language Processing: Ask database questions in plain English
- 🤖 AI-Powered SQL Generation: Uses Nebius AI to convert questions to SQL
- 📊 Interactive Results: View query results in clean, sortable tables
- 📝 Business Insights: Get AI-generated explanations of query results
- 📚 Query History: Track all your previous queries and results
- 🔍 SQL Preview: Review generated SQL before execution
- ⚙️ Easy Configuration: Simple setup with API keys and connection strings
- 🔒 Secure Connections: SSL-enabled database connections
- 🎯 Example Questions: Quick-start with pre-built examples
- Python 3.10+
- Nebius AI API key
- GibsonAI DB connection
- MySQL database access
-
Clone the repository:
git clone https://github.com/Arindam200/awesome-ai-apps.git cd simple_ai_agents/talk_to_db -
Install the required dependencies:
uv sync
-
Create a
.envfile in the project root and add your API key:NEBIUS_API_KEY=your_nebius_api_key
-
Start the Streamlit application:
uv run streamlit run app.py
-
Open your web browser and navigate to the provided local URL (typically http://localhost:8501)
-
Configure your settings in the sidebar:
- Nebius API Key: Enter your Nebius AI API key
- Database Connection String: Enter your MySQL connection string from GibsonAI
-
Ask questions in plain English:
- "What are the product categories we have?"
- "Show me all products with their prices"
- "How many orders do we have?"
- "What are the top 5 most expensive products?"
- "Show me users and their order counts"
-
Review the generated SQL query
-
Execute the query to see results
-
Get AI-generated explanations of the results
The application supports MySQL databases. Enter your connection string in the format:
mysql://username:password@host/database
- SELECT queries: Data retrieval and analysis
- Complex JOINs: Multi-table queries
- Aggregations: COUNT, SUM, AVG operations
- Filtering: WHERE clauses and conditions
- Sorting: ORDER BY operations
- Limiting: LIMIT clauses for large datasets
- "Show me all users who made orders"
- "What's the total revenue from completed orders?"
- "Which products are out of stock?"
- "Find the most popular product categories"
- "Show me recent orders with customer details"
- Nebius AI API Key: Get your API key from https://studio.nebius.com/
- UI Layer (
app.py): Streamlit interface and user interactions - Database Layer (
database.py): Connection management and query execution - AI Layer (
ai_services.py): Natural language processing and SQL generation
- Connection String Parser: Safely parses MySQL connection strings
- SQL Translator: Converts natural language to SQL using Nebius AI
- Result Explainer: Provides business insights from query results
- Query History: Tracks and displays previous queries
- Ask a Question: "What are the top 5 most expensive products?"
- AI Generates SQL:
SELECT id, name, price FROM product ORDER BY price DESC LIMIT 5 - Review SQL: Check the generated query before execution
- Execute Query: Run the query and see results
- Get Explanation: AI explains the results in plain English
- Save to History: Query is saved for future reference
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
