This project aims to convert natural language queries into SQL queries using the latest Google Gemini model. It utilizes Python, SQLite, and the Streamlit library to create a user-friendly interface for querying a database using natural language.
Before running the project, ensure that you have the following dependencies installed:
- Python (version 3.6 or higher)
- SQLite3 (comes pre-installed with Python)
- Streamlit (run
pip install streamlit
to install) - google.generativeai (run
pip install google.generativeai
to install) - python-dotenv (run
pip install python-dotenv
to install)
- Clone the repository or download the source code.
- Navigate to the project directory.
- Create a new SQLite database file named
student.db
in the project directory. - Create a
.env
file in the project directory and add your Google API key with the following format: GOOGLE_API_KEY=your_api_key_here
The project consists of two main files: sql.py
and app.py
.
This file sets up the SQLite database and inserts sample data into the STUDENT
table. Follow these steps:
- Open the
sql.py
file in a text editor or an integrated development environment (IDE). - Modify the
table_info
variable to define the structure of your desired table if needed. - Update the
cursor.execute
statements with your table name and desired data insertions if needed. - Save the changes and run the
sql.py
script.
The script will create the STUDENT
table and insert sample data into it.
This file contains the Streamlit application that allows users to input natural language queries and retrieve data from the SQLite database using the Google Gemini model. Follow these steps:
- Open the
app.py
file in a text editor or an IDE. - Ensure that you have set up the
.env
file with your Google API key. - Run the
app.py
script using the commandstreamlit run app.py
in your terminal or command prompt. - The Streamlit application will open in your default web browser.
- Enter your natural language query in the input field and click the "Submit" button.
- The application will convert your query into an SQL statement, execute it against the
student.db
database, and display the results.
To customize the project for your specific use case, follow these steps:
- Modify the
table_info
variable insql.py
to define the structure of your desired table. - Update the
cursor.execute
statements insql.py
with your table name and desired data insertions. - Modify the prompt in
app.py
to provide the appropriate instructions for the Google Gemini model based on your database schema. - Update the
sql_data_retriver
function inapp.py
to handle any additional logic or error handling specific to your use case.
We welcome contributions to this project! If you find any issues or have suggestions for improvements, please feel free to open an issue or submit a pull request. To contribute code changes, fork the repository, create a new branch, make your changes, and submit a pull request. Please ensure that your code adheres to the project's coding standards and conventions.
We aim to maintain a welcoming and inclusive environment for all contributors. Please respect others and their contributions, use inclusive language, and refrain from any form of harassment, discrimination, or unacceptable behavior.
This project is licensed under the MIT License. You are free to use, modify, and distribute the code as per the terms of the license.