An AI-powered application that allows users to query a SQLite database using natural language. Built with Streamlit, LangChain, and Groq (Llama 3.1).
- Natural Language Processing: Converts English questions into valid SQL queries.
- Live Execution: Runs generated queries against a local SQLite database and displays results.
- Streamlit UI: A clean, interactive web interface for user input and data visualization.
- Dockerized: Easy to deploy and run in a containerized environment.
├── main.py # Streamlit application logic
├── database.py # Script to initialize and seed the SQLite DB
├── requirements.txt # Python dependencies
├── .env # Environment variables (API Keys)
├── .gitignore # Files excluded from Git
├── Dockerfile # Docker configuration
└── student.db # SQLite database (generated locally)
git clone [https://github.com/aniketbhoy/Text-to-SQL.git](https://github.com/aniketbhoy/Text-to-SQL.git)
cd Text-to-SQL
Create a .env file in the root directory and add your Groq API Key:
GROQ_API_KEY=your_lp_api_key_here
It is recommended to use a virtual environment:
# Create virtual environment
python -m venv myenv
# Activate it (Mac/Linux)
source myenv/bin/activate
# Install dependencies
pip install -r requirements.txt
# Initialize the database
python database.py
# Run the app
streamlit run main.py
This project is fully containerized. You can build and run it without needing to install Python locally.
Build the image:
docker build -t text-to-sql:latest .Run the container:
docker run -p 8501:8501 --env-file .env text-to-sql
Then visit http://localhost:8501 in your browser.
The app queries a STUDENT table with the following structure:
| Column | Type | Description |
|---|---|---|
| NAME | VARCHAR | Name of the student |
| COURSE | VARCHAR | Subject of study |
| SECTION | VARCHAR | Class section (A, B, etc) |
| MARKS | INT | Exam score |
- "How many students are there?"
- "Show me all students in the Data Science course."
- "Who got the highest marks in Section A?"
- "List the names of students in DEVOPS."
Distributed under the MIT License. See LICENSE for more information.
---