ayush2917 commited on
Commit
1790f92
·
verified ·
1 Parent(s): 8d1f4b0

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +30 -23
Dockerfile CHANGED
@@ -1,40 +1,47 @@
1
- # Base image
2
- FROM python:3.9-slim-buster
3
 
4
- # Environment variables
5
  ENV PYTHONDONTWRITEBYTECODE=1 \
6
  PYTHONUNBUFFERED=1 \
7
- TOKENIZERS_PARALLELISM=false \
8
- HF_HOME=/app/cache \
9
- HUGGINGFACE_HUB_CACHE=/app/cache
 
10
 
11
- # Set working directory
12
  WORKDIR /app
13
 
14
- # Install OS dependencies
15
  RUN apt-get update && apt-get install -y --no-install-recommends \
16
  build-essential \
17
- libgomp1 \
18
- curl \
19
  && rm -rf /var/lib/apt/lists/*
20
 
21
- # Copy files
22
- COPY . .
23
 
24
  # Install Python dependencies
25
  RUN pip install --upgrade pip && \
26
  pip install --no-cache-dir -r requirements.txt
27
 
28
- # Preload models into cache
29
- RUN python -c "\
30
- from sentence_transformers import SentenceTransformer; \
31
- SentenceTransformer('all-MiniLM-L6-v2', cache_folder='/app/cache'); \
32
- from transformers import AutoModelForCausalLM, AutoTokenizer; \
33
- AutoModelForCausalLM.from_pretrained('distilgpt2', cache_dir='/app/cache'); \
34
- AutoTokenizer.from_pretrained('distilgpt2', cache_dir='/app/cache')"
35
 
36
- # Hugging Face Spaces expects app on port 7860
37
- ENV PORT=7860
38
 
39
- # Run with Gunicorn (bind to PORT)
40
- CMD ["gunicorn", "--bind", "0.0.0.0:7860", "app:app"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Use the official Hugging Face Docker image as base
2
+ FROM python:3.9-slim
3
 
4
+ # Set environment variables
5
  ENV PYTHONDONTWRITEBYTECODE=1 \
6
  PYTHONUNBUFFERED=1 \
7
+ HF_HOME=/cache \
8
+ HUGGINGFACE_HUB_CACHE=/cache \
9
+ PIP_NO_CACHE_DIR=1 \
10
+ PORT=8000
11
 
12
+ # Create and set working directory
13
  WORKDIR /app
14
 
15
+ # Install system dependencies
16
  RUN apt-get update && apt-get install -y --no-install-recommends \
17
  build-essential \
 
 
18
  && rm -rf /var/lib/apt/lists/*
19
 
20
+ # Copy requirements first for better caching
21
+ COPY requirements.txt .
22
 
23
  # Install Python dependencies
24
  RUN pip install --upgrade pip && \
25
  pip install --no-cache-dir -r requirements.txt
26
 
27
+ # Copy the rest of the application
28
+ COPY . .
 
 
 
 
 
29
 
30
+ # Create necessary directories
31
+ RUN mkdir -p /app/data /cache
32
 
33
+ # Download models during build (optional)
34
+ RUN python -c "\
35
+ try: \
36
+ from sentence_transformers import SentenceTransformer; \
37
+ SentenceTransformer('all-MiniLM-L6-v2', cache_folder='/cache'); \
38
+ from transformers import AutoModelForCausalLM, AutoTokenizer; \
39
+ AutoModelForCausalLM.from_pretrained('distilgpt2', cache_dir='/cache'); \
40
+ AutoTokenizer.from_pretrained('distilgpt2', cache_dir='/cache'); \
41
+ except Exception as e: \
42
+ print(f'Model preloading failed: {str(e)}'); \
43
+ raise \
44
+ "
45
+
46
+ # Run the application
47
+ CMD gunicorn --bind 0.0.0.0:$PORT --workers 2 --timeout 120 --preload app:app