Spaces:
Running
on
T4
Running
on
T4
# Base image with CUDA 12.6.3 and cuDNN | |
FROM nvidia/cuda:12.6.3-cudnn-runtime-ubuntu22.04 | |
# Set environment variables | |
ARG DEBIAN_FRONTEND=noninteractive | |
ENV PYTHONUNBUFFERED=1 \ | |
GRADIO_ALLOW_FLAGGING=never \ | |
GRADIO_NUM_PORTS=1 \ | |
GRADIO_SERVER_NAME=0.0.0.0 \ | |
GRADIO_THEME=huggingface \ | |
SYSTEM=spaces \ | |
AM_I_IN_A_DOCKER_CONTAINER=Yes \ | |
PYTHONPATH=/home/appuser/app \ | |
HF_HOME=/home/appuser/.cache \ | |
TORCH_HOME=/home/appuser/.cache \ | |
NVIDIA_VISIBLE_DEVICES=all \ | |
NVIDIA_DRIVER_CAPABILITIES=compute,utility | |
# Install system dependencies | |
RUN apt-get update && apt-get install --no-install-recommends -y \ | |
build-essential \ | |
python3.10 \ | |
python3.10-distutils \ | |
python3-pip \ | |
ffmpeg \ | |
libsm6 \ | |
libxext6 \ | |
libgl1 \ | |
&& apt-get clean && rm -rf /var/lib/apt/lists/* | |
# Set Python 3.10 as the default python3 and pip | |
RUN ln -sf /usr/bin/python3.10 /usr/bin/python \ | |
&& ln -sf /usr/bin/pip3 /usr/bin/pip | |
# Install `uv` | |
RUN pip install --upgrade pip \ | |
&& pip install uv | |
# Create a non-root user | |
RUN useradd -m -u 1000 appuser | |
# Set working directory to the user's home directory | |
WORKDIR /home/appuser/app | |
# Copy dependency files, including LICENSE and README.md | |
COPY --chown=appuser pyproject.toml uv.lock LICENSE README.md ./ | |
# Install dependencies using `uv` | |
RUN uv sync --frozen | |
# Copy the application code | |
COPY --chown=appuser app app | |
# Ensure non-root user has write access to the cache directory | |
RUN mkdir -p /home/appuser/.cache && chown -R appuser:appuser /home/appuser/.cache | |
# Set ownership for all files to the app user | |
# Avoid unnecessary `chown` for better performance since `COPY --chown` already sets ownership | |
# Switch to the non-root user | |
USER appuser | |
# Set the cache directory for Hugging Face and other tools | |
ENV HF_HOME=$CACHE_DIR \ | |
TRANSFORMERS_CACHE=$CACHE_DIR \ | |
TORCH_HOME=$CACHE_DIR | |
# Expose the port for Gradio | |
EXPOSE 7862 | |
# Command to run the application | |
CMD ["uv", "run", "python", "app/main.py"] | |