https://github.com/kunalmishravitb/medical-chatbot
MediNeuron is an AI-powered medical chatbot leveraging Llama 2 and Pinecone to deliver precise, literature-based health insights through an interactive Flask app.
https://github.com/kunalmishravitb/medical-chatbot
flask langchain llama2 meta pinecone python sentence-transformers vector-database
Last synced: 4 months ago
JSON representation
MediNeuron is an AI-powered medical chatbot leveraging Llama 2 and Pinecone to deliver precise, literature-based health insights through an interactive Flask app.
- Host: GitHub
- URL: https://github.com/kunalmishravitb/medical-chatbot
- Owner: kunalmishravitb
- License: mit
- Created: 2025-07-04T05:08:39.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2025-07-04T06:29:16.000Z (about 1 year ago)
- Last Synced: 2025-07-17T16:02:26.319Z (about 1 year ago)
- Topics: flask, langchain, llama2, meta, pinecone, python, sentence-transformers, vector-database
- Language: Jupyter Notebook
- Homepage:
- Size: 10.5 MB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# π©Ί MediNeuron: End-to-End Medical Chatbot using Llama 2
## π Project Overview
During the pandemic, I encountered the challenge of finding reliable, understandable medical information online. Motivated by this, I developed an AI-powered Medical Chatbot to provide users with accurate medical responses sourced from trusted medical encyclopedias rather than scattered online content. This project integrates Metaβs Llama 2 model with a vector database to create a domain-specific chatbot capable of answering medical queries with precision.
## βοΈ How It Works
* **Data Ingestion**: A medical encyclopedia PDF is collected as the knowledge base.
* **Text Chunking**: The large document is split into overlapping text chunks to preserve context and fit model token limits.
* **Embeddings Creation**: Chunks are converted into embeddings using sentence-transformers.
* **Vector Database**: Embeddings are stored in Pinecone for fast similarity searches.
* **Query Handling**:
* User queries are converted into embeddings.
* Pinecone retrieves relevant chunks.
* Retrieved text and the original query are fed into Llama 2 for generating context-aware answers.
* **Model Optimization**: A quantized 7B parameter version of Llama 2 is used to reduce memory requirements while maintaining accuracy.
* **Web Interface**: Built with Flask to provide an interactive user experience.
## π Tech Stack
* Python
* Meta Llama2
* LangChain
* Pinecone
* Flask
* sentence-transformers
## π Security
* API keys and sensitive information are stored in a `.env` file to ensure security and prevent accidental exposure.
## π Project Structure
```
MEDICAL-CHATBOT/
β
βββ data/
β βββ Medical_book.pdf # Medical encyclopedia PDF
β
βββ model/
β βββ llama-2-7b-chat.ggmlv3.q4_0.bin # Quantized Llama 2 model file
β
βββ research/
β βββ trials.ipynb # Jupyter notebook for experiments
β
βββ src/
β βββ __init__.py
β βββ helper.py # Helper functions for processing
β βββ prompt.py # Prompt engineering utilities
β
βββ static/
β βββ .gitkeep
β βββ style.css # Custom CSS for web UI
β
βββ templates/
β βββ chat.html # HTML template for the chat UI
β
βββ venv/ # Virtual environment
β
βββ .env # Environment variables (Pinecone keys)
βββ .gitignore # Git ignore file
βββ LICENSE # MIT License file
βββ app.py # Flask web application
βββ requirements.txt # Project dependencies
βββ setup.py # Setup script for packaging (if needed)
βββ store_index.py # Script to store embeddings in Pinecone
βββ template.py # Script for creating folder structure
βββ README.md # Project documentation
```
## π How to Run
### Step 1: Clone the Repository
```bash
git clone https://github.com/kunalmishravitb/Medical-Chatbot.git
cd Medical-Chatbot
```
### Step 2: Create a Conda Environment
```bash
conda create -n venv python=3.10 -y
conda activate venv
```
### Step 3: Install Dependencies
```bash
pip install -r requirements.txt
```
### Step 4: Configure Environment Variables
Create a `.env` file in the root directory with:
```
PINECONE_API_KEY = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
PINECONE_API_ENV = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
```
### Step 5: Download Llama 2 Model
* Download the quantized model file:
* `llama-2-7b-chat.ggmlv3.q4_0.bin`
* From: [https://huggingface.co/TheBloke/Llama-2-7B-Chat-GGML/tree/main](https://huggingface.co/TheBloke/Llama-2-7B-Chat-GGML/tree/main)
* Place the file in the `model/` directory.
### Step 6: Build the Vector Index
```bash
python store_index.py
```
### Step 7: Launch the Web Application
```bash
python app.py
```
Open your browser and navigate to:
```
http://localhost:5000
```
## π‘ Key Features
* Retrieval-augmented chatbot delivering medical information grounded in actual medical literature.
* Domain-specific insights rather than generic internet searches.
* Efficient handling of large documents using chunking and embeddings.
* Fast, scalable similarity searches via Pinecone.
* Resource-optimized deployment using quantized models.
## π Why This Matters
This project blends NLP, vector databases, and modern LLMs to make medical information more accessible and reliable. It transforms overwhelming medical research into conversational, user-friendly answers β a step toward bridging the gap between technology and human health concerns.