Spaces:
Running
Running
# Base image with CUDA 12.6.3 and cuDNN | |
# FROM nvidia/cuda:12.6.3-cudnn-runtime-ubuntu22.04 | |
FROM python:3.10-bookworm | |
# Set environment variables | |
ARG DEBIAN_FRONTEND=noninteractive | |
ENV PYTHONUNBUFFERED=1 \ | |
GRADIO_FLAGGING_MODE=never \ | |
GRADIO_NUM_PORTS=1 \ | |
GRADIO_SERVER_NAME=0.0.0.0 \ | |
GRADIO_THEME=huggingface \ | |
GRADIO_CACHE_DIR=/home/appuser/.gradio_cache \ | |
SYSTEM=spaces \ | |
AM_I_IN_A_DOCKER_CONTAINER=Yes \ | |
PYTHONPATH=/home/appuser/app \ | |
HF_HOME=/home/appuser/.cache \ | |
TORCH_HOME=/home/appuser/.cache \ | |
TMP_DIR=/home/appuser/tmp \ | |
TRANSFORMERS_CACHE=/home/appuser/.cache/transformers \ | |
NVIDIA_VISIBLE_DEVICES=all \ | |
NVIDIA_DRIVER_CAPABILITIES=compute,utility | |
# Install system dependencies and set Python 3.10 as default | |
RUN apt-get update && apt-get install --no-install-recommends -y \ | |
build-essential \ | |
curl \ | |
git \ | |
ffmpeg \ | |
libsm6 \ | |
libxext6 \ | |
libgl1 \ | |
&& apt-get clean && rm -rf /var/lib/apt/lists/* | |
# Create a non-root user | |
RUN useradd -m -u 1000 appuser | |
# Set working directory | |
WORKDIR /home/appuser/app | |
# Ensure non-root user has write access to cache and tmp directories | |
RUN mkdir -p /home/appuser/.cache/transformers /home/appuser/tmp /home/appuser/.cache \ | |
&& chown -R appuser:appuser /home/appuser/.cache /home/appuser/tmp/ /home/appuser/app/ | |
# Switch to non-root user | |
USER appuser | |
# Expose port for Gradio | |
EXPOSE 7860 | |
# Install `uv` | |
RUN curl -LsSf https://astral.sh/uv/install.sh | sh | |
# Change shell to bash | |
SHELL ["/bin/bash", "-c"] | |
# Copy dependency files and install dependencies | |
COPY --chown=appuser pyproject.toml dawsonia.toml uv.lock LICENSE README.md ./ | |
RUN /home/appuser/.local/bin/uv sync -p 3.10 --frozen --no-cache \ | |
&& chown -R appuser:appuser /home/appuser/app/.venv \ | |
&& rm -rf /home/appuser/.cache | |
# Copy application code | |
COPY --chown=appuser app app | |
COPY --chown=appuser table_formats table_formats | |
COPY --chown=appuser examples examples | |
COPY --chown=appuser output output | |
COPY --chown=appuser data data | |
# Command to run the application | |
CMD ["/home/appuser/.local/bin/uv", "run", "app/main.py"] | |