arshan123 commited on
Commit
e01a98f
·
verified ·
1 Parent(s): d7412ad

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +47 -45
Dockerfile CHANGED
@@ -1,45 +1,47 @@
1
- FROM python:3.10-slim
2
-
3
- # Set up a new user named "user" with user ID 1000 (required by HuggingFace Spaces)
4
- RUN useradd -m -u 1000 user
5
-
6
- # Set working directory
7
- WORKDIR /app
8
-
9
- # System dependencies for audio processing
10
- RUN apt-get update && apt-get install -y \
11
- libsndfile1 \
12
- ffmpeg \
13
- && rm -rf /var/lib/apt/lists/*
14
-
15
- # Copy requirements and install as root
16
- COPY --chown=user requirements.txt /app/requirements.txt
17
- RUN pip install --no-cache-dir --upgrade pip && \
18
- pip install --no-cache-dir -r requirements.txt
19
-
20
- # Copy application files with correct ownership
21
- COPY --chown=user app.py /app/
22
- COPY --chown=user detector.py /app/
23
-
24
- # Switch to the "user" user
25
- USER user
26
-
27
- # Set home to the user's home directory
28
- ENV HOME=/home/user \
29
- PATH=/home/user/.local/bin:$PATH \
30
- PYTHONUNBUFFERED=1
31
-
32
- # Pre-download models (will be cached in user's home)
33
- RUN python -c "from transformers import AutoModelForAudioClassification, AutoFeatureExtractor, WhisperProcessor, WhisperForConditionalGeneration; \
34
- print('Downloading models...'); \
35
- AutoModelForAudioClassification.from_pretrained('garystafford/wav2vec2-deepfake-voice-detector'); \
36
- AutoFeatureExtractor.from_pretrained('garystafford/wav2vec2-deepfake-voice-detector'); \
37
- WhisperProcessor.from_pretrained('openai/whisper-base'); \
38
- WhisperForConditionalGeneration.from_pretrained('openai/whisper-base'); \
39
- print('Models downloaded successfully')"
40
-
41
- # Expose HuggingFace Spaces port
42
- EXPOSE 7860
43
-
44
- # Run with uvicorn (FastAPI)
45
- CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
 
 
 
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"]