Spaces:
Running
Running
Update Dockerfile
Browse files- Dockerfile +47 -45
Dockerfile
CHANGED
|
@@ -1,45 +1,47 @@
|
|
| 1 |
-
FROM python:3.10-slim
|
| 2 |
-
|
| 3 |
-
#
|
| 4 |
-
RUN
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
COPY --chown=user
|
| 23 |
-
|
| 24 |
-
#
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
#
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.10-slim
|
| 2 |
+
|
| 3 |
+
# 1. Install system dependencies (FFmpeg is required for audio)
|
| 4 |
+
RUN apt-get update && \
|
| 5 |
+
apt-get install -y ffmpeg git && \
|
| 6 |
+
rm -rf /var/lib/apt/lists/*
|
| 7 |
+
|
| 8 |
+
# 2. Setup a non-root user (Required for Hugging Face Spaces permissions)
|
| 9 |
+
RUN useradd -m -u 1000 user
|
| 10 |
+
WORKDIR /app
|
| 11 |
+
RUN chown user:user /app
|
| 12 |
+
|
| 13 |
+
# 3. Switch to user
|
| 14 |
+
USER user
|
| 15 |
+
ENV PATH="/home/user/.local/bin:$PATH" \
|
| 16 |
+
PYTHONUNBUFFERED=1 \
|
| 17 |
+
PYTHONDONTWRITEBYTECODE=1 \
|
| 18 |
+
TRANSFORMERS_CACHE=/app/cache \
|
| 19 |
+
HF_HOME=/app/cache
|
| 20 |
+
|
| 21 |
+
# 4. Install Python dependencies
|
| 22 |
+
COPY --chown=user:user requirements.txt .
|
| 23 |
+
|
| 24 |
+
# Install Torch CPU (saves space) - Critical for free tier
|
| 25 |
+
RUN pip install --no-cache-dir --user torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
|
| 26 |
+
|
| 27 |
+
# Install other requirements (Flask, Librosa, Gunicorn)
|
| 28 |
+
RUN pip install --no-cache-dir --user -r requirements.txt
|
| 29 |
+
|
| 30 |
+
# 5. Copy application code
|
| 31 |
+
COPY --chown=user:user . .
|
| 32 |
+
|
| 33 |
+
# 6. Pre-download models (Optional but speeds up first boot)
|
| 34 |
+
# We do this AFTER installing requirements so libs are available
|
| 35 |
+
RUN python -c "from transformers import AutoModelForAudioClassification, AutoFeatureExtractor, WhisperProcessor, WhisperForConditionalGeneration; \
|
| 36 |
+
print('Downloading models...'); \
|
| 37 |
+
AutoModelForAudioClassification.from_pretrained('garystafford/wav2vec2-deepfake-voice-detector'); \
|
| 38 |
+
AutoFeatureExtractor.from_pretrained('garystafford/wav2vec2-deepfake-voice-detector'); \
|
| 39 |
+
WhisperProcessor.from_pretrained('openai/whisper-base'); \
|
| 40 |
+
WhisperForConditionalGeneration.from_pretrained('openai/whisper-base'); \
|
| 41 |
+
print('Models downloaded successfully')"
|
| 42 |
+
|
| 43 |
+
# 7. Expose the Hugging Face port
|
| 44 |
+
EXPOSE 7860
|
| 45 |
+
|
| 46 |
+
# 8. THE CRITICAL FIX: Use Gunicorn for Flask (Not Uvicorn)
|
| 47 |
+
CMD ["python", "-m", "gunicorn", "-b", "0.0.0.0:7860", "app:app", "--workers", "2", "--timeout", "120"]
|