File size: 5,443 Bytes
45b17a5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
---
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 <account-id>.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 <account-id>.dkr.ecr.us-east-1.amazonaws.com/medical-bot:latest

# 4. Push to ECR
docker push <account-id>.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) |