Spaces:
Runtime error
Runtime error
File size: 1,169 Bytes
adad4ac |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# Use an official Python runtime as a parent image
FROM python:3.9-slim
# Install git and git-lfs
RUN apt-get update && apt-get install -y git git-lfs && git lfs install
# Create a non-root user 'appuser'
RUN useradd -ms /bin/bash appuser
# Set the working directory
WORKDIR /home/appuser/app
# Copy requirements file
COPY requirements.txt .
# Install required packages
RUN pip install --no-cache-dir -r requirements.txt
# Copy application code
COPY . .
# Set environment variables for cache directories
ENV HF_HOME=/home/appuser/app/.cache
ENV HF_DATASETS_CACHE=/home/appuser/app/.cache
# Create the cache directory
RUN mkdir -p /home/appuser/app/.cache
# Change ownership of the application files
RUN chown -R appuser:appuser /home/appuser/app
# Switch to non-root user
USER appuser
# Pre-download models and datasets
RUN python -c "from sentence_transformers import SentenceTransformer; SentenceTransformer('all-MiniLM-L6-v2')"
RUN python -c "from datasets import load_dataset; load_dataset('Gustavosta/Stable-Diffusion-Prompts')"
# Expose port 7860
EXPOSE 7860
# Command to run the API
CMD ["uvicorn", "api:app", "--host", "0.0.0.0", "--port", "7860"]
|