Spaces:
Sleeping
Sleeping
Mohammad Zeeshan commited on
Update Dockerfile
Browse files- Dockerfile +21 -14
Dockerfile
CHANGED
|
@@ -1,26 +1,33 @@
|
|
| 1 |
-
#
|
| 2 |
-
FROM python:3.9
|
| 3 |
|
| 4 |
-
# Set the working directory
|
| 5 |
WORKDIR /app
|
|
|
|
| 6 |
|
| 7 |
-
# Copy the requirements file into the container
|
| 8 |
-
COPY requirements.txt .
|
| 9 |
-
|
| 10 |
-
# Install the dependencies
|
| 11 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 12 |
|
| 13 |
-
#
|
| 14 |
-
|
|
|
|
|
|
|
| 15 |
|
| 16 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
ENV TRANSFORMERS_CACHE=/app/cache
|
|
|
|
| 18 |
|
| 19 |
-
# Copy
|
| 20 |
COPY . .
|
| 21 |
|
| 22 |
-
#
|
|
|
|
|
|
|
|
|
|
| 23 |
EXPOSE 7860
|
| 24 |
|
| 25 |
-
#
|
| 26 |
-
CMD ["
|
|
|
|
| 1 |
+
# 🏗️ Stage 1: Build dependencies in a lightweight Python image
|
| 2 |
+
FROM python:3.9-slim AS builder
|
| 3 |
|
|
|
|
| 4 |
WORKDIR /app
|
| 5 |
+
COPY requirements.txt .
|
| 6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 8 |
|
| 9 |
+
# 🚀 Stage 2: Final optimized production image
|
| 10 |
+
FROM python:3.9-slim
|
| 11 |
+
|
| 12 |
+
WORKDIR /app
|
| 13 |
|
| 14 |
+
# Copy dependencies from builder stage
|
| 15 |
+
COPY --from=builder /usr/local/lib/python3.9/site-packages /usr/local/lib/python3.9/site-packages
|
| 16 |
+
COPY --from=builder /usr/local/bin /usr/local/bin
|
| 17 |
+
|
| 18 |
+
# Set up a persistent cache for Hugging Face models
|
| 19 |
+
RUN mkdir -p /app/cache && chmod -R 777 /app/cache
|
| 20 |
ENV TRANSFORMERS_CACHE=/app/cache
|
| 21 |
+
ENV HF_HOME=/app/cache
|
| 22 |
|
| 23 |
+
# Copy application code
|
| 24 |
COPY . .
|
| 25 |
|
| 26 |
+
# Preload the model (avoid startup delays)
|
| 27 |
+
RUN python -c "from transformers import pipeline; pipeline('translation', model='facebook/m2m100_418M')"
|
| 28 |
+
|
| 29 |
+
# Expose port
|
| 30 |
EXPOSE 7860
|
| 31 |
|
| 32 |
+
# Start the FastAPI server using Uvicorn
|
| 33 |
+
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "2", "--timeout-keep-alive", "5"]
|