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

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +33 -21
Dockerfile CHANGED
@@ -1,40 +1,52 @@
 
1
  FROM python:3.12-slim
2
 
 
3
  WORKDIR /app
4
 
5
- # Install minimal system dependencies
6
  RUN apt-get update && apt-get install -y \
 
 
7
  git \
8
  && rm -rf /var/lib/apt/lists/*
9
 
10
- # Copy requirements first for better caching
11
- COPY requirements.txt .
12
- RUN pip install --no-cache-dir -r requirements.txt
13
- RUN python -m spacy download en_core_web_sm
14
-
15
- # Verify transformers installation and explicitly install if needed
16
- RUN pip install --no-cache-dir transformers[torch] pytorch-transformers
17
-
18
- # Pre-download model with simplified import approach
19
- RUN python -c "from transformers import pipeline; \
20
- nlp = pipeline('question-answering', model='deepset/deberta-v3-base-squad2', cache_dir='/tmp/huggingface');"
21
-
22
- # Create accessible directories
23
  RUN mkdir -p /tmp/uploads /tmp/huggingface \
24
  && chmod -R 777 /tmp/uploads /tmp/huggingface
25
 
26
- # Streamlit config
27
- RUN mkdir -p .streamlit && echo '[server]\nenableCORS=false\nenableXsrfProtection=false\n\n[browser]\nserverAddress="0.0.0.0"\nserverPort=7860' > .streamlit/config.toml
28
-
29
- # Environment variables
30
- ENV TRANSFORMERS_CACHE=/tmp/huggingface
31
- ENV HF_HOME=/tmp/huggingface
32
  ENV PYTHONUNBUFFERED=1
33
  ENV UPLOAD_FOLDER=/tmp/uploads
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
 
35
- # Copy app code
36
  COPY . .
37
 
 
38
  EXPOSE 7860
39
 
 
40
  CMD ["streamlit", "run", "app.py", "--server.port=7860", "--server.address=0.0.0.0"]
 
1
+ # Use official Python 3.12 image
2
  FROM python:3.12-slim
3
 
4
+ # Set working directory
5
  WORKDIR /app
6
 
7
+ # Install system dependencies
8
  RUN apt-get update && apt-get install -y \
9
+ build-essential \
10
+ curl \
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
28
+ RUN pip install --no-cache-dir -r requirements.txt
29
+
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\
43
+ enableXsrfProtection=false\n' > .streamlit/config.toml
44
 
45
+ # Copy application code
46
  COPY . .
47
 
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"]