Gemini-Powered SQL Code Generator This project is a simple yet powerful web application that leverages the Google Gemini API to translate natural language descriptions into SQL queries. It provides a user-friendly interface for generating complex database queries without needing to write the SQL code manually.
β¨ Features Natural Language to SQL: Effortlessly generate SQL queries by typing what you need in plain English.
Gemini API Integration: Utilizes the advanced capabilities of the Gemini model for accurate and context-aware code generation.
Easy-to-Use Web Interface: A straightforward web page for entering prompts and viewing the generated SQL code.
Secure API Key Management: Uses a .env file to securely store your API key, keeping it separate from your codebase.
βοΈ Prerequisites Before you get started, ensure you have the following installed on your machine:
Python 3.7+: Download the latest version from python.org.
pip: Python's package installer, which comes with Python.
Gemini API Key: An active API key from Google AI Studio. You can create one for free here.
π Installation & Setup Follow these steps to set up and run the project locally.
Clone the Repository
If you are using Git, clone the project to your local machine.
Bash
git clone https://github.com/your-username/your-project.git cd your-project Alternatively, if you received a .zip file, extract all contents into a new folder and navigate into it using your terminal.
Install all the required Python libraries
Configure Your API Key
Create a file named .env in the root directory of your project. Open it with a text editor and add your Gemini API key in the following format:
GEMINI_API_KEY="YOUR_API_KEY_HERE" Replace "YOUR_API_KEY_HERE" with the actual key you obtained from Google AI Studio.
Start the Application
From your terminal, with the virtual environment active, run the main Python script.
Bash
python app.py Access the Web Interface
The application will start a local web server. Open your web browser and navigate to the following address:
http://127.0.0.1:5000 Generate SQL
On the web page, enter your natural language request in the input box (e.g., "select all users from the users table where their age is greater than 30").
Click the "Generate SQL" button.
The generated SQL code will appear in the output box below.
π Project Structure This is a typical structure for a web application using a framework like Flask.
/your-project βββ app.py # The main application script βββ backend/ # Likely contains additional Python modules or logic βββ static/ # Contains static assets like CSS, JavaScript, and images βββ templates/ # Contains HTML template files for the web interface β βββ index.html βββ .env # Your API key configuration file (user-created) βββ .gitignore # Tells git which files to ignore βββ requirements.txt # List of Python dependencies