Spaces:
Sleeping
Sleeping
Update Dockerfile
Browse files- Dockerfile +24 -14
Dockerfile
CHANGED
|
@@ -1,28 +1,38 @@
|
|
| 1 |
-
# Use
|
| 2 |
FROM python:3.10-slim
|
|
|
|
|
|
|
| 3 |
ENV TORCH_DISABLE_CUDA=1
|
|
|
|
|
|
|
| 4 |
|
| 5 |
# Set working directory
|
| 6 |
WORKDIR /app
|
| 7 |
|
| 8 |
-
# Copy
|
| 9 |
COPY requirements.txt .
|
| 10 |
|
| 11 |
-
#
|
| 12 |
-
RUN
|
| 13 |
-
|
|
|
|
| 14 |
|
| 15 |
-
# Copy
|
| 16 |
COPY . .
|
| 17 |
|
| 18 |
-
#
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
# Expose FastAPI port
|
| 22 |
-
EXPOSE 7860
|
| 23 |
|
| 24 |
-
#
|
|
|
|
| 25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
-
# Run FastAPI with uvicorn
|
| 28 |
-
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "]
|
|
|
|
| 1 |
+
# Use a lightweight Python base image
|
| 2 |
FROM python:3.10-slim
|
| 3 |
+
|
| 4 |
+
# Disable CUDA since we're using CPU-only
|
| 5 |
ENV TORCH_DISABLE_CUDA=1
|
| 6 |
+
ENV TRANSFORMERS_CACHE=/app/hf_cache
|
| 7 |
+
ENV HF_HOME=/app/hf_cache
|
| 8 |
|
| 9 |
# Set 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 application code
|
| 21 |
COPY . .
|
| 22 |
|
| 23 |
+
# Make 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 |
+
# Preload model embeddings (optional)
|
| 30 |
+
# Commented out to speed up Cloud Build — will load at runtime in main.py
|
| 31 |
+
# RUN python -c "import torch, pandas as pd; from sentence_transformers import SentenceTransformer; \
|
| 32 |
+
# model = SentenceTransformer('./muril_combined_multilingual_model'); \
|
| 33 |
+
# df = pd.read_csv('./muril_multilingual_dataset.csv').dropna(subset=['question','answer']); \
|
| 34 |
+
# embeddings = model.encode(df['answer'].tolist(), convert_to_tensor=True); \
|
| 35 |
+
# torch.save(embeddings, './answer_embeddings.pt'); print('✅ Precomputed embeddings saved');"
|
| 36 |
|
| 37 |
+
# Run the FastAPI app with uvicorn
|
| 38 |
+
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8080"]
|