This is a Streamlit-based application that converts natural language questions into SQL queries and retrieves data from a SQLite database. It uses:
- π€ Google Generative AI (Gemini 2.0 Flash) for natural language to SQL conversion
- ποΈ SQLite for database operations
- π₯οΈ Streamlit for the web interface
- π― Smart prompt engineering for accurate SQL generation
- Clone the repository (if you haven't yet)
git clone https://github.com/yourusername/your-repo-name.git
cd your-repo-name- Install dependencies:
pip install -r requirements.txt- Create a .env file in the project root and add your API key:
GOOGLE_API_KEY=your_google_api_key- Prepare your SQLite database:
- Ensure you have a
student.dbfile in your project root - The database should contain a
STUDENTtable with columns:NAME,CLASS,SECTION,MARKS
- Ensure you have a
The application expects a SQLite database with the following structure:
CREATE TABLE STUDENT (
NAME TEXT,
CLASS TEXT,
SECTION TEXT,
MARKS INTEGER
);Start the Streamlit app:
streamlit run app.py- Enter your question in natural language (e.g., "How many students are in Data Science class?")
- The app uses Google Gemini to convert your question into a SQL query
- The generated SQL query is executed against the SQLite database
- Results are displayed in the Streamlit interface
-
"How many entries of records are present?"
- Generates:
SELECT COUNT(*) FROM STUDENT
- Generates:
-
"Tell me all the students studying in Data Science class?"
- Generates:
SELECT * FROM STUDENT WHERE CLASS = 'Data Science'
- Generates:
-
"Show me students with marks greater than 80"
- Generates:
SELECT * FROM STUDENT WHERE MARKS > 80
- Generates:
- β Natural language to SQL conversion
- β Real-time query execution
- β Clean and intuitive web interface
- β Error handling for database operations
- β Smart prompt engineering for accurate results
- The database file
student.dbmust be present in the project root - Queries are limited to the STUDENT table structure
- The app automatically handles SQL formatting and execution
- No SQL injection protection - use only for trusted environments
streamlit
google-generativeai
python-dotenv
sqlite3