philipobiorah commited on
Commit
b46be0b
·
verified ·
1 Parent(s): db87bba

Update Dockerfile

Browse files

modified Dockerfile and replace any reference to /root/.cache with /tmp/huggingface_cache

Files changed (1) hide show
  1. Dockerfile +15 -21
Dockerfile CHANGED
@@ -1,44 +1,38 @@
1
- # Use an official Python runtime as the base image
2
  FROM python:3.9-slim
3
 
4
- # Set the working directory inside the container
5
  WORKDIR /app
6
 
7
- # Install system dependencies for ML and data processing libraries
8
  RUN apt-get update && apt-get install -y \
9
  build-essential \
10
  libopenblas-dev \
11
  libomp-dev \
12
  && rm -rf /var/lib/apt/lists/*
13
 
14
- # Upgrade pip to avoid dependency issues
15
- RUN pip install --upgrade pip
16
 
17
- # Set writable cache directories for Hugging Face and Matplotlib
18
- RUN mkdir -p /root/.cache/huggingface /tmp/matplotlib
19
-
20
- # Set environment variables
21
- ENV HF_HOME=/root/.cache/huggingface
22
  ENV MPLCONFIGDIR=/tmp/matplotlib
23
 
24
-
25
- # Add Hugging Face API token (replace YOUR_HF_TOKEN with your actual token)
26
- ENV HUGGINGFACE_TOKEN=${HUGGINGFACE_TOKEN}
27
-
28
-
29
-
30
-
31
- # Copy the dependencies file first for caching efficiency
32
  COPY requirements.txt /app/requirements.txt
33
 
34
  # Install Python dependencies
35
  RUN pip install --no-cache-dir -r requirements.txt
36
 
37
- # Copy the rest of the application code
 
 
 
38
  COPY . /app
39
 
40
- # Expose port 7860 (required by Hugging Face Spaces)
41
  EXPOSE 7860
42
 
43
- # Command to run the Flask app
44
  CMD ["python", "main.py"]
 
1
+ # Use an official Python runtime as a parent image
2
  FROM python:3.9-slim
3
 
4
+ # Set the working directory to /app
5
  WORKDIR /app
6
 
7
+ # Install system dependencies for machine learning and data processing libraries
8
  RUN apt-get update && apt-get install -y \
9
  build-essential \
10
  libopenblas-dev \
11
  libomp-dev \
12
  && rm -rf /var/lib/apt/lists/*
13
 
14
+ # Create writable cache directories for Hugging Face and Matplotlib
15
+ RUN mkdir -p /tmp/huggingface_cache /tmp/matplotlib
16
 
17
+ # Set environment variables
18
+ ENV TRANSFORMERS_CACHE=/tmp/huggingface_cache
19
+ ENV HF_HOME=/tmp/huggingface_cache
 
 
20
  ENV MPLCONFIGDIR=/tmp/matplotlib
21
 
22
+ # Copy requirements.txt first to leverage Docker caching
 
 
 
 
 
 
 
23
  COPY requirements.txt /app/requirements.txt
24
 
25
  # Install Python dependencies
26
  RUN pip install --no-cache-dir -r requirements.txt
27
 
28
+ # Install PyTorch separately to ensure compatibility with the correct architecture
29
+ RUN pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
30
+
31
+ # Copy the rest of the application code
32
  COPY . /app
33
 
34
+ # Expose port 7860 for Hugging Face Spaces
35
  EXPOSE 7860
36
 
37
+ # Command to run your Flask app
38
  CMD ["python", "main.py"]