Spaces:
Running
Running
Update Dockerfile
Browse files- Dockerfile +24 -11
Dockerfile
CHANGED
@@ -1,27 +1,40 @@
|
|
1 |
-
#
|
2 |
-
# you will also find guides on how best to write your Dockerfile
|
3 |
-
|
4 |
FROM python:3.9
|
5 |
|
|
|
6 |
RUN useradd -m -u 1000 user
|
7 |
USER user
|
|
|
|
|
8 |
ENV PATH="/home/user/.local/bin:$PATH"
|
9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
&& python -c "from torchvision.models.detection import fasterrcnn_resnet50_fpn, FasterRCNN_ResNet50_FPN_Weights; \
|
16 |
weights = FasterRCNN_ResNet50_FPN_Weights.DEFAULT; \
|
17 |
model = fasterrcnn_resnet50_fpn(weights=weights)"
|
18 |
|
19 |
-
|
20 |
-
|
21 |
-
WORKDIR /app
|
22 |
-
|
23 |
COPY --chown=user ./requirements.txt requirements.txt
|
24 |
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
25 |
|
|
|
26 |
COPY --chown=user . /app
|
|
|
|
|
|
|
|
|
|
|
27 |
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
|
|
1 |
+
# Use Python 3.9 as the base image
|
|
|
|
|
2 |
FROM python:3.9
|
3 |
|
4 |
+
# Create a user and set permissions
|
5 |
RUN useradd -m -u 1000 user
|
6 |
USER user
|
7 |
+
|
8 |
+
# Ensure PATH includes user's local bin
|
9 |
ENV PATH="/home/user/.local/bin:$PATH"
|
10 |
|
11 |
+
# Set environment variables to cache Hugging Face & Torch models
|
12 |
+
ENV TRANSFORMERS_CACHE="/cache/huggingface"
|
13 |
+
ENV TORCH_HOME="/cache/torch"
|
14 |
+
|
15 |
+
# Set working directory
|
16 |
+
WORKDIR /app
|
17 |
+
|
18 |
+
# Create model cache directories with correct permissions
|
19 |
+
RUN mkdir -p /cache/huggingface /cache/torch && chmod -R 777 /cache
|
20 |
|
21 |
+
# Preload models into cache
|
22 |
+
RUN python -c "from transformers import AutoModelForCausalLM, AutoTokenizer; \
|
23 |
+
AutoModelForCausalLM.from_pretrained('microsoft/phi-2'); \
|
24 |
+
AutoTokenizer.from_pretrained('microsoft/phi-2')" \
|
25 |
&& python -c "from torchvision.models.detection import fasterrcnn_resnet50_fpn, FasterRCNN_ResNet50_FPN_Weights; \
|
26 |
weights = FasterRCNN_ResNet50_FPN_Weights.DEFAULT; \
|
27 |
model = fasterrcnn_resnet50_fpn(weights=weights)"
|
28 |
|
29 |
+
# Copy requirements and install dependencies
|
|
|
|
|
|
|
30 |
COPY --chown=user ./requirements.txt requirements.txt
|
31 |
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
32 |
|
33 |
+
# Copy the rest of the application code
|
34 |
COPY --chown=user . /app
|
35 |
+
|
36 |
+
# Expose the port (optional)
|
37 |
+
EXPOSE 7860
|
38 |
+
|
39 |
+
# Start the FastAPI application with Uvicorn
|
40 |
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|