Spaces:
Runtime error
Runtime error
Update Dockerfile
Browse files- Dockerfile +30 -23
Dockerfile
CHANGED
|
@@ -1,40 +1,47 @@
|
|
| 1 |
-
#
|
| 2 |
-
FROM python:3.9-slim
|
| 3 |
|
| 4 |
-
#
|
| 5 |
ENV PYTHONDONTWRITEBYTECODE=1 \
|
| 6 |
PYTHONUNBUFFERED=1 \
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
|
|
|
| 10 |
|
| 11 |
-
#
|
| 12 |
WORKDIR /app
|
| 13 |
|
| 14 |
-
# Install
|
| 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
|
| 22 |
-
COPY . .
|
| 23 |
|
| 24 |
# Install Python dependencies
|
| 25 |
RUN pip install --upgrade pip && \
|
| 26 |
pip install --no-cache-dir -r requirements.txt
|
| 27 |
|
| 28 |
-
#
|
| 29 |
-
|
| 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 |
-
#
|
| 37 |
-
|
| 38 |
|
| 39 |
-
#
|
| 40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|