babaTEEpe's picture
Update Dockerfile
73ad60e verified
FROM python:3.10-slim
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
ENV HOME=/home/user
ENV PATH=/home/user/.local/bin:$PATH
# Create a non-root user (required by Hugging Face)
RUN useradd -m -u 1000 user
WORKDIR /app
# Install system dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
ffmpeg \
espeak \
libespeak1 \
libsm6 \
libxext6 \
libgl1 \
libblas3 \
liblapack3 \
&& rm -rf /var/lib/apt/lists/*
# Copy requirements and install
COPY requirements.txt .
RUN pip install --no-cache-dir --upgrade pip && \
pip install --no-cache-dir -r requirements.txt && \
pip install --no-cache-dir hf_transfer
# Create necessary directories and set permissions
RUN mkdir -p /app/temp /app/outputs && \
chown -R user:user /app
# Copy the rest of the application
COPY --chown=user . .
# Switch to non-root user
USER user
# Set higher-speed download env
ENV HF_HUB_ENABLE_HF_TRANSFER=1
# Pre-download models to cache as the correct USER using CLI (more memory efficient)
RUN huggingface-cli download HuggingFaceTB/SmolLM2-1.7B-Instruct
RUN huggingface-cli download runwayml/stable-diffusion-v1-5
# HuggingFace Spaces expects port 7860
EXPOSE 7860
# Launch the app
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]