Skip to content

kishorekrrish3/QueryMind

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

8 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿงฎ QueryMind

Natural Language to SQL Generator powered by Gemini AI

An AI-powered SQL assistant that converts plain English prompts into executable SQL queries, complete with sample outputs and explanations. Describe the data you want โ€” QueryMind generates the SQL instantly.


Python Streamlit Google Gemini Python Dotenv MIT License


๐Ÿ“– What is QueryMind?

QueryMind is an AI-powered SQL query generator that translates natural language prompts into SQL queries using Googleโ€™s Gemini AI.

Instead of manually writing complex SQL queries, users can simply describe the data they want in plain English, and the system will automatically:

  1. Generate the correct SQL query.
  2. Show a sample tabular output of the expected result.
  3. Provide a human-readable explanation of the query logic.

Built using Streamlit, the application offers an intuitive interface that allows developers, students, and analysts to quickly generate SQL queries without deep database expertise.


โœจ Features

Feature Description
๐Ÿง  AI-Powered SQL Generation Converts natural language prompts into SQL queries
๐Ÿ“Š Sample Output Generation Displays expected result tables
๐Ÿ“– Query Explanation Provides easy-to-understand explanation of SQL logic
โšก Fast Interactive UI Built with Streamlit for rapid interaction
๐Ÿ” Secure API Key Management Uses .env configuration with python-dotenv
๐ŸŽ“ Learning Tool Great for students learning SQL concepts

๐Ÿ—๏ธ System Architecture

Query Generation Pipeline

graph TD
    A[๐Ÿ‘ค User Input - Natural Language] --> B[Streamlit Web Interface]
    B --> C[Prompt Processing]

    C --> D[Google Gemini AI]

    D --> E[SQL Query Generation]
    D --> F[Sample Output Generation]
    D --> G[Query Explanation]

    E --> H[Display Results in UI]
    F --> H
    G --> H
Loading

AI Processing Workflow

The system follows a simple yet effective pipeline:

1๏ธโƒฃ User Prompt

  • The user enters a query request in plain English.

Example:

Retrieve employee names and departments from the employees table where department is Sales

2๏ธโƒฃ AI Interpretation

  • Gemini AI interprets the prompt and understands:

    • table name
    • fields
    • conditions

3๏ธโƒฃ SQL Generation

  • The model generates the corresponding SQL statement.

4๏ธโƒฃ Output Simulation

  • The system generates a sample result table.

5๏ธโƒฃ Explanation

  • Gemini explains the SQL query in simple terms.

๐Ÿ› ๏ธ Technology Stack

Core System

Component Technology
Programming Language Python
Web Framework Streamlit
AI Model Google Gemini AI
Environment Management python-dotenv
Data Processing Python Standard Libraries

๐Ÿ“‚ Project Structure

SQL-Query-Generator-using-Gemini-AI/
โ”‚
โ”œโ”€โ”€ app.py                 # Streamlit application
โ”œโ”€โ”€ query_generator.py     # Gemini AI prompt handler
โ”œโ”€โ”€ utils/
โ”‚   โ””โ”€โ”€ prompt_templates.py
โ”‚
โ”œโ”€โ”€ requirements.txt       # Python dependencies
โ”œโ”€โ”€ .env                   # API key configuration
โ””โ”€โ”€ README.md

๐Ÿš€ Installation & Setup

Prerequisites

  • Python 3.9+
  • Google AI Studio API Key

1๏ธโƒฃ Clone the Repository

git clone https://github.com/kishorekrrish3/SQL-Query-Generator-using-Gemini-AI.git
cd SQL-Query-Generator-using-Gemini-AI

2๏ธโƒฃ Install Dependencies

pip install -r requirements.txt

Or install individually:

pip install streamlit
pip install google-generativeai
pip install python-dotenv

3๏ธโƒฃ Configure API Key

Create a .env file in the project root.

GOOGLE_API_KEY=your_google_api_key_here

The application automatically loads the key using python-dotenv.


๐Ÿƒ Running the Application

Start the Streamlit application:

streamlit run app.py

The application will run locally at:

http://localhost:8501

๐ŸŒ Application Workflow

Step 1 โ€” Enter Natural Language Query

Example prompt:

Retrieve all employee names and departments from the employees table where the department is Sales

Step 2 โ€” Generate SQL

Click Generate SQL Query.

The system sends the prompt to Gemini AI.


Step 3 โ€” View Results

The interface displays:

Output Description
SQL Query Generated SQL statement
Sample Output Example result table
Explanation Human-readable query explanation

๐Ÿ“Š Example Output

Input Prompt

Retrieve all employee names and departments from the employees table where the department is Sales

Generated SQL Query

SELECT name, department
FROM employees
WHERE department = 'Sales';

Expected Output

name department
John Doe Sales
Jane Roe Sales

Explanation

The query retrieves the name and department fields from the employees table, filtering records where the department equals Sales.


โš™๏ธ Configuration

Setting File Description
API Key .env Google Gemini API authentication
Prompt Templates prompt_templates.py Query generation prompts
Streamlit UI app.py Interface and interaction logic

๐Ÿ› Known Issues & Troubleshooting

Gemini API not working

Check that:

  • .env file exists
  • GOOGLE_API_KEY is valid
  • Internet connection is active

Streamlit app not loading

Restart the server:

streamlit run app.py

๐Ÿ”ฎ Future Improvements

  • ๐Ÿง  Database schema awareness
  • ๐Ÿ”— Direct database execution
  • ๐Ÿ“Š Visual query builder
  • ๐Ÿ“š SQL learning mode for beginners
  • ๐Ÿ—‚ Multi-database support (MySQL, PostgreSQL, SQLite)

๐Ÿค Contributing

Contributions are welcome.

  1. Fork the repository
  2. Create a feature branch
  3. Commit your changes
  4. Open a pull request

๐Ÿ“œ License

This project is licensed under the MIT License.



Making databases accessible through natural language.



QueryMind โ€” where English becomes SQL.

About

A Streamlit tool that converts plain English into SQL queries, with sample output and explanations.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages