Astha is a Flask-based medical question-answering chatbot built with LangChain, Pinecone, OpenAI, and Hugging Face embeddings. It uses a RAG pipeline to retrieve relevant chunks from an indexed medical PDF and generate concise answers through a web chat interface.
- Medical RAG chatbot with Pinecone vector search
- OpenAI chat model for answer generation
- Hugging Face sentence-transformer embeddings
- Responsive chat UI with Flask templates and static CSS
- Dockerized production runtime with Gunicorn
- GitHub Actions CI/CD to Amazon ECR and EC2
- Self-hosted GitHub runner based deployment on EC2
.
├── app.py # Flask app and RAG endpoint
├── Dockerfile # Production Docker image
├── requirements.txt # Python dependencies
├── data/
│ └── Medical_book.pdf # Source document for indexing
├── src/
│ ├── helper.py # PDF loading, splitting, embeddings
│ ├── prompt.py # RAG prompt template
│ └── store_index.py # Pinecone indexing script
├── static/
│ └── style.css # Chat UI styles
├── templates/
│ └── chat.html # Chat page
└── .github/workflows/
└── cicd.yaml # ECR build and EC2 deployment
- Python 3.12
- Flask 3.1
- LangChain 0.3
- Pinecone
- OpenAI API
- Sentence Transformers
- Docker
- Gunicorn
- AWS ECR + EC2
- GitHub Actions
Create a .env file locally:
OPENAI_API_KEY=your_openai_api_key
PINECONE_API_KEY=your_pinecone_api_keyFor GitHub Actions deployment, configure these repository secrets:
AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY
AWS_DEFAULT_REGION
ECR_REPO
OPENAI_API_KEY
PINECONE_API_KEY
ECR_REPO should be only the ECR repository name, not the full URL.
Example:
ECR_REPO=astha-medical-chatbot
Create and activate a virtual environment:
python3.12 -m venv myenv
source myenv/bin/activateInstall dependencies:
pip install -r requirements.txtRun the Flask app:
python app.pyOpen:
http://127.0.0.1:8080
Before the chatbot can answer from your PDF, the Pinecone index must be populated.
Run:
python src/store_index.pyThe script:
- loads PDFs from
data/ - creates text chunks
- embeds chunks using
sentence-transformers/all-MiniLM-L6-v2 - uploads vectors to the Pinecone index:
medical-chatbot-index
You only need to rerun this when the source documents or embedding model change.
The frontend sends chat messages to:
POST /get
Example:
curl -X POST http://127.0.0.1:8080/get \
-H "Content-Type: application/json" \
-d '{"message":"What is acne?"}'Response:
{
"answer": "Acne is a common skin disease..."
}Build the image:
docker build -t astha-medical-chatbot .Run the container:
docker run -d \
--name astha-medical-chatbot \
-e OPENAI_API_KEY="$OPENAI_API_KEY" \
-e PINECONE_API_KEY="$PINECONE_API_KEY" \
-p 8080:8080 \
astha-medical-chatbotOpen:
http://localhost:8080
This project uses GitHub Actions with two jobs:
-
Continuous-Integration- builds the Docker image
- pushes it to Amazon ECR
-
Continuous-Deployment- runs on the EC2 self-hosted GitHub runner
- pulls the latest image from ECR
- stops and removes the old container
- starts the new container on port
8080
Live app format:
http://YOUR_EC2_PUBLIC_IP:8080
Deployment status note: the previous EC2 instance used for this project was terminated to avoid ongoing AWS charges. To deploy again, create a new EC2 instance, install Docker, configure a new self-hosted GitHub runner, update the security group, and rerun the GitHub Actions workflow.
Make sure the EC2 security group allows:
Custom TCP 8080
SSH 22
On EC2, the runner should be installed as a service:
cd ~/actions-runner
sudo ./svc.sh status
sudo ./svc.sh startExpected status:
active (running)
Connected to GitHub
Listening for Jobs
If it is not installed:
cd ~/actions-runner
sudo ./svc.sh install
sudo ./svc.sh startThe EC2 self-hosted runner is offline.
Fix:
cd ~/actions-runner
sudo ./svc.sh start
sudo ./svc.sh statusThis is usually a NumPy/Torch compatibility issue in Docker. The project pins:
numpy==1.26.4
torch==2.2.2
Rebuild and redeploy the Docker image after dependency changes.
Docker layers filled the EC2 disk.
Fix on EC2:
docker system prune -a -f
docker volume prune -f
df -hCheck container logs:
docker logs astha-medical-chatbot --tail 100Also confirm these environment variables are passed into the container:
OPENAI_API_KEY
PINECONE_API_KEY
The Docker container runs:
gunicorn app:app --workers 1 --threads 2 --timeout 120 --bind 0.0.0.0:8080This chatbot is for educational and informational support only. It is not a replacement for professional medical advice, diagnosis, or treatment.