This is a simple tool built with Streamlit and Google's Gemini AI to help you generate SQL queries from plain English text prompts. The tool interprets your input, generates an SQL query, provides a sample output, and explains the query.
- SQL Query Generation: Translates plain English prompts into SQL query snippets.
- Sample Output: Provides an expected result in a tabular format.
- Explanation: Delivers an easy-to-understand explanation of the generated SQL query.
Make sure you have Python installed. You’ll also need to install Streamlit, Python-dotenv, and Google’s Gemini AI library.
-
Clone the repository:
git clone https://github.com/kishorekrrish3/SQL-Query-Generator-using-Gemini-AI.git cd SQL-Query-Generator-using-Gemini-AI -
Install Dependencies:
pip install -r requirements.txt
(Or, if you prefer individually)
pip install streamlit pip install google-generativeai pip install python-dotenv
-
Set Up API Key using .env:
-
Create a
.envfile in the project root. -
Add your Google API key as follows:
GOOGLE_API_KEY=your_google_api_key_here
-
The app will automatically load this key using
python-dotenv.
-
-
Run the Application:
streamlit run app.py
-
Enter Your Query:
- In the Streamlit app, type a query in plain English into the text area, describing the SQL query you want.
-
Generate:
-
Click on "Generate SQL Query."
-
The application will display:
- The generated SQL query.
- A sample output in tabular form.
- A simple explanation of the SQL query.
-
-
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: Retrieves employee names and departments for all records in the 'employees' table where the department matches 'Sales'.
Feel free to open issues or submit pull requests. Contributions are always welcome!
This project is licensed under the MIT License. See LICENSE for details.
- Streamlit for providing an interactive web framework.
- Google's Gemini AI for enabling natural language SQL query generation.
Happy querying! 🤖