ayush2917 commited on
Commit
2b4ef1b
·
verified ·
1 Parent(s): 421727b

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +14 -2
Dockerfile CHANGED
@@ -10,6 +10,9 @@ RUN useradd -m -u 1000 appuser
10
  # Create cache directory and set permissions
11
  RUN mkdir -p /app/cache && chown -R appuser:appuser /app
12
 
 
 
 
13
  # Install system dependencies
14
  RUN apt-get update && apt-get install -y \
15
  build-essential \
@@ -19,15 +22,24 @@ RUN apt-get update && apt-get install -y \
19
  COPY requirements.txt .
20
  RUN pip install --no-cache-dir -r requirements.txt
21
 
 
 
 
 
 
 
 
 
 
 
22
  # Copy all project files
23
  COPY . .
24
 
25
  # Switch to non-root user
26
  USER appuser
27
 
28
- # Set environment variables for Hugging Face cache and disable Xet Storage
29
  ENV HF_HOME=/app/cache
30
- ENV HUGGINGFACE_HUB_DISABLE_XET=true
31
 
32
  # Expose the Flask port
33
  EXPOSE 8000
 
10
  # Create cache directory and set permissions
11
  RUN mkdir -p /app/cache && chown -R appuser:appuser /app
12
 
13
+ # Set environment variable to disable Xet Storage early
14
+ ENV HUGGINGFACE_HUB_DISABLE_XET=true
15
+
16
  # Install system dependencies
17
  RUN apt-get update && apt-get install -y \
18
  build-essential \
 
22
  COPY requirements.txt .
23
  RUN pip install --no-cache-dir -r requirements.txt
24
 
25
+ # Pre-download models to cache with retry mechanism
26
+ RUN for i in 1 2 3 4 5; do \
27
+ python -c "from langchain_huggingface import HuggingFaceEmbeddings; HuggingFaceEmbeddings(model_name='all-MiniLM-L6-v2')" && break || \
28
+ echo "Retry $i failed for all-MiniLM-L6-v2, waiting before next attempt..." && sleep 10; \
29
+ done || { echo "Failed to download all-MiniLM-L6-v2 after 5 retries"; exit 1; }
30
+ RUN for i in 1 2 3 4 5; do \
31
+ python -c "from transformers import AutoModelForCausalLM, AutoTokenizer; AutoTokenizer.from_pretrained('distilgpt2'); AutoModelForCausalLM.from_pretrained('distilgpt2')" && break || \
32
+ echo "Retry $i failed for distilgpt2, waiting before next attempt..." && sleep 10; \
33
+ done || { echo "Failed to download distilgpt2 after 5 retries"; exit 1; }
34
+
35
  # Copy all project files
36
  COPY . .
37
 
38
  # Switch to non-root user
39
  USER appuser
40
 
41
+ # Set environment variable for Hugging Face cache
42
  ENV HF_HOME=/app/cache
 
43
 
44
  # Expose the Flask port
45
  EXPOSE 8000