boffire commited on
Commit
789ed1f
·
verified ·
1 Parent(s): d125e65

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +14 -5
Dockerfile CHANGED
@@ -14,18 +14,27 @@ RUN pip install --no-cache-dir --upgrade pip
14
  RUN pip install --no-cache-dir -r requirements.txt
15
 
16
  # Set environment variables for Hugging Face
17
- ENV TRANSFORMERS_CACHE=/tmp/transformers_cache
18
  ENV HF_HOME=/tmp/hf_cache
19
  ENV TOKENIZERS_PARALLELISM=false
20
 
21
- # Create cache directories
22
- RUN mkdir -p /tmp/transformers_cache /tmp/hf_cache
 
 
 
 
23
 
24
  # Copy application code
25
  COPY app.py .
26
 
 
 
 
 
 
27
  # Expose port 7860 for Hugging Face Spaces
28
  EXPOSE 7860
29
 
30
- # Run the Flask app
31
- CMD ["python", "app.py"]
 
 
14
  RUN pip install --no-cache-dir -r requirements.txt
15
 
16
  # Set environment variables for Hugging Face
 
17
  ENV HF_HOME=/tmp/hf_cache
18
  ENV TOKENIZERS_PARALLELISM=false
19
 
20
+ # Create cache directories and make them writable by any user
21
+ RUN mkdir -p /tmp/hf_cache && chmod -R 777 /tmp/hf_cache
22
+
23
+ # Create a non-root user (HF Spaces convention)
24
+ RUN useradd -m -u 1000 user
25
+ ENV HOME=/home/user
26
 
27
  # Copy application code
28
  COPY app.py .
29
 
30
+ # Make sure the non-root user owns the app directory
31
+ RUN chown -R user:user /app
32
+
33
+ USER user
34
+
35
  # Expose port 7860 for Hugging Face Spaces
36
  EXPOSE 7860
37
 
38
+ # Run with gunicorn: single worker (model is loaded once, in-process;
39
+ # multiple workers would each load their own copy of the model into memory)
40
+ CMD ["gunicorn", "--bind", "0.0.0.0:7860", "--workers", "1", "--threads", "4", "--timeout", "120", "app:app"]