This project provides a Gradio-based web application that allows users to interact with an SQLite database using natural language queries. It leverages the LangChain library and OpenAI's language model to convert plain English questions into SQL queries and execute them on the provided database.
Try the app: https://sabagul-text-to-sql.hf.space/
- Upload SQLite Database: Upload an SQLite database file to the application.
- Natural Language Queries: Enter plain English queries to retrieve data from the database.
- Real-time Results: Get results from your database based on your queries.
To set up and run this application locally, follow these steps:
git clone https://github.com/Saba-Gul/Text-to-SQL.git
cd text-to-sql
python -m venv venv
source venv/bin/activate # On Windows use `venv\Scripts\activate`
pip install -r requirements.txt
Create a .env
file in the root of the project and add your OpenAI API key:
OPENAI_API_KEY=your-openai-api-key-here
python app.py
This application can be deployed on Hugging Face Spaces or any other platform that supports Python and environment variables.
- Create a New Space: Go to Hugging Face Spaces and create a new space.
- Add Secrets: In your space settings, add a secret named
OPENAI_API_KEY
with your OpenAI API key as the value. - Upload Code: Push your code to the repository connected to your Hugging Face Space.
- Open the Application: Navigate to the URL provided by your Hugging Face Space or local server.
- Upload Database: Use the file upload component to upload an SQLite database file.
- Query the Database: Enter your SQL query in plain English and click "Run Query" to see the results.
- "How many rows are there?"
- "What is the total revenue by month?"
- "Which product line had the largest revenue?"
- "Which day of the week has the best average ratings for each branch?"