panchadip commited on
Commit
e2356be
·
verified ·
1 Parent(s): e311c25

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +27 -18
Dockerfile CHANGED
@@ -1,26 +1,35 @@
 
1
  FROM python:3.10-slim
2
 
3
- # System dependencies
4
- RUN apt-get update && apt-get install -y build-essential && rm -rf /var/lib/apt/lists/*
 
5
 
6
- # Install Python deps first
7
- COPY requirements.txt .
8
- RUN pip install --no-cache-dir -r requirements.txt
 
 
9
 
10
- # Set environment variables
11
- ENV NLTK_DATA=/usr/local/nltk_data
12
- ENV HF_HOME=/usr/local/huggingface_cache
13
 
14
- # Create writable directories
15
- RUN mkdir -p $NLTK_DATA $HF_HOME
16
 
17
- # Download NLTK, spaCy model, and sentence-transformers model at build time
18
- RUN python -m nltk.downloader punkt && \
19
- python -m spacy download en_core_web_sm && \
20
- python -c "from sentence_transformers import SentenceTransformer; SentenceTransformer('all-MiniLM-L6-v2')"
21
 
22
- # Set working directory and copy app code
23
- WORKDIR /app
24
- COPY . .
 
 
 
 
 
 
25
 
26
- CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8000"]
 
 
1
+ # Use the official Python image
2
  FROM python:3.10-slim
3
 
4
+ # Set environment variables to prevent Python from writing .pyc files and buffering stdout
5
+ ENV PYTHONDONTWRITEBYTECODE=1
6
+ ENV PYTHONUNBUFFERED=1
7
 
8
+ # Create writable directories for nltk_data and huggingface_cache
9
+ RUN mkdir -p /app/nltk_data && \
10
+ mkdir -p /app/huggingface_cache && \
11
+ chmod -R 777 /app/nltk_data && \
12
+ chmod -R 777 /app/huggingface_cache
13
 
14
+ # Set environment variables for NLTK and Hugging Face cache directories
15
+ ENV NLTK_DATA=/app/nltk_data
16
+ ENV HF_HOME=/app/huggingface_cache
17
 
18
+ # Set working directory
19
+ WORKDIR /app
20
 
21
+ # Copy requirements.txt into the container
22
+ COPY requirements.txt /app/
 
 
23
 
24
+ # Install Python dependencies
25
+ RUN pip install --upgrade pip
26
+ RUN pip install --no-cache-dir -r requirements.txt
27
+
28
+ # Copy the FastAPI app code into the container
29
+ COPY . /app/
30
+
31
+ # Expose the port for the FastAPI app
32
+ EXPOSE 7860
33
 
34
+ # Run FastAPI app using uvicorn
35
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]