# Read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker FROM python:3.11-slim # Install ffmpeg + system deps as ROOT (prima di switchare utente) RUN apt-get update && apt-get install -y --no-install-recommends \ ffmpeg \ curl \ ca-certificates \ && rm -rf /var/lib/apt/lists/* # Verifica ffmpeg installato RUN ffmpeg -version && ffprobe -version # Crea utente non-root (richiesto da HF Spaces) RUN useradd -m -u 1000 user USER user ENV PATH="/home/user/.local/bin:$PATH" \ PYTHONUNBUFFERED=1 \ PYTHONDONTWRITEBYTECODE=1 \ PIP_NO_CACHE_DIR=1 \ PIP_DISABLE_PIP_VERSION_CHECK=1 WORKDIR /app # Copia e installa requirements COPY --chown=user ./requirements.txt requirements.txt RUN pip install --no-cache-dir --upgrade -r requirements.txt # Copia codice COPY --chown=user . /app # Crea cartelle necessarie con permessi corretti RUN mkdir -p /tmp/public && chmod 777 /tmp/public EXPOSE 7860 # Healthcheck opzionale HEALTHCHECK --interval=30s --timeout=10s --start-period=20s --retries=3 \ CMD curl -f http://localhost:7860/health || exit 1 # Avvio: 1 worker (per condividere JOBS dict in memoria), no reload CMD ["uvicorn", "app:app", \ "--host", "0.0.0.0", \ "--port", "7860", \ "--workers", "1", \ "--log-level", "info", \ "--timeout-keep-alive", "120", \ "--limit-concurrency", "100"]