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