{"id":19481428,"url":"https://github.com/gauravooo2/text-to-sql-llm-ai-chatbot","last_synced_at":"2026-07-14T02:31:25.023Z","repository":{"id":259198007,"uuid":"876541900","full_name":"GauravOOO2/Text-To-SQL-LLM-AI-ChatBot","owner":"GauravOOO2","description":null,"archived":false,"fork":false,"pushed_at":"2024-10-22T07:43:08.000Z","size":6,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-25T17:37:08.140Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://text-to-sql-llm-ai-chatbot.onrender.com/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/GauravOOO2.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-22T06:33:44.000Z","updated_at":"2024-10-22T07:52:35.000Z","dependencies_parsed_at":"2024-10-23T12:33:03.777Z","dependency_job_id":null,"html_url":"https://github.com/GauravOOO2/Text-To-SQL-LLM-AI-ChatBot","commit_stats":null,"previous_names":["gauravooo2/text-to-sql-llm-ai-chatbot"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/GauravOOO2/Text-To-SQL-LLM-AI-ChatBot","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GauravOOO2%2FText-To-SQL-LLM-AI-ChatBot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GauravOOO2%2FText-To-SQL-LLM-AI-ChatBot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GauravOOO2%2FText-To-SQL-LLM-AI-ChatBot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GauravOOO2%2FText-To-SQL-LLM-AI-ChatBot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/GauravOOO2","download_url":"https://codeload.github.com/GauravOOO2/Text-To-SQL-LLM-AI-ChatBot/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GauravOOO2%2FText-To-SQL-LLM-AI-ChatBot/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35443979,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-14T02:00:06.603Z","response_time":114,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-10T20:04:47.504Z","updated_at":"2026-07-14T02:31:25.006Z","avatar_url":"https://github.com/GauravOOO2.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# 🧠 AI Chatbot with Gemini LLM, LangChain, SQL, and Streamlit\n\nThis project is an AI-powered chatbot application built using **Google's Gemini LLM**, **LangChain**, **ChromaDB**, and **Streamlit**. The chatbot is specifically designed to retrieve answers based solely on a local SQL database of students' records. This ensures that the bot doesn't generate random or hallucinated answers but provides SQL query-based responses strictly from the dataset.\n\n## 📝 Project Overview\n\nThis chatbot is a data retrieval tool that leverages **Google Gemini's Language Model (LLM)**, allowing it to convert natural language questions into SQL queries. The queries are then run against a local SQLite database, and the results are returned to the user via a simple and intuitive **Streamlit** UI. **LangChain** is used as part of the backend to help integrate the LLM and the SQL query generation process.\n\nThe core idea behind this project is to have a reliable, data-constrained chatbot that will **only answer based on the data available in the database**—it does not generate responses that are not tied to the underlying database. This makes it particularly useful for scenarios where data accuracy and consistency are paramount.\n\n## 🌟 Key Features\n\n1. **Gemini LLM Integration**: The app uses Google's Gemini LLM to process user inputs and convert them into SQL queries dynamically.\n2. **SQL Query Generation**: The bot is capable of transforming user questions into precise SQL queries that retrieve the necessary information from the `STUDENT` table in an SQLite database.\n3. **Data Accuracy**: The chatbot restricts its answers to the information available in the `student.db` SQLite database, preventing random responses.\n4. **Streamlit UI**: A user-friendly interface built with **Streamlit** allows users to input queries and get responses directly from the chatbot.\n5. **LangChain**: Leveraged to build a seamless pipeline between the language model and the database query execution.\n6. **SQLite Database**: The data is stored in a local `SQLite` database (`student.db`), containing information about students such as their name, class, section, and marks.\n7. **Prompt-Based AI**: The chatbot uses a well-defined prompt to guide its behavior, ensuring SQL query generation adheres to the defined schema of the database.\n\n## ⚙️ Technologies Used\n\n- **Google Gemini LLM**: A language model that processes user queries and generates responses.\n- **LangChain**: Used to build robust LLM-powered applications that connect the language model to the database.\n- **ChromaDB**: An optional component that helps manage and store embeddings or vectorized data (currently not fully utilized in this version but can be expanded).\n- **SQLite**: A lightweight SQL database to store the student data.\n- **Streamlit**: A Python framework to build interactive and user-friendly web apps.\n- **Python**: Backend and core logic.\n\n## 🛠️ Setup Instructions\n\nTo run this project locally or on a cloud platform like Render, follow the steps below.\n\n### 1. Clone the Repository\n\n```bash\ngit clone https://github.com/GauravOOO2/Text-To-SQL-LLM-AI-ChatBot.git\ncd Text-To-SQL-LLM-AI-ChatBot\n```\n\n### 2. Install Dependencies\n\nMake sure you have **Python 3.8+** installed. Then, install the required dependencies using `pip`:\n\n```bash\npip install -r requirements.txt\n```\n\n### 3. Set Up Environment Variables\n\nCreate a `.env` file in the project directory and add your **Google API key** for Gemini LLM:\n\n```bash\nGOOGLE_API_KEY=your-google-api-key\n```\n\n### 4. Initialize the SQLite Database\n\nYou can either create the SQLite database (`student.db`) manually, or you can run the `sql.py` script to set up the database with sample student records.\n\nTo create the database with predefined student data:\n\n```bash\npython sql.py\n```\n\n### 5. Run the Streamlit Application\n\nRun the Streamlit app locally using the following command:\n\n```bash\nstreamlit run app.py\n```\n\n### 6. Deploy on Render\n\nIf deploying on Render, ensure you:\n\n1. Set the start command as `streamlit run app.py`.\n2. Include the `Procfile` in the root of your project with the following content:\n\n```bash\nweb: streamlit run app.py\n```\n\n3. Configure the environment variable `GOOGLE_API_KEY` in the Render dashboard.\n\n## 💻 Project Structure\n\n```\n.\n├── app.py                # Main Streamlit app\n├── sql.py                # Script to initialize SQLite database with sample student data\n├── student.db            # SQLite database (optional, can be generated dynamically)\n├── requirements.txt      # Project dependencies\n├── .env                  # Environment variables (not included in repo)\n├── Procfile              # Start command for Render deployment\n└── README.md             # Project documentation (this file)\n```\n\n### File Descriptions\n\n- **`app.py`**: Contains the main logic for the Streamlit web app, including user input handling, invoking the Gemini LLM, and displaying the SQL query results.\n- **`sql.py`**: Initializes an SQLite database with student records, creating the table and populating it with data.\n- **`student.db`**: The SQLite database where student data is stored. It contains the table `STUDENT` with columns for name, class, section, and marks.\n- **`requirements.txt`**: Lists the Python packages required to run the project (Streamlit, google-generativeai, LangChain, etc.).\n\n## 🔍 How It Works\n\n1. **User Query Input**: The user enters a natural language question in the Streamlit app.\n2. **LLM Processing**: The Gemini LLM takes the user question and converts it into an SQL query based on the pre-defined prompt.\n3. **SQL Query Execution**: The SQL query is executed against the local SQLite database (`student.db`).\n4. **Response**: The chatbot displays the query result as the response to the user. The bot **only retrieves and responds with data present in the `STUDENT` table** and does not generate any other information.\n\n### Example Queries:\n- **User**: *\"Tell me all students studying in AI \u0026 ML class?\"*\n- **Bot**: *SELECT * FROM STUDENT WHERE CLASS='AI \u0026 ML';*\n  \n  **Response**: `Emily Davis, Michael Brown`\n\n- **User**: *\"How many students are there in total?\"*\n- **Bot**: *SELECT COUNT(*) FROM STUDENT;*\n  \n  **Response**: `10`\n\n## 🚀 Future Enhancements\n\n- **Expand Dataset**: Include more detailed data fields (e.g., grades, attendance, etc.) to make the chatbot more informative.\n- **ChromaDB Integration**: Fully integrate ChromaDB for better vector search and embedding management, expanding the bot's ability to understand queries beyond simple SQL.\n- **Enhanced UI**: Improve the frontend design with additional features like charts and visual data representations.\n- **Error Handling**: Add more robust error handling for invalid or out-of-scope queries.\n\n## 🧑‍💻 Contributing\n\nContributions are welcome! If you'd like to improve this project or add new features, feel free to open a pull request.\n\n1. Fork the project.\n2. Create a new feature branch.\n3. Submit a pull request detailing your changes.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgauravooo2%2Ftext-to-sql-llm-ai-chatbot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgauravooo2%2Ftext-to-sql-llm-ai-chatbot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgauravooo2%2Ftext-to-sql-llm-ai-chatbot/lists"}