fizello / Dockerfile
Fizello's picture
Update Dockerfile
43dfe80 verified
Raw
History Blame Contribute Delete
2.4 kB
# Fizello — single-image deployment.
# Compatible with Hugging Face Spaces (port 7860), Render, Fly.io, Railway, any Docker host.
#
# Build : docker build -t fizello .
# Run : docker run -p 7860:7860 -v $(pwd)/hf-cache:/data/hf-cache fizello
FROM python:3.11-slim
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PIP_NO_CACHE_DIR=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1 \
TRANSFORMERS_NO_ADVISORY_WARNINGS=1 \
HF_HUB_DISABLE_TELEMETRY=1 \
HF_HOME=/data/hf-cache
# Native deps for Pillow / piexif / image formats / pypdf
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
libjpeg62-turbo libpng16-16 libtiff6 libwebp7 \
libheif1 libopenjp2-7 zlib1g \
tesseract-ocr tesseract-ocr-fra tesseract-ocr-ita \
tesseract-ocr-eng tesseract-ocr-spa tesseract-ocr-deu \
curl ca-certificates \
&& rm -rf /var/lib/apt/lists/*
# HF Spaces requires UID 1000
RUN useradd --create-home --uid 1000 fizello \
&& mkdir -p /data/hf-cache /app \
&& chown -R fizello:fizello /data /app
WORKDIR /app
# Install CPU-only torch first from the official wheels (smaller + faster to install
# than the default CUDA build). Then the rest of the requirements.
COPY --chown=fizello:fizello requirements.txt .
RUN pip install --no-cache-dir --index-url https://download.pytorch.org/whl/cpu \
torch==2.4.1 torchvision==0.19.1 \
&& pip install --no-cache-dir -r requirements.txt
# Pré-télécharge les modèles ML DANS l'image (build time). Ainsi, à chaque
# démarrage du conteneur (y compris au réveil après mise en veille), les poids
# sont déjà sur le disque : plus aucun téléchargement lent à la première analyse.
RUN python -c "from huggingface_hub import snapshot_download; \
snapshot_download('prithivMLmods/Deep-Fake-Detector-v2-Model'); \
snapshot_download('Organika/sdxl-detector')" \
&& chown -R fizello:fizello /data
# App + frontend
COPY --chown=fizello:fizello app ./app
COPY --chown=fizello:fizello static ./static
USER fizello
# HF Spaces uses 7860 by default; everything else can override with $PORT
ENV PORT=7860
EXPOSE 7860
HEALTHCHECK --interval=30s --timeout=5s --start-period=120s --retries=3 \
CMD curl -fsS http://localhost:${PORT}/health || exit 1
# Bind to 0.0.0.0 so the container is reachable from the outside
CMD ["sh", "-c", "uvicorn app.main:app --host 0.0.0.0 --port ${PORT}"]