Spaces:
Sleeping
Sleeping
Update Dockerfile
Browse files- Dockerfile +1 -26
Dockerfile
CHANGED
|
@@ -1,38 +1,13 @@
|
|
| 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"]
|
|
|
|
|
|
|
| 1 |
FROM python:3.9
|
| 2 |
|
|
|
|
| 3 |
RUN useradd -m -u 1000 user
|
| 4 |
USER user
|
| 5 |
ENV PATH="/home/user/.local/bin:$PATH"
|
| 6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
WORKDIR /app
|
| 8 |
|
|
|
|
| 9 |
COPY --chown=user ./requirements.txt requirements.txt
|
| 10 |
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
| 11 |
|
|
|
|
| 12 |
COPY --chown=user . /app
|
| 13 |
+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|