Spaces:
Sleeping
Sleeping
Update Dockerfile
Browse files- Dockerfile +23 -17
Dockerfile
CHANGED
|
@@ -1,29 +1,35 @@
|
|
| 1 |
-
#
|
| 2 |
-
FROM python:3.9-slim
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
-
# Install system dependencies for transformers
|
| 5 |
RUN apt-get update && \
|
| 6 |
apt-get install -y --no-install-recommends gcc python3-dev && \
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
-
# Set working directory
|
| 10 |
WORKDIR /app
|
| 11 |
|
| 12 |
-
#
|
| 13 |
-
COPY
|
| 14 |
-
|
| 15 |
|
| 16 |
-
#
|
| 17 |
-
RUN
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
"""
|
| 21 |
|
| 22 |
-
# Copy application
|
| 23 |
COPY app.py text2generation.py ./
|
| 24 |
|
| 25 |
-
#
|
| 26 |
EXPOSE 7860
|
|
|
|
|
|
|
| 27 |
|
| 28 |
-
#
|
| 29 |
-
CMD ["gunicorn", "--bind", "0.0.0.0:7860", "--workers", "2", "app:app"]
|
|
|
|
| 1 |
+
# Stage 1: Builder for model caching
|
| 2 |
+
FROM python:3.9-slim as builder
|
| 3 |
+
|
| 4 |
+
WORKDIR /app
|
| 5 |
+
COPY requirements.txt .
|
| 6 |
|
|
|
|
| 7 |
RUN apt-get update && \
|
| 8 |
apt-get install -y --no-install-recommends gcc python3-dev && \
|
| 9 |
+
pip install --user -r requirements.txt && \
|
| 10 |
+
python -c "from transformers import pipeline; pipeline('text-generation', model='tiiuae/falcon-7b-instruct')"
|
| 11 |
+
|
| 12 |
+
# Stage 2: Runtime image
|
| 13 |
+
FROM python:3.9-slim
|
| 14 |
|
|
|
|
| 15 |
WORKDIR /app
|
| 16 |
|
| 17 |
+
# Copy only necessary files from builder
|
| 18 |
+
COPY --from=builder /root/.cache /root/.cache
|
| 19 |
+
COPY --from=builder /usr/local/lib/python3.9/site-packages /usr/local/lib/python3.9/site-packages
|
| 20 |
|
| 21 |
+
# Install runtime dependencies
|
| 22 |
+
RUN apt-get update && \
|
| 23 |
+
apt-get install -y --no-install-recommends libgomp1 && \
|
| 24 |
+
rm -rf /var/lib/apt/lists/*
|
|
|
|
| 25 |
|
| 26 |
+
# Copy application code
|
| 27 |
COPY app.py text2generation.py ./
|
| 28 |
|
| 29 |
+
# Configure production server
|
| 30 |
EXPOSE 7860
|
| 31 |
+
HEALTHCHECK --interval=30s --timeout=30s --start-period=120s --retries=3 \
|
| 32 |
+
CMD curl -f http://localhost:7860/health || exit 1
|
| 33 |
|
| 34 |
+
# Use gunicorn with 2 workers (optimal for HF Spaces)
|
| 35 |
+
CMD ["gunicorn", "--bind", "0.0.0.0:7860", "--workers", "2", "--timeout", "120", "app:app"]
|