Dan Vancea commited on
Commit
ac34b3e
·
1 Parent(s): 801b1af

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +20 -18
Dockerfile CHANGED
@@ -1,37 +1,39 @@
1
- # Use a slim Python 3.11 image to keep the base footprint small
2
  FROM python:3.11-slim
3
 
4
- # Prevent Python from writing pyc files and keep stdout/stderr unbuffered
5
  ENV PYTHONDONTWRITEBYTECODE=1
6
  ENV PYTHONUNBUFFERED=1
7
 
8
- # Install system dependencies required by Whisper
9
  RUN apt-get update && apt-get install -y \
10
  ffmpeg \
11
  git \
12
  && rm -rf /var/lib/apt/lists/*
13
 
14
- # Set the working directory
15
- WORKDIR /app
 
16
 
17
- # Copy dependency list first to leverage Docker layer caching
18
- COPY requirements.txt .
 
19
 
20
- # Optimize PyTorch installation:
21
- # If you are deploying to a standard CPU environment, pulling the CPU-only wheels
22
- # prevents downloading CUDA binaries, saving ~2GB of image space.
23
- RUN pip install --no-cache-dir torch torchaudio --index-url https://download.pytorch.org/whl/cpu
24
 
25
- # Install the rest of the Python dependencies
26
- RUN pip install --no-cache-dir -r requirements.txt
27
 
28
- # Pre-cache the Whisper 'medium' model during the image build phase
29
- RUN python -c "import whisper; whisper.load_model('medium')"
 
30
 
31
- # Copy the application code and necessary binary files (like q_table.pkl)
32
- COPY . .
 
33
 
34
- # Expose the port defined in your backend.py
 
 
 
35
  EXPOSE 7860
36
 
37
  # Start the Flask application
 
 
1
  FROM python:3.11-slim
2
 
 
3
  ENV PYTHONDONTWRITEBYTECODE=1
4
  ENV PYTHONUNBUFFERED=1
5
 
6
+ # 1. Install system dependencies
7
  RUN apt-get update && apt-get install -y \
8
  ffmpeg \
9
  git \
10
  && rm -rf /var/lib/apt/lists/*
11
 
12
+ # 2. Create the non-root user required by Hugging Face Spaces (UID 1000)
13
+ RUN useradd -m -u 1000 user
14
+ USER user
15
 
16
+ # Set environment variables for the new user
17
+ ENV HOME=/home/user \
18
+ PATH=/home/user/.local/bin:$PATH
19
 
20
+ WORKDIR $HOME/app
 
 
 
21
 
22
+ # 3. Copy requirements and transfer ownership to the new user
23
+ COPY --chown=user requirements.txt .
24
 
25
+ # 4. Install Python dependencies as the user
26
+ RUN pip install --user --no-cache-dir torch torchaudio --index-url https://download.pytorch.org/whl/cpu
27
+ RUN pip install --user --no-cache-dir -r requirements.txt
28
 
29
+ # 5. Pre-cache Whisper WITHOUT loading it into PyTorch memory to avoid OOM limits.
30
+ # Using whisper._download handles the checksum logic and places it in the user's cache directory.
31
+ RUN python -c "import whisper, os; whisper._download(whisper._MODELS['medium'], os.path.expanduser('~/.cache/whisper'), False)"
32
 
33
+ # 6. Copy the rest of the application code
34
+ COPY --chown=user . .
35
+
36
+ # Expose the correct Hugging Face port
37
  EXPOSE 7860
38
 
39
  # Start the Flask application