Bushra-KB commited on
Commit
1f6bb6b
·
verified ·
1 Parent(s): ef48146

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +25 -33
Dockerfile CHANGED
@@ -1,42 +1,34 @@
1
- FROM python:3.14-slim
2
-
3
- # Set environment variables for caching to a writable directory
4
- # These will be used by huggingface libraries to store models and other assets.
5
- ENV HF_HOME=/data/huggingface
6
- ENV TORCH_HOME=/data/torch
7
- ENV TRANSFORMERS_CACHE=/data/huggingface/hub
8
- ENV HF_DATASETS_CACHE=/data/huggingface/datasets
9
-
10
- # Create the cache directories and make them writable by any user
11
- RUN mkdir -p $TRANSFORMERS_CACHE $HF_DATASETS_CACHE $TORCH_HOME && \
12
- chmod -R 777 /data
13
-
14
- # System deps for soundfile, audio encoding, and uroman
 
 
 
 
15
  RUN apt-get update && apt-get install -y --no-install-recommends \
16
- libsndfile1 ffmpeg git perl && \
17
- rm -rf /var/lib/apt/lists/*
18
 
19
- # Clone and install uroman from source so the tokenizer can find it
20
- RUN git clone https://github.com/isi-nlp/uroman.git /opt/uroman && \
21
- ln -s /opt/uroman/bin/uroman.pl /usr/local/bin/uroman
22
 
 
23
  WORKDIR /app
24
-
25
- # Install Python deps
26
  COPY backend/requirements.txt /app/requirements.txt
27
- RUN pip install --no-cache-dir --upgrade pip && \
28
- pip install --no-cache-dir -r /app/requirements.txt
29
 
30
- # Copy app code
31
  COPY backend/ /app/
32
 
33
- # Optional: pre-cache the MMS model at build time to speed up first request
34
- # This now uses the cache directory defined by the ENV variables.
35
- RUN python -c "from transformers import VitsModel, AutoTokenizer; model_id = 'facebook/mms-tts-amh'; VitsModel.from_pretrained(model_id); AutoTokenizer.from_pretrained(model_id); print('Pre-cached MMS model')"
36
-
37
- # Spaces expects the app to listen on $PORT (default 7860)
38
- ENV PORT=7860
39
  EXPOSE 7860
40
-
41
- # Start the Flask app via gunicorn
42
- CMD ["gunicorn", "app:app", "--bind", "0.0.0.0:7860", "--workers", "1", "--threads", "4", "--timeout", "300"]
 
1
+ FROM python:3.11-slim
2
+
3
+ # Set environment variables for writable caches on Hugging Face Spaces
4
+ ENV DEBIAN_FRONTEND=noninteractive \
5
+ PIP_NO_CACHE_DIR=1 \
6
+ PYTHONDONTWRITEBYTECODE=1 \
7
+ PYTHONUNBUFFERED=1 \
8
+ PORT=7860 \
9
+ # Point all caches to the writable /data volume
10
+ HOME=/data \
11
+ XDG_CACHE_HOME=/data/.cache \
12
+ HF_HOME=/data/.cache/huggingface \
13
+ HUGGINGFACE_HUB_CACHE=/data/.cache/huggingface/hub \
14
+ TRANSFORMERS_CACHE=/data/transformers \
15
+ TORCH_HOME=/data/torch \
16
+ HF_HUB_DISABLE_TELEMETRY=1
17
+
18
+ # System dependencies for audio processing
19
  RUN apt-get update && apt-get install -y --no-install-recommends \
20
+ libsndfile1 \
21
+ && rm -rf /var/lib/apt/lists/*
22
 
23
+ # Create the cache directories and make them writable
24
+ RUN mkdir -p /data/.cache/huggingface/hub /data/transformers /data/torch && chmod -R 777 /data
 
25
 
26
+ # Set up the app
27
  WORKDIR /app
 
 
28
  COPY backend/requirements.txt /app/requirements.txt
29
+ RUN pip install -r /app/requirements.txt
 
30
 
 
31
  COPY backend/ /app/
32
 
 
 
 
 
 
 
33
  EXPOSE 7860
34
+ CMD ["gunicorn", "-w", "2", "-k", "gthread", "-b", "0.0.0.0:${PORT}", "app:app"]