Query any SQLite database using plain English!
This project converts natural language to SQL using LangChain and Groqβs LLaMA3 model, executes the generated SQL against a specified SQLite database, and displays results in a sleek Streamlit web interface.
.
βββ app.py # Streamlit app for user interaction
βββ database.py # Optional script to create/populate a sample DB
βββ your_database.db# SQLite DB file (user-provided or auto-loaded)
βββ requirements.txt
βββ README.md
- π¬ Convert English questions into SQL using LLaMA3 via Groq API
- π Support for any SQLite database
- π§ Auto-extracts and feeds database schema to the LLM
- π View query results in an interactive table
- π₯ Download results as CSV
- π Toggle to view a plain-English explanation of the SQL
- π Auto-render bar charts for
COUNT,AVG,SUMqueries
To support any SQLite .db file:
-
Replace the default
student.dbwith your own.dbfile -
In
app.py, modify theDB_PATHvariable:DB_PATH = "your_database.db"
-
Make sure the schema is readable. The code automatically extracts table/column names using:
SELECT name FROM sqlite_master WHERE type='table'; PRAGMA table_info(table_name);
-
This schema is sent to LLaMA3 to help it generate accurate SQL for your specific database.
git clone https://github.com/yourusername/nl2sql-interface.git
cd nl2sql-interfaceCreate a requirements.txt file with:
streamlit
pandas
langchain
langchain-groqThen install:
pip install -r requirements.txtFor Linux/macOS:
export GROQ_API_KEY=your_groq_api_keyFor Windows (CMD):
set GROQ_API_KEY=your_groq_api_key- Use
student.db(provided), or - Replace it with your own
.dbfile and update theDB_PATHinapp.py
streamlit run app.pyTry questions like:
- "How many records are there in each table?"
- "Show all entries from the
employeestable." - "What is the average salary by department?"
- "List customers who spent more than $500."
- Python 3.7+
- SQLite β lightweight relational database
- Streamlit β frontend UI
- LangChain β framework for LLM chaining
- Groq + LLaMA3 β LLM backend for NLβSQL
This project is licensed under the MIT License.
Thanks to these amazing tools:
β¨ Build once, query any database with the power of language + LLMs!