This project showcases the capabilities of combining OpenAI's GPT-4 with Streamlit to generate SQL queries based on natural language input. Users can enter a message describing the data they want to query from an SQLite database, and the application will display the generated SQL query as well as the results from the database.
- Natural Language to SQL: Uses GPT-4 to transform user's natural language input into an SQL query.
- Streamlit Interface: Provides a simple and intuitive interface for users to input their queries.
- SQLite Backend: Uses SQLite as the database backend to store and query the financial data.
- Python 3.6 or above
- Virtual Environment (recommended)
-
Clone the Repository:
git clone https://github.com/NikhilSehgal123/Azure-OpenAI-SQL.git
-
Set up a Virtual Environment (optional but recommended):
python -m venv .venv source .venv/bin/activate # On Windows, use: .venv\Scripts\activate
-
Install the Dependencies:
pip install -r requirements.txt
-
Set up Environment Variables:
If you're using any external services like Azure or APIs, make sure you have the credentials set up as environment variables or stored safely.
-
Run the Streamlit App:
streamlit run main_app_streamlit.py
-
Open the displayed URL in your browser, usually
http://localhost:8501
. -
Type in your natural language query into the input box, like "Show me all expenses greater than 1000".
-
View the generated SQL query and the results from the database.
-
SQLite Database:
The app uses SQLite to create a table representing a company's finances. It holds fields like revenue, expenses, and profit.
-
Schema Retrieval:
Before generating a query, the system retrieves the schema of the table from SQLite to understand its structure.
-
GPT-4 Model:
The main functionality relies on the GPT-4 model to convert a user's natural language input into an SQL query. The app sends a formatted message containing the table's schema to GPT-4, which then returns an appropriate SQL query.
-
Query Execution:
The app then executes the generated SQL query on the SQLite database and retrieves the results.
Feel free to fork this repository, create a feature branch, and submit a pull request if you have improvements or fixes you'd like to share.
This project is open source, under the MIT license.