Skip to content

Commit b94a08e

Browse files
Merge pull request #50 from souvikmajumder26/dev
Updated installation using docker
2 parents c4f6e05 + 7a0c8a8 commit b94a08e

File tree

5 files changed

+256
-42
lines changed

5 files changed

+256
-42
lines changed

Dockerfile

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Use Python 3.11 as the base image
2+
FROM python:3.11-slim
3+
4+
# Set working directory
5+
WORKDIR /app
6+
7+
# Install system dependencies
8+
RUN apt-get update && apt-get install -y \
9+
ffmpeg \
10+
poppler-utils \
11+
tesseract-ocr \
12+
git \
13+
curl \
14+
&& apt-get clean \
15+
&& rm -rf /var/lib/apt/lists/*
16+
17+
# Clone the repository
18+
RUN git clone https://github.com/souvikmajumder26/Multi-Agent-Medical-Assistant.git .
19+
20+
# Create necessary directories for data persistence and uploads
21+
RUN mkdir -p data/processed data/qdrantdb uploads/backend uploads/skin_lesion_output
22+
23+
# Install Python dependencies
24+
RUN pip install --no-cache-dir -r requirements.txt
25+
RUN pip install --no-cache-dir unstructured[pdf]
26+
27+
# Expose the port that FastAPI will run on
28+
EXPOSE 8000
29+
30+
# Volumes for data persistence
31+
VOLUME ["/app/data/processed", "/app/data/qdrantdb", "/app/uploads"]
32+
33+
# Define healthcheck
34+
HEALTHCHECK --interval=30s --timeout=5s --start-period=15s --retries=3 \
35+
CMD curl -f http://localhost:8000/health || exit 1
36+
37+
# Create entry point script
38+
COPY entrypoint.sh /app/entrypoint.sh
39+
RUN chmod +x /app/entrypoint.sh
40+
41+
ENTRYPOINT ["/app/entrypoint.sh"]

README.md

Lines changed: 111 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
- [Key Features](#key-features)
2828
- [Tech Stack](#technology-stack)
2929
- [Installation and Setup](#installation-setup)
30+
- [Using Docker](#docker-setup)
31+
- [Manual Installation](#manual-setup)
3032
- [Usage](#usage)
3133
- [Contributions](#contributions)
3234
- [License](#license)
@@ -161,6 +163,85 @@ If you like what you see and would want to support the project's developer, you
161163

162164
## 🚀 Installation & Setup <a name="installation-setup"></a>
163165

166+
## 📌 Option 1: Using Docker <a name="docker-setup"></a>
167+
168+
### 1️⃣ Clone the Repository
169+
```bash
170+
git clone https://github.com/souvikmajumder26/Multi-Agent-Medical-Assistant.git
171+
cd Multi-Agent-Medical-Assistant
172+
```
173+
174+
### 2️⃣ Set Up API Keys
175+
- Create a `.env` file and add the following API keys:
176+
177+
> [!NOTE]
178+
> You may use any llm and embedding model of your choice...
179+
> 1. If using Azure OpenAI, no modification required.
180+
> 2. If using direct OpenAI, modify the llm and embedding model definitions in the 'config.py' and provide appropriate env variables.
181+
> 3. If using local models, appropriate code changes might be required throughout the codebase especially in 'agents'.
182+
183+
> [!WARNING]
184+
> If all necessary env variables are not provided, errors will be thrown in console.
185+
186+
```bash
187+
# LLM Configuration (Azure Open AI - gpt-4o used in development)
188+
# If using any other LLM API key or local LLM, appropriate code modification is required
189+
deployment_name =
190+
model_name = gpt-4o
191+
azure_endpoint =
192+
openai_api_key =
193+
openai_api_version =
194+
195+
# Embedding Model Configuration (Azure Open AI - text-embedding-ada-002 used in development)
196+
# If using any other embedding model, appropriate code modification is required
197+
embedding_deployment_name =
198+
embedding_model_name = text-embedding-ada-002
199+
embedding_azure_endpoint =
200+
embedding_openai_api_key =
201+
embedding_openai_api_version =
202+
203+
# Speech API Key (Free credits available with new Eleven Labs Account)
204+
ELEVEN_LABS_API_KEY =
205+
206+
# Web Search API Key (Free credits available with new Tavily Account)
207+
TAVILY_API_KEY =
208+
209+
# Hugging Face Token - using reranker model "ms-marco-TinyBERT-L-6"
210+
HUGGINGFACE_TOKEN =
211+
212+
# (OPTIONAL) If using Qdrant server version, local does not require API key
213+
QDRANT_URL =
214+
QDRANT_API_KEY =
215+
```
216+
217+
### 3️⃣ Run with Docker Compose
218+
```bash
219+
docker-compose up -d
220+
```
221+
This will start two services:
222+
223+
- fastapi-backend: Runs the FastAPI backend on port 8000
224+
- main-app: Runs the main application (app.py)
225+
226+
### 4️⃣ Ingest data into the Vector DB
227+
```bash
228+
# To ingest a single file
229+
docker-compose run --rm fastapi-backend ingest --file ./data/raw/your_file.pdf
230+
231+
# To ingest all files in a directory
232+
docker-compose run --rm fastapi-backend ingest --dir ./data/raw
233+
```
234+
235+
### 5️⃣ Access the Application
236+
The application will be available at: `http://localhost:8000`
237+
238+
### 6️⃣ Stopping the Application
239+
```bash
240+
docker-compose down
241+
```
242+
243+
## 📌 Option 2: Manual Installation <a name="manual-setup"></a>
244+
164245
### 1️⃣ Clone the Repository
165246
```bash
166247
git clone https://github.com/souvikmajumder26/Multi-Agent-Medical-Assistant.git
@@ -233,53 +314,13 @@ winget install ffmpeg
233314
```bash
234315
pip install -r requirements.txt
235316
```
236-
- Might be required, might not be:
317+
- Might be required:
237318
```bash
238319
pip install unstructured[pdf]
239320
```
240321

241322
### 4️⃣ Set Up API Keys
242-
- Create a `.env` file and add the following API keys:
243-
244-
> [!NOTE]
245-
> You may use any llm and embedding model of your choice...
246-
> 1. If using Azure OpenAI, no modification required.
247-
> 2. If using direct OpenAI, modify the llm and embedding model definitions in the 'config.py' and provide appropriate env variables.
248-
> 3. If using local models, appropriate code changes might be required throughout the codebase especially in 'agents'.
249-
250-
> [!WARNING]
251-
> If all necessary env variables are not provided, errors will be thrown in console.
252-
253-
```bash
254-
# LLM Configuration (Azure Open AI - gpt-4o used in development)
255-
# If using any other LLM API key or local LLM, appropriate code modification is required
256-
deployment_name =
257-
model_name = gpt-4o
258-
azure_endpoint =
259-
openai_api_key =
260-
openai_api_version =
261-
262-
# Embedding Model Configuration (Azure Open AI - text-embedding-ada-002 used in development)
263-
# If using any other embedding model, appropriate code modification is required
264-
embedding_deployment_name =
265-
embedding_model_name = text-embedding-ada-002
266-
embedding_azure_endpoint =
267-
embedding_openai_api_key =
268-
embedding_openai_api_version =
269-
270-
# Speech API Key (Free credits available with new Eleven Labs Account)
271-
ELEVEN_LABS_API_KEY =
272-
273-
# Web Search API Key (Free credits available with new Tavily Account)
274-
TAVILY_API_KEY =
275-
276-
# Hugging Face Token - using reranker model "ms-marco-TinyBERT-L-6"
277-
HUGGINGFACE_TOKEN =
278-
279-
# (OPTIONAL) If using Qdrant server version, local does not require API key
280-
QDRANT_URL =
281-
QDRANT_API_KEY =
282-
```
323+
- Create a `.env` file and add the required API keys as shown in `Option 1`.
283324

284325
### 5️⃣ Run the Application
285326
- Run the following commands one after another in separate windows with same directorty and virtual environment. Keep both running simultanesouly.
@@ -303,6 +344,34 @@ python ingest_rag_data.py --dir ./data/raw
303344

304345
---
305346

347+
## Docker Related Information:
348+
349+
### Data Persistence
350+
351+
The vector database data is stored in Docker volumes:
352+
353+
- `vector-db-processed`: Contains data from the `data/processed` directory
354+
- `vector-db-qdrant`: Contains data from the `data/qdrantdb` directory
355+
- `upload-data`: Contains uploaded files in the `uploads` directory
356+
357+
This ensures your data persists even if you remove the containers.
358+
359+
### Troubleshooting Docker Setup
360+
361+
- If the containers aren't starting properly, check logs:
362+
```bash
363+
docker-compose logs fastapi-backend
364+
docker-compose logs main-app
365+
```
366+
- Make sure all required environment variables are set in the `.env` file
367+
- To completely clean up and restart:
368+
```bash
369+
docker-compose down -v
370+
docker-compose up -d --build
371+
```
372+
373+
---
374+
306375
## 🧠 Usage <a name="usage"></a>
307376

308377
> [!NOTE]

api/fastapi_backend.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@
2626
class QueryRequest(BaseModel):
2727
query: str
2828

29+
# Add a health check endpoint
30+
@app.get("/health")
31+
def health_check():
32+
"""Health check endpoint for Docker health checks"""
33+
return {"status": "healthy"}
34+
2935
@app.post("/chat")
3036
def chat(request: QueryRequest, response: Response, request_obj: Request):
3137
"""Process user text query through the multi-agent system."""

docker-compose.yml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
version: '3.8'
2+
3+
services:
4+
fastapi-backend:
5+
build:
6+
context: .
7+
dockerfile: Dockerfile
8+
ports:
9+
- "8000:8000"
10+
environment:
11+
- deployment_name=${deployment_name}
12+
- model_name=${model_name}
13+
- azure_endpoint=${azure_endpoint}
14+
- openai_api_key=${openai_api_key}
15+
- openai_api_version=${openai_api_version}
16+
- embedding_deployment_name=${embedding_deployment_name}
17+
- embedding_model_name=${embedding_model_name}
18+
- embedding_azure_endpoint=${embedding_azure_endpoint}
19+
- embedding_openai_api_key=${embedding_openai_api_key}
20+
- embedding_openai_api_version=${embedding_openai_api_version}
21+
- ELEVEN_LABS_API_KEY=${ELEVEN_LABS_API_KEY}
22+
- TAVILY_API_KEY=${TAVILY_API_KEY}
23+
- HUGGINGFACE_TOKEN=${HUGGINGFACE_TOKEN}
24+
- QDRANT_URL=${QDRANT_URL}
25+
- QDRANT_API_KEY=${QDRANT_API_KEY}
26+
volumes:
27+
- vector-db-processed:/app/data/processed
28+
- vector-db-qdrant:/app/data/qdrantdb
29+
- upload-data:/app/uploads
30+
command: api
31+
healthcheck:
32+
test: curl -f http://localhost:8000/health || exit 1
33+
interval: 30s
34+
timeout: 5s
35+
retries: 3
36+
start_period: 15s
37+
38+
main-app:
39+
build:
40+
context: .
41+
dockerfile: Dockerfile
42+
depends_on:
43+
fastapi-backend:
44+
condition: service_healthy
45+
environment:
46+
- deployment_name=${deployment_name}
47+
- model_name=${model_name}
48+
- azure_endpoint=${azure_endpoint}
49+
- openai_api_key=${openai_api_key}
50+
- openai_api_version=${openai_api_version}
51+
- embedding_deployment_name=${embedding_deployment_name}
52+
- embedding_model_name=${embedding_model_name}
53+
- embedding_azure_endpoint=${embedding_azure_endpoint}
54+
- embedding_openai_api_key=${embedding_openai_api_key}
55+
- embedding_openai_api_version=${embedding_openai_api_version}
56+
- ELEVEN_LABS_API_KEY=${ELEVEN_LABS_API_KEY}
57+
- TAVILY_API_KEY=${TAVILY_API_KEY}
58+
- HUGGINGFACE_TOKEN=${HUGGINGFACE_TOKEN}
59+
- QDRANT_URL=${QDRANT_URL}
60+
- QDRANT_API_KEY=${QDRANT_API_KEY}
61+
volumes:
62+
- vector-db-processed:/app/data/processed
63+
- vector-db-qdrant:/app/data/qdrantdb
64+
- upload-data:/app/uploads
65+
command: app
66+
67+
volumes:
68+
vector-db-processed:
69+
vector-db-qdrant:
70+
upload-data:

entrypoint.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
3+
# First argument determines which service to run
4+
if [ "$1" = "api" ]; then
5+
echo "Starting FastAPI backend..."
6+
exec uvicorn api.fastapi_backend:app --host 0.0.0.0 --port 8000
7+
elif [ "$1" = "app" ]; then
8+
echo "Starting main application..."
9+
exec python app.py
10+
elif [ "$1" = "all" ]; then
11+
echo "Starting both services..."
12+
uvicorn api.fastapi_backend:app --host 0.0.0.0 --port 8000 &
13+
python app.py
14+
wait
15+
elif [ "$1" = "ingest" ]; then
16+
echo "Ingesting data..."
17+
if [ "$2" = "--file" ]; then
18+
exec python ingest_rag_data.py --file "$3"
19+
elif [ "$2" = "--dir" ]; then
20+
exec python ingest_rag_data.py --dir "$3"
21+
else
22+
echo "Please provide valid arguments: --file or --dir"
23+
exit 1
24+
fi
25+
else
26+
echo "Please specify which service to run: api, app, all, or ingest"
27+
exit 1
28+
fi

0 commit comments

Comments
 (0)