Commit ·
a46b08f
1
Parent(s): e480039
Deploy DeepFake Detector API - 2026-04-21 02:45:09
Browse files- Dockerfile +8 -20
- README.md +13 -0
- requirements-optional.txt +6 -0
- requirements-runtime.txt +32 -0
- requirements.txt +4 -40
Dockerfile
CHANGED
|
@@ -17,12 +17,6 @@ ENV PYTHONDONTWRITEBYTECODE=1 \
|
|
| 17 |
HF_HOME=/app/.hf_cache/hf_home \
|
| 18 |
HF_XET_CACHE=/app/.hf_cache/xet
|
| 19 |
|
| 20 |
-
# Install system dependencies
|
| 21 |
-
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 22 |
-
curl \
|
| 23 |
-
git \
|
| 24 |
-
&& rm -rf /var/lib/apt/lists/*
|
| 25 |
-
|
| 26 |
# Create non-root user (HF Spaces requirement)
|
| 27 |
RUN useradd -m -u 1000 user
|
| 28 |
USER user
|
|
@@ -30,9 +24,14 @@ USER user
|
|
| 30 |
# Set PATH for user-installed packages
|
| 31 |
ENV PATH="/home/user/.local/bin:$PATH"
|
| 32 |
|
| 33 |
-
#
|
| 34 |
-
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
# Copy only files required for model prefetch first.
|
| 38 |
COPY --chown=user:user app /app/app
|
|
@@ -47,17 +46,6 @@ RUN mkdir -p /app/.hf_cache /app/.hf_cache/hf_home /app/.hf_cache/xet \
|
|
| 47 |
# Switch back to user
|
| 48 |
USER user
|
| 49 |
|
| 50 |
-
# Prefetch model artifacts at build time so startup does not wait on model downloads.
|
| 51 |
-
RUN HF_CACHE_DIR=/app/.hf_cache HF_HUB_CACHE=/app/.hf_cache HF_HOME=/app/.hf_cache/hf_home HF_XET_CACHE=/app/.hf_cache/xet python -m app.scripts.prefetch_models
|
| 52 |
-
|
| 53 |
-
# Copy full project contents after prefetch so docs/tests edits do not invalidate prefetch layers.
|
| 54 |
-
COPY --chown=user:user . /app
|
| 55 |
-
|
| 56 |
-
# Final copy can strip executable mode from scripts on Windows hosts; re-apply execute bit.
|
| 57 |
-
USER root
|
| 58 |
-
RUN chmod +x /app/start.sh
|
| 59 |
-
USER user
|
| 60 |
-
|
| 61 |
# Expose default app port
|
| 62 |
EXPOSE 7860
|
| 63 |
|
|
|
|
| 17 |
HF_HOME=/app/.hf_cache/hf_home \
|
| 18 |
HF_XET_CACHE=/app/.hf_cache/xet
|
| 19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
# Create non-root user (HF Spaces requirement)
|
| 21 |
RUN useradd -m -u 1000 user
|
| 22 |
USER user
|
|
|
|
| 24 |
# Set PATH for user-installed packages
|
| 25 |
ENV PATH="/home/user/.local/bin:$PATH"
|
| 26 |
|
| 27 |
+
# Install runtime dependencies by default (inference + explainability + LLM).
|
| 28 |
+
# Optional dependencies are local test tools.
|
| 29 |
+
ARG INSTALL_OPTIONAL_DEPS=false
|
| 30 |
+
COPY --chown=user:user requirements-runtime.txt requirements-optional.txt requirements.txt ./
|
| 31 |
+
RUN pip install --no-cache-dir --upgrade -r requirements-runtime.txt \
|
| 32 |
+
&& if [ "$INSTALL_OPTIONAL_DEPS" = "true" ]; then \
|
| 33 |
+
pip install --no-cache-dir --upgrade -r requirements-optional.txt; \
|
| 34 |
+
fi
|
| 35 |
|
| 36 |
# Copy only files required for model prefetch first.
|
| 37 |
COPY --chown=user:user app /app/app
|
|
|
|
| 46 |
# Switch back to user
|
| 47 |
USER user
|
| 48 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
# Expose default app port
|
| 50 |
EXPOSE 7860
|
| 51 |
|
README.md
CHANGED
|
@@ -73,6 +73,7 @@ HF Spaces deploy variables (used by [backend/deploy-to-hf.sh](deploy-to-hf.sh)):
|
|
| 73 |
- `HF_SPACE_WEB_URL`
|
| 74 |
- `HF_SPACE_APP_URL`
|
| 75 |
- `HF_DEPLOY_DIR`
|
|
|
|
| 76 |
- `HF_BUCKET_SYNC_ON_DEPLOY` (default: `true`)
|
| 77 |
|
| 78 |
## API Endpoints
|
|
@@ -99,6 +100,18 @@ docker build -t deepfake-detector-api .
|
|
| 99 |
docker run -p 7860:7860 deepfake-detector-api
|
| 100 |
```
|
| 101 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
## Deploy to Hugging Face Spaces
|
| 103 |
|
| 104 |
Recommended path is the Bash deploy script.
|
|
|
|
| 73 |
- `HF_SPACE_WEB_URL`
|
| 74 |
- `HF_SPACE_APP_URL`
|
| 75 |
- `HF_DEPLOY_DIR`
|
| 76 |
+
- `INSTALL_OPTIONAL_DEPS` (`true`/`false`, default `false`)
|
| 77 |
- `HF_BUCKET_SYNC_ON_DEPLOY` (default: `true`)
|
| 78 |
|
| 79 |
## API Endpoints
|
|
|
|
| 100 |
docker run -p 7860:7860 deepfake-detector-api
|
| 101 |
```
|
| 102 |
|
| 103 |
+
Image defaults:
|
| 104 |
+
|
| 105 |
+
- Installs `requirements-runtime.txt` (inference + explainability + LLM)
|
| 106 |
+
- Skips build-time model prefetch (first boot fills `/data` cache)
|
| 107 |
+
- `POST /predict` defaults to `explain=true`
|
| 108 |
+
|
| 109 |
+
Enable optional test dependencies at build time:
|
| 110 |
+
|
| 111 |
+
```bash
|
| 112 |
+
docker build --build-arg INSTALL_OPTIONAL_DEPS=true -t deepfake-detector-api .
|
| 113 |
+
```
|
| 114 |
+
|
| 115 |
## Deploy to Hugging Face Spaces
|
| 116 |
|
| 117 |
Recommended path is the Bash deploy script.
|
requirements-optional.txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# DeepFake Detector Backend - Optional Dependencies
|
| 2 |
+
# Install these for local development/testing only.
|
| 3 |
+
|
| 4 |
+
# Testing
|
| 5 |
+
pytest>=7.4.0,<9.0.0
|
| 6 |
+
pytest-asyncio>=0.23.0,<1.0.0
|
requirements-runtime.txt
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# DeepFake Detector Backend - Runtime Dependencies (inference + API)
|
| 2 |
+
|
| 3 |
+
# Web framework
|
| 4 |
+
fastapi>=0.109.0,<1.0.0
|
| 5 |
+
uvicorn[standard]>=0.27.0,<1.0.0
|
| 6 |
+
|
| 7 |
+
# Data validation
|
| 8 |
+
pydantic>=2.5.0,<3.0.0
|
| 9 |
+
pydantic-settings>=2.1.0,<3.0.0
|
| 10 |
+
|
| 11 |
+
# Core image handling
|
| 12 |
+
pillow>=10.2.0,<11.0.0
|
| 13 |
+
matplotlib>=3.7.0,<4.0.0
|
| 14 |
+
|
| 15 |
+
# Deep Learning
|
| 16 |
+
torch>=2.0.0,<3.0.0
|
| 17 |
+
torchvision>=0.15.0,<1.0.0
|
| 18 |
+
timm>=0.9.0
|
| 19 |
+
|
| 20 |
+
# Machine Learning (for fusion models)
|
| 21 |
+
scikit-learn==1.6.1
|
| 22 |
+
numpy>=1.24.0,<2.0.0
|
| 23 |
+
|
| 24 |
+
# Hugging Face Hub
|
| 25 |
+
huggingface_hub>=0.20.0,<1.0.0
|
| 26 |
+
hf_xet
|
| 27 |
+
|
| 28 |
+
# Google Gemini for LLM explanations
|
| 29 |
+
google-genai>=1.0.0
|
| 30 |
+
|
| 31 |
+
# File uploads
|
| 32 |
+
python-multipart>=0.0.6,<1.0.0
|
requirements.txt
CHANGED
|
@@ -1,40 +1,4 @@
|
|
| 1 |
-
#
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
uvicorn[standard]>=0.27.0,<1.0.0
|
| 6 |
-
|
| 7 |
-
# Data validation
|
| 8 |
-
pydantic>=2.5.0,<3.0.0
|
| 9 |
-
pydantic-settings>=2.1.0,<3.0.0
|
| 10 |
-
|
| 11 |
-
# Image processing
|
| 12 |
-
pillow>=10.2.0,<11.0.0
|
| 13 |
-
matplotlib>=3.7.0,<4.0.0
|
| 14 |
-
opencv-python>=4.8.0,<5.0.0
|
| 15 |
-
|
| 16 |
-
# Deep Learning
|
| 17 |
-
torch>=2.0.0,<3.0.0
|
| 18 |
-
torchvision>=0.15.0,<1.0.0
|
| 19 |
-
timm>=0.9.0
|
| 20 |
-
|
| 21 |
-
# Machine Learning (for fusion models)
|
| 22 |
-
scikit-learn==1.6.1
|
| 23 |
-
numpy>=1.24.0,<2.0.0
|
| 24 |
-
|
| 25 |
-
# Hugging Face Hub
|
| 26 |
-
huggingface_hub>=0.20.0,<1.0.0
|
| 27 |
-
hf_xet
|
| 28 |
-
|
| 29 |
-
# HTTP client (optional, for testing)
|
| 30 |
-
httpx>=0.26.0,<1.0.0
|
| 31 |
-
|
| 32 |
-
# File uploads
|
| 33 |
-
python-multipart>=0.0.6,<1.0.0
|
| 34 |
-
|
| 35 |
-
# Testing
|
| 36 |
-
pytest>=7.4.0,<9.0.0
|
| 37 |
-
pytest-asyncio>=0.23.0,<1.0.0
|
| 38 |
-
|
| 39 |
-
# Google Gemini for LLM explanations
|
| 40 |
-
google-genai>=1.0.0
|
|
|
|
| 1 |
+
# Full dependency set for local development.
|
| 2 |
+
# Production images should install requirements-runtime.txt only.
|
| 3 |
+
-r requirements-runtime.txt
|
| 4 |
+
-r requirements-optional.txt
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|