Chvigo commited on
Commit
7e27ad7
·
verified ·
1 Parent(s): eb86c9e

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +20 -12
Dockerfile CHANGED
@@ -1,19 +1,27 @@
1
  # Base image: CPU-only Python 3.12
2
  FROM python:3.12-slim
3
 
4
- # Set working directory
5
- WORKDIR /app
 
 
 
 
6
 
7
- # Copy project files
8
- COPY requirements.txt .
9
- COPY app.py .
10
 
11
- # Install dependencies
12
- RUN pip install --upgrade pip
13
- RUN pip install --no-cache-dir -r requirements.txt
 
14
 
15
- # Expose port
16
- EXPOSE 8000
17
 
18
- # Start Flask app
19
- CMD ["gunicorn", "--bind", "0.0.0.0:8000", "app:app"]
 
 
 
 
 
1
  # Base image: CPU-only Python 3.12
2
  FROM python:3.12-slim
3
 
4
+ # Create a non-root user (UID 1000 is required by Hugging Face)
5
+ RUN useradd -m -u 1000 user
6
+ USER user
7
+ ENV HOME=/home/user \
8
+ PATH=/home/user/.local/bin:$PATH \
9
+ HF_HOME=/home/user/huggingface
10
 
11
+ # Set working directory to the user's home
12
+ WORKDIR $HOME/app
 
13
 
14
+ # Copy and install dependencies first (for better caching)
15
+ COPY --chown=user requirements.txt .
16
+ RUN pip install --upgrade pip && \
17
+ pip install --no-cache-dir -r requirements.txt
18
 
19
+ # Copy application code
20
+ COPY --chown=user app.py .
21
 
22
+ # Hugging Face Spaces MUST use port 7860
23
+ EXPOSE 7860
24
+
25
+ # Use Gunicorn with 1 worker and multiple threads for CPU LLM inference
26
+ # Note: 1 worker prevents loading the 1GB+ model into memory multiple times
27
+ CMD ["gunicorn", "--bind", "0.0.0.0:7860", "--workers", "1", "--threads", "4", "--timeout", "120", "app:app"]