An open API service indexing awesome lists of open source software.

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.

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.