akashjayampu commited on
Commit
b47756a
·
verified ·
1 Parent(s): ea959d9

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +19 -14
Dockerfile CHANGED
@@ -1,26 +1,31 @@
 
1
  FROM python:3.9-slim
2
 
3
- # Set environment variables for Hugging Face cache
4
  ENV HF_HOME=/app/.cache/huggingface
5
 
 
6
  WORKDIR /app
7
 
8
- # Install dependencies
 
 
 
9
  COPY requirements.txt .
10
  RUN pip install --no-cache-dir -r requirements.txt
11
 
12
- # Copy your app source code
13
- COPY src/ ./src
14
-
15
- # Set environment variable for HF token (pass your real token at build/run time or use build args)
16
- ARG HF_TOKEN
17
- ENV HF_TOKEN=${HF_TOKEN}
18
 
19
- # Optional: pre-download models (skip if gated or use runtime download)
20
- # RUN python3 -c "from transformers import pipeline; pipeline('sentiment-analysis', model='distilbert-base-uncased-finetuned-sst-2-english')"
 
 
 
 
21
 
22
- # Expose port for Streamlit
23
- EXPOSE 8501
24
 
25
- # Run your Streamlit app
26
- CMD ["streamlit", "run", "src/streamlit_app.py", "--server.port=8501", "--server.address=0.0.0.0"]
 
1
+ # Use lightweight Python base image
2
  FROM python:3.9-slim
3
 
4
+ # Set Hugging Face cache directory (replaces deprecated TRANSFORMERS_CACHE)
5
  ENV HF_HOME=/app/.cache/huggingface
6
 
7
+ # Set working directory
8
  WORKDIR /app
9
 
10
+ # Create cache directory with open permissions
11
+ RUN mkdir -p /app/.cache/huggingface && chmod -R 777 /app/.cache/huggingface
12
+
13
+ # Install Python dependencies
14
  COPY requirements.txt .
15
  RUN pip install --no-cache-dir -r requirements.txt
16
 
17
+ # Copy app files
18
+ COPY . .
 
 
 
 
19
 
20
+ # Preload gated and public models using secret HF_TOKEN
21
+ RUN python3 -c "import os; from transformers import pipeline; \
22
+ pipe = pipeline('summarization', model='mistralai/Mistral-7B-Instruct-v0.1', \
23
+ tokenizer='mistralai/Mistral-7B-Instruct-v0.1', use_auth_token=os.getenv('HF_TOKEN'))" && \
24
+ python3 -c "from transformers import pipeline; \
25
+ pipeline('sentiment-analysis', model='distilbert-base-uncased-finetuned-sst-2-english')"
26
 
27
+ # Expose Streamlit default port
28
+ EXPOSE 7860
29
 
30
+ # Run Streamlit app
31
+ CMD ["streamlit", "run", "src/streamlit_app.py", "--server.port=7860", "--server.address=0.0.0.0"]