koulsahil commited on
Commit
ae4e18e
·
verified ·
1 Parent(s): 395ecbb

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +38 -14
Dockerfile CHANGED
@@ -1,5 +1,5 @@
1
- # Use official Python 3.12 image
2
- FROM python:3.12-slim
3
 
4
  # Set working directory
5
  WORKDIR /app
@@ -11,17 +11,14 @@ RUN apt-get update && apt-get install -y \
11
  git \
12
  && rm -rf /var/lib/apt/lists/*
13
 
14
- # Create directories with proper permissions
15
- RUN mkdir -p /tmp/uploads /tmp/huggingface \
16
- && chmod -R 777 /tmp/uploads /tmp/huggingface
17
 
18
- # Set environment variables
19
- ENV PYTHONUNBUFFERED=1
20
- ENV UPLOAD_FOLDER=/tmp/uploads
21
  ENV TRANSFORMERS_CACHE=/tmp/huggingface
22
  ENV HF_HOME=/tmp/huggingface
23
 
24
- # Copy requirements file first to leverage Docker cache
25
  COPY requirements.txt .
26
 
27
  # Install Python dependencies
@@ -30,13 +27,36 @@ RUN pip install --no-cache-dir -r requirements.txt
30
  # Install spaCy model
31
  RUN python -m spacy download en_core_web_sm
32
 
33
- # Pre-download Hugging Face models and tokenizers
34
  RUN python -c "\
35
- from transformers import AutoTokenizer; \
36
- AutoTokenizer.from_pretrained('deepset/deberta-v3-base-squad2', cache_dir='/tmp/huggingface'); \
37
- AutoTokenizer.from_pretrained('distilbert-base-uncased', cache_dir='/tmp/huggingface')"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
 
39
- # Create Streamlit config
 
 
 
 
 
 
 
 
 
40
  RUN mkdir -p .streamlit && \
41
  echo '[server]\n\
42
  enableCORS=false\n\
@@ -48,5 +68,9 @@ COPY . .
48
  # Expose port
49
  EXPOSE 7860
50
 
 
 
 
 
51
  # Run the application
52
  CMD ["streamlit", "run", "app.py", "--server.port=7860", "--server.address=0.0.0.0"]
 
1
+ # Use official Python 3.12 image with slim variant
2
+ FROM python:3.12-slim as builder
3
 
4
  # Set working directory
5
  WORKDIR /app
 
11
  git \
12
  && rm -rf /var/lib/apt/lists/*
13
 
14
+ # Create model cache directory
15
+ RUN mkdir -p /tmp/huggingface && chmod -R 777 /tmp/huggingface
 
16
 
17
+ # Set environment variables for Hugging Face cache
 
 
18
  ENV TRANSFORMERS_CACHE=/tmp/huggingface
19
  ENV HF_HOME=/tmp/huggingface
20
 
21
+ # Copy only requirements first to leverage Docker cache
22
  COPY requirements.txt .
23
 
24
  # Install Python dependencies
 
27
  # Install spaCy model
28
  RUN python -m spacy download en_core_web_sm
29
 
30
+ # Pre-download models and tokenizers (both deberta and distilbert)
31
  RUN python -c "\
32
+ from transformers import AutoTokenizer, AutoModel; \
33
+ print('Downloading deepset/deberta-v3-base-squad2...'); \
34
+ AutoTokenizer.from_pretrained('deepset/deberta-v3-base-squad2'); \
35
+ AutoModel.from_pretrained('deepset/deberta-v3-base-squad2'); \
36
+ print('Downloading distilbert-base-uncased...'); \
37
+ AutoTokenizer.from_pretrained('distilbert-base-uncased'); \
38
+ AutoModel.from_pretrained('distilbert-base-uncased')"
39
+
40
+ # --- Runtime stage ---
41
+ FROM python:3.12-slim
42
+
43
+ WORKDIR /app
44
+
45
+ # Copy only necessary files from builder
46
+ COPY --from=builder /tmp/huggingface /tmp/huggingface
47
+ COPY --from=builder /usr/local/lib/python3.12/site-packages /usr/local/lib/python3.12/site-packages
48
+ COPY --from=builder /usr/local/bin /usr/local/bin
49
 
50
+ # Create required directories
51
+ RUN mkdir -p /tmp/uploads && chmod -R 777 /tmp/uploads /tmp/huggingface
52
+
53
+ # Set environment variables
54
+ ENV PYTHONUNBUFFERED=1
55
+ ENV UPLOAD_FOLDER=/tmp/uploads
56
+ ENV TRANSFORMERS_CACHE=/tmp/huggingface
57
+ ENV HF_HOME=/tmp/huggingface
58
+
59
+ # Streamlit config
60
  RUN mkdir -p .streamlit && \
61
  echo '[server]\n\
62
  enableCORS=false\n\
 
68
  # Expose port
69
  EXPOSE 7860
70
 
71
+ # Health check
72
+ HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
73
+ CMD curl -f http://localhost:7860/_stcore/health || exit 1
74
+
75
  # Run the application
76
  CMD ["streamlit", "run", "app.py", "--server.port=7860", "--server.address=0.0.0.0"]