MoizK commited on
Commit
9c3b266
·
verified ·
1 Parent(s): a682f32

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +30 -12
Dockerfile CHANGED
@@ -1,5 +1,7 @@
 
1
  FROM python:3.10-slim
2
 
 
3
  RUN apt-get update && \
4
  apt-get install -y \
5
  build-essential \
@@ -7,12 +9,20 @@ RUN apt-get update && \
7
  poppler-utils \
8
  && rm -rf /var/lib/apt/lists/*
9
 
 
10
  WORKDIR /app
11
 
12
- # pre-create Chainlit’s runtime dirs so it won’t hit permission errors
13
- RUN mkdir -p /app/.files /app/.chainlit && \
14
- chmod a+rwx /app/.files /app/.chainlit
15
-
 
 
 
 
 
 
 
16
  ENV PYTHONUNBUFFERED=1
17
  ENV TRANSFORMERS_CACHE=/app/model_cache
18
  ENV HF_HOME=/app/model_cache
@@ -20,19 +30,27 @@ ENV TORCH_HOME=/app/model_cache
20
  ENV CHAINLIT_HOST=0.0.0.0
21
  ENV CHAINLIT_PORT=7860
22
 
 
23
  COPY requirements.txt .
24
  RUN pip install --no-cache-dir -r requirements.txt
25
 
26
- RUN mkdir -p /app/model_cache /app/vectorstore/db_faiss /app/data
27
-
28
  COPY model.py ingest.py chainlit.md download_assets.py ./
29
 
30
- RUN python -c "from transformers import AutoTokenizer, AutoModelForSeq2SeqLM; \
31
- AutoTokenizer.from_pretrained('google/flan-t5-base'); \
32
- AutoModelForSeq2SeqLM.from_pretrained('google/flan-t5-base'); \
33
- from sentence_transformers import SentenceTransformer; \
34
- SentenceTransformer('sentence-transformers/all-MiniLM-L6-v2')"
 
 
 
35
 
 
36
  EXPOSE 7860
37
 
38
- CMD ["chainlit", "run", "model.py", "--host", "0.0.0.0", "--port", "7860"]
 
 
 
 
 
1
+ # Use Python 3.10 slim image as base
2
  FROM python:3.10-slim
3
 
4
+ # Install system dependencies
5
  RUN apt-get update && \
6
  apt-get install -y \
7
  build-essential \
 
9
  poppler-utils \
10
  && rm -rf /var/lib/apt/lists/*
11
 
12
+ # Set working directory
13
  WORKDIR /app
14
 
15
+ # Pre-create all runtime & cache dirs with open perms
16
+ RUN mkdir -p \
17
+ /app/.files \
18
+ /app/.chainlit \
19
+ /app/.cache \
20
+ /app/model_cache \
21
+ /app/vectorstore/db_faiss \
22
+ /app/data && \
23
+ chmod -R a+rwx /app/.files /app/.chainlit /app/.cache /app/model_cache /app/vectorstore /app/data
24
+
25
+ # Environment variables
26
  ENV PYTHONUNBUFFERED=1
27
  ENV TRANSFORMERS_CACHE=/app/model_cache
28
  ENV HF_HOME=/app/model_cache
 
30
  ENV CHAINLIT_HOST=0.0.0.0
31
  ENV CHAINLIT_PORT=7860
32
 
33
+ # Install Python deps
34
  COPY requirements.txt .
35
  RUN pip install --no-cache-dir -r requirements.txt
36
 
37
+ # Copy your application code
 
38
  COPY model.py ingest.py chainlit.md download_assets.py ./
39
 
40
+ # Pre‐warm large models into the cache (so first startup is fast)
41
+ RUN python -c "\
42
+ from transformers import AutoTokenizer, AutoModelForSeq2SeqLM; \
43
+ AutoTokenizer.from_pretrained('google/flan-t5-base'); \
44
+ AutoModelForSeq2SeqLM.from_pretrained('google/flan-t5-base'); \
45
+ from sentence_transformers import SentenceTransformer; \
46
+ SentenceTransformer('sentence-transformers/all-MiniLM-L6-v2')\
47
+ "
48
 
49
+ # Expose Chainlit’s port
50
  EXPOSE 7860
51
 
52
+ # On container start, download your assets then launch Chainlit
53
+ CMD ["sh", "-c", "\
54
+ python download_assets.py && \
55
+ exec chainlit run model.py --host 0.0.0.0 --port 7860\
56
+ "]