This project implements a real-world production-style AI chatbot system that:
- Loads medical PDFs
- Extracts documents from the PDFs
- Chunks the documents
- Converts them into vector embeddings
- Stores embeddings in Pinecone
- Retrieves relevant context for user queries
- Uses an LLM to generate medically grounded responses
- Serves a web interface via Flask
- Deploys to AWS using Docker, ECR, and EC2
Unlike a generic chatbot, this system uses a custom medical knowledge base, making responses more relevant and context-driven.
This basically provides all the help required from doctors, additional assistance system for patients
Tech Stack
- Backend & Application:
- Python – Core programming language
- Flask – Web framework for serving chatbot UI
- LangChain – RAG orchestration and chain management
- OpenAI API – LLM and embeddings
- Pinecone – Vector database for similarity search
- Data Processing:
- PDF Loader (LangChain)
- Text Splitters (Chunking strategy)
- OpenAI Embedding Models
- Frontend: Basic client-side interaction via Flask routing
- HTML (Jinja Templates)
- CSS (Static assets)
- DevOps & Cloud:
- Docker – Containerization
- Amazon ECR – Container registry
- Amazon EC2 – Hosting environment
- IAM – Access management
- GitHub Actions – CI/CD automation
- Development Tools:
- VS Code / PyCharm
- AWS CLI
- Git & GitHub
- Virtual Environment (venv)
Architecture Components
| Layer | Component | Responsibility |
|---|---|---|
| Presentation Layer | Flask + HTML Templates | User interface & request handling |
| Application Layer | LangChain | Orchestrates RAG pipeline |
| Embedding Layer | OpenAI Embeddings | Converts text to vectors |
| Retrieval Layer | Pinecone | Vector similarity search |
| Generation Layer | OpenAI GPT | Response generation |
| Deployment Layer | Docker + AWS | Containerization & hosting |
Architecture Flowchart
flowchart TD
A["User (Browser)"]
B["Flask Web Application (app.py)"]
C["LangChain RAG Pipeline"]
D["Retriever (Pinecone Vector Store)"]
E["Relevant Medical Document Chunks"]
F["OpenAI LLM (Response Generation)"]
G["Response Returned to User"]
A --> B
B --> C
C --> D
D --> E
E --> F
F --> G
Deployment Architecture (AWS)
flowchart TD
A["Developer Machine"]
B["Docker Image"]
C["Amazon ECR (Image Registry)"]
D["Amazon EC2 (Ubuntu Instance)"]
E["Running Docker Container"]
F["Public IP (Accessible Web App)"]
A --> B
B --> C
C --> D
D --> E
E --> F
CI/CD:
GitHub Push → GitHub Actions → Build → Push to ECR → Deploy to EC2
MedicalChatbot/
│
├── .github/workflows/ # CI/CD configuration
├── data/ # Medical documents (PDFs)
├── research/ # Experiment notebooks
├── src/ # Core logic
├── static/ # CSS / frontend assets
├── templates/ # HTML templates
├── app.py # Flask entrypoint
├── store_index.py # Embedding & indexing script
├── Dockerfile
├── requirements.txt
├── setup.py
└── README.md
- Clone Repository:
git clone https://github.com/AishwaryaMaddula/MedicalChatbot.git
cd MedicalChatbot- Create Virtual Environment:
python -m venv venv
source venv/bin/activate # Mac/Linux
venv\Scripts\activate # Windows- Install Dependencies:
pip install -r requirements.txt- Environment Variables: Create a .env file and add following keys:
OPENAI_API_KEY=
PINECONE_API_KEY=Make sure .env is in .gitignore.
- Create Pinecone Index:
Run ingestion script to embed and store documents:
python store_index.py- Start Flask App:
python app.pyVisit: http://localhost:8080 to view the application
AWS Deployment (Production)
Local → Docker → Amazon ECR → EC2 → Running Container
- Create IAM User:
- This user performs:
- Build docker image of the source code
- Push docker image to ECR
- Launch EC2
- Pull image from ECR in EC2
- Launch docker image in EC2
- Name it as "medical-chatbot"
- Grant following policies:
- EC2 access: It is virtual machine
AmazonEC2FullAccess
- ECR: Elastic Container registry to save your docker image in aws
AmazonEC2ContainerRegistryFullAccess
- EC2 access: It is virtual machine
- Configure AWS CLI:
aws configure
- This user performs:
- For the created user, generate access key and secret key.
- Create ECR Repository and copy repository URI:
<aws_account_id>.dkr.ecr.us-east-1.amazonaws.com/medical-chatbot- Create EC2 Instance (region can be us-east-1. ensure HTTPS, HTTP and SSH authentication types are selected)
- Launch EC2 Instance and Install Docker on EC2:
#optinal
sudo apt-get update -y
sudo apt-get upgrade
#required
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
sudo usermod -aG docker ubuntu
newgrp docker- Configure EC2 as self hosted runner: Go to
Github Repository Settings -> Actions -> Runners -> New Self-hosted runner -> Select Linux -> run displayed commands in EC2 one by one - Setup github secrets:
- AWS_ACCESS_KEY_ID
- AWS_SECRET_ACCESS_KEY
- AWS_DEFAULT_REGION
- ECR_REPO
- PINECONE_API_KEY
- OPENAI_API_KEY
- Create yaml file that contains CI/CD workflow:
.github/workflows/cicd.yml
Add template in yaml file to include following:
- Trigger
Run on push to main - CI Job
- Checkout repository
- Configure AWS credentials
- Login to Amazon ECR
- Build Docker image
- Tag image
- Push image to ECR
- CD Job
- Depend on CI job
- Run on self-hosted (EC2) runner
- Login to ECR
- Pull latest image
- Run Docker container
- Expose application port