Spaces:
Sleeping
Sleeping
Update Dockerfile
Browse files- Dockerfile +17 -46
Dockerfile
CHANGED
|
@@ -1,59 +1,30 @@
|
|
| 1 |
-
#
|
| 2 |
-
# β
Base Image
|
| 3 |
-
# -------------------------------
|
| 4 |
FROM python:3.10-slim
|
| 5 |
|
| 6 |
-
#
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
ENV
|
| 10 |
-
TORCH_DISABLE_CUDA=1 \
|
| 11 |
-
TRANSFORMERS_CACHE=/app/hf_cache \
|
| 12 |
-
HF_HOME=/app/hf_cache
|
| 13 |
|
|
|
|
| 14 |
WORKDIR /app
|
| 15 |
|
| 16 |
-
#
|
| 17 |
-
# β
System Dependencies
|
| 18 |
-
# -------------------------------
|
| 19 |
-
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 20 |
-
git \
|
| 21 |
-
&& rm -rf /var/lib/apt/lists/*
|
| 22 |
-
|
| 23 |
-
# -------------------------------
|
| 24 |
-
# β
Install Python Dependencies
|
| 25 |
-
# -------------------------------
|
| 26 |
COPY requirements.txt .
|
| 27 |
-
RUN pip install --no-cache-dir -r requirements.txt
|
| 28 |
|
| 29 |
-
#
|
| 30 |
-
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
| 32 |
COPY . .
|
| 33 |
|
| 34 |
-
#
|
| 35 |
-
# β
Prepare Cache & Permissions
|
| 36 |
-
# -------------------------------
|
| 37 |
RUN mkdir -p /app/hf_cache && chmod -R 777 /app/hf_cache
|
| 38 |
|
| 39 |
-
#
|
| 40 |
-
# β
Expose Port
|
| 41 |
-
# -------------------------------
|
| 42 |
EXPOSE 8080
|
| 43 |
|
| 44 |
-
#
|
| 45 |
-
|
| 46 |
-
# -------------------------------
|
| 47 |
-
# NOTE:
|
| 48 |
-
# Model & embeddings are loaded lazily in a background thread (main.py)
|
| 49 |
-
# so container becomes healthy immediately and avoids 30-min timeout.
|
| 50 |
-
#
|
| 51 |
-
# You can preload if you really want, but itβs slower on build:
|
| 52 |
-
# RUN python -c "from sentence_transformers import SentenceTransformer; \
|
| 53 |
-
# model = SentenceTransformer('./muril_combined_multilingual_model'); \
|
| 54 |
-
# print('β
Model preloaded')"
|
| 55 |
-
|
| 56 |
-
# -------------------------------
|
| 57 |
-
# β
Start FastAPI with Uvicorn
|
| 58 |
-
# -------------------------------
|
| 59 |
-
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8080"]
|
|
|
|
| 1 |
+
# Use lightweight Python base image
|
|
|
|
|
|
|
| 2 |
FROM python:3.10-slim
|
| 3 |
|
| 4 |
+
# Disable CUDA & set cache locations
|
| 5 |
+
ENV TORCH_DISABLE_CUDA=1
|
| 6 |
+
ENV TRANSFORMERS_CACHE=/app/hf_cache
|
| 7 |
+
ENV HF_HOME=/app/hf_cache
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
+
# Working directory
|
| 10 |
WORKDIR /app
|
| 11 |
|
| 12 |
+
# Copy dependency list
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
COPY requirements.txt .
|
|
|
|
| 14 |
|
| 15 |
+
# Install dependencies efficiently
|
| 16 |
+
RUN apt-get update && apt-get install -y git && \
|
| 17 |
+
pip install --no-cache-dir -r requirements.txt && \
|
| 18 |
+
rm -rf /var/lib/apt/lists/*
|
| 19 |
+
|
| 20 |
+
# Copy app code
|
| 21 |
COPY . .
|
| 22 |
|
| 23 |
+
# Create cache folder (writable)
|
|
|
|
|
|
|
| 24 |
RUN mkdir -p /app/hf_cache && chmod -R 777 /app/hf_cache
|
| 25 |
|
| 26 |
+
# Expose port
|
|
|
|
|
|
|
| 27 |
EXPOSE 8080
|
| 28 |
|
| 29 |
+
# Run the FastAPI app
|
| 30 |
+
CMD ["python", "main.py"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|