AbdoIR commited on
Commit
0063ddd
·
verified ·
1 Parent(s): 51aa33d

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +17 -12
Dockerfile CHANGED
@@ -1,39 +1,44 @@
1
  # Use a slim Python base image
2
  FROM python:3.9-slim
3
 
4
- # Install system build deps (adjust if you know you don't need them)
5
  RUN apt-get update && \
6
  apt-get install -y --no-install-recommends \
7
  build-essential \
8
  gcc \
 
 
 
9
  libgomp1 \
10
- git && \
11
  rm -rf /var/lib/apt/lists/*
12
 
13
- # Prevent Python from writing .pyc files and enable unbuffered logging
14
  ENV PYTHONDONTWRITEBYTECODE=1 \
15
- PYTHONUNBUFFERED=1
 
 
 
 
 
16
 
17
  WORKDIR /app
18
 
19
- # Copy only requirements first to leverage Docker cache
20
  COPY requirements.txt /app/requirements.txt
21
-
22
- # Install Python packages globally (as root)
23
  RUN pip install --no-cache-dir --upgrade pip && \
24
  pip install --no-cache-dir -r /app/requirements.txt
25
 
26
- # Create a non-root user and switch to it
27
  RUN useradd -m -u 1000 user
28
  USER user
29
  ENV PATH="/home/user/.local/bin:$PATH"
30
 
31
- # Copy application code as the non-root user
32
  COPY --chown=user:root . /app
33
 
34
- # Expose the port expected by Hugging Face Spaces (7860)
35
  EXPOSE 7860
36
 
37
- # Run uvicorn pointing at the FastAPI app defined in `main.py` (module:main, variable:app)
38
- # Use a reasonable timeout for long uploads and keep 1 worker (models are heavy)
39
  CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "1", "--timeout-keep-alive", "120"]
 
1
  # Use a slim Python base image
2
  FROM python:3.9-slim
3
 
4
+ # Install system dependencies for audio and model support
5
  RUN apt-get update && \
6
  apt-get install -y --no-install-recommends \
7
  build-essential \
8
  gcc \
9
+ git \
10
+ ffmpeg \
11
+ libsndfile1 \
12
  libgomp1 \
13
+ curl && \
14
  rm -rf /var/lib/apt/lists/*
15
 
16
+ # Environment variables for better performance & Hugging Face cache
17
  ENV PYTHONDONTWRITEBYTECODE=1 \
18
+ PYTHONUNBUFFERED=1 \
19
+ HF_HOME=/tmp/huggingface \
20
+ TRANSFORMERS_CACHE=/tmp/huggingface/transformers \
21
+ HF_HUB_CACHE=/tmp/huggingface/hub \
22
+ HF_DATASETS_CACHE=/tmp/huggingface/datasets \
23
+ XDG_CACHE_HOME=/tmp/huggingface
24
 
25
  WORKDIR /app
26
 
27
+ # Copy and install dependencies
28
  COPY requirements.txt /app/requirements.txt
 
 
29
  RUN pip install --no-cache-dir --upgrade pip && \
30
  pip install --no-cache-dir -r /app/requirements.txt
31
 
32
+ # Create non-root user
33
  RUN useradd -m -u 1000 user
34
  USER user
35
  ENV PATH="/home/user/.local/bin:$PATH"
36
 
37
+ # Copy code
38
  COPY --chown=user:root . /app
39
 
40
+ # Expose Hugging Face port
41
  EXPOSE 7860
42
 
43
+ # Run the app
 
44
  CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "1", "--timeout-keep-alive", "120"]