qtAnswering / Dockerfile
ikraamkb's picture
Update Dockerfile
ce61d8a verified
raw
history blame
1.4 kB
# Use Python 3.9 as the base image
FROM python:3.9
# Create a user and set permissions
RUN useradd -m -u 1000 user
USER user
# Ensure PATH includes user's local bin
ENV PATH="/home/user/.local/bin:$PATH"
# Set environment variables to cache Hugging Face & Torch models
ENV TRANSFORMERS_CACHE="/cache/huggingface"
ENV TORCH_HOME="/cache/torch"
# Set working directory
WORKDIR /app
# Create model cache directories with correct permissions
RUN mkdir -p /cache/huggingface /cache/torch && chmod -R 777 /cache
# Preload models into cache
RUN python -c "from transformers import AutoModelForCausalLM, AutoTokenizer; \
AutoModelForCausalLM.from_pretrained('microsoft/phi-2'); \
AutoTokenizer.from_pretrained('microsoft/phi-2')" \
&& python -c "from torchvision.models.detection import fasterrcnn_resnet50_fpn, FasterRCNN_ResNet50_FPN_Weights; \
weights = FasterRCNN_ResNet50_FPN_Weights.DEFAULT; \
model = fasterrcnn_resnet50_fpn(weights=weights)"
# Copy requirements and install dependencies
COPY --chown=user ./requirements.txt requirements.txt
RUN pip install --no-cache-dir --upgrade -r requirements.txt
# Copy the rest of the application code
COPY --chown=user . /app
# Expose the port (optional)
EXPOSE 7860
# Start the FastAPI application with Uvicorn
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]