--- title: Student Support Chatbot emoji: 🎓 colorFrom: purple colorTo: indigo sdk: docker pinned: false --- # 🎓 Student Support Chatbot A fully deployed AI-powered RAG (Retrieval-Augmented Generation) chatbot that answers student queries about admissions, fees, courses, campus life, and more. Built with LangChain, Google Gemini, Pinecone, and Flask. --- ## 🏗️ Architecture ``` Student Question ↓ HuggingFace Embeddings (all-MiniLM-L6-v2) ↓ Pinecone Vector DB (semantic search → top 3 results) ↓ Google Gemini LLM (generates final answer) ↓ Flask Web App (chat interface) ``` **Dataset**: [`bot-remains/student-assistance-chatbot`](https://huggingface.co/datasets/bot-remains/student-assistance-chatbot) — 217 student Q&A pairs covering admissions, eligibility, fees, academics, and campus life. --- ## 🛠️ Tech Stack | Layer | Technology | | --------------- | ------------------------------------ | | LLM | Google Gemini 2.5 Flash | | Embeddings | HuggingFace `all-MiniLM-L6-v2` | | Vector Database | Pinecone | | Framework | LangChain | | Web App | Flask | | Deployment | AWS App Runner + Amazon ECR / Docker | --- ## 🚀 How to Run Locally ### Step 1: Clone the repository ```bash git clone https://github.com/aak007/Build-a-Complete-Medical-Chatbot-with-LLMs-LangChain-Pinecone-Flask-AWS.git cd Build-a-Complete-Medical-Chatbot-with-LLMs-LangChain-Pinecone-Flask-AWS ``` ### Step 2: Create and activate conda environment ```bash conda create -n medibot python=3.10 -y conda activate medibot ``` ### Step 3: Install dependencies ```bash pip install -r requirements.txt ``` ### Step 4: Set up environment variables Create a `.env` file in the root directory: ```ini PINECONE_API_KEY=your_pinecone_api_key GOOGLE_API_KEY=your_gemini_api_key # Optional: choose your index name PINECONE_INDEX_NAME=student-chatbot # Dataset source options: hf | local | pdf DATA_SOURCE=hf # If DATA_SOURCE=hf HF_DATASET_NAME=bot-remains/student-assistance-chatbot # If DATA_SOURCE=local (csv/json/jsonl/txt/md) LOCAL_DATASET_PATH=data/my_dataset.csv TEXT_COLUMNS=question,answer # If DATA_SOURCE=pdf (single file or folder) # LOCAL_DATASET_PATH=data/student_buddy_qa.pdf ``` ### Step 5: Index the dataset into Pinecone _(Run only once)_ ```bash python store_index.py ``` This downloads the student Q&A dataset from HuggingFace and stores it as vector embeddings in your Pinecone `student-chatbot` index. ### Use Your Own Dataset You can replace the default dataset with your own data and re-index it. 1. Put your file inside the project, for example `data/my_dataset.csv`. 2. Update `.env`: ```ini DATA_SOURCE=local LOCAL_DATASET_PATH=data/my_dataset.csv TEXT_COLUMNS=question,answer PINECONE_INDEX_NAME=my-student-bot-index ``` 3. Rebuild vectors: ```bash python store_index.py ``` 4. Start app: ```bash python app.py ``` Supported local file formats: - `csv` (recommended) - `json` (array of objects) - `jsonl` (one JSON object per line) - `txt` / `md` (split by blank lines) For PDF knowledge bases: ```ini DATA_SOURCE=pdf LOCAL_DATASET_PATH=data/student_buddy_qa.pdf PINECONE_INDEX_NAME=student-buddy-index ``` Then run: ```bash python store_index.py python app.py ``` Example CSV schema: ```csv question,answer,category What is eligibility for B.Tech?,Candidates must pass 10+2 with PCM and required cutoff,admissions What are hostel fees?,Hostel fees vary by room type and campus policy,fees ``` ### Step 6: Start the app ```bash python app.py ``` ### Step 7: Open in browser ``` http://localhost:7860 ``` --- ## ☁️ Deployment ### AWS App Runner + ECR (Recommended) ```bash # 1. Authenticate Docker to AWS ECR aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin .dkr.ecr.us-east-1.amazonaws.com # 2. Build Docker image docker build --no-cache -t medical-bot . # 3. Tag image docker tag medical-bot:latest .dkr.ecr.us-east-1.amazonaws.com/medical-bot:latest # 4. Push to ECR docker push .dkr.ecr.us-east-1.amazonaws.com/medical-bot:latest ``` Then deploy via AWS App Runner, set **port 7860**, and add your `PINECONE_API_KEY` and `GOOGLE_API_KEY` as environment variables. --- ## 📁 Project Structure ``` ├── app.py # Flask web server ├── store_index.py # Downloads dataset & indexes into Pinecone ├── Dockerfile # Docker config for deployment ├── requirements.txt # Python dependencies ├── setup.py ├── src/ │ ├── helper.py # load_hf_dataset(), text_split(), embeddings │ └── prompt.py # System prompt for student support ├── static/ │ └── style.css # Premium student-themed UI └── templates/ └── chat.html # Chat interface ``` --- ## 🔑 Required API Keys | Key | Where to Get | | ------------------ | ------------------------------------------------------------- | | `PINECONE_API_KEY` | [app.pinecone.io](https://app.pinecone.io/) | | `GOOGLE_API_KEY` | [aistudio.google.com](https://aistudio.google.com/app/apikey) |