File size: 1,027 Bytes
e630855
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
FROM python:3.11-slim

ENV PYTHONUNBUFFERED=1 \
    PIP_NO_CACHE_DIR=1 \
    HF_HOME=/app/.cache/huggingface \
    UPLOAD_DIR=/tmp/uploads \
    PORT=7860

WORKDIR /app

# System libs needed by soundfile / librosa for audio decoding.
RUN apt-get update && apt-get install -y --no-install-recommends \
    libsndfile1 ffmpeg \
    && rm -rf /var/lib/apt/lists/*

COPY requirements.txt .
RUN pip install -r requirements.txt

COPY backend ./backend
COPY frontend ./frontend

# Pre-download the gender model so the first request isn't slow.
RUN python -c "from transformers import Wav2Vec2ForSequenceClassification, Wav2Vec2FeatureExtractor as F; M='prithivMLmods/Common-Voice-Gender-Detection'; Wav2Vec2ForSequenceClassification.from_pretrained(M); F.from_pretrained(M)"

# Make caches/uploads writable for non-root hosts (e.g. HF Spaces runs as uid 1000).
RUN mkdir -p /tmp/uploads "$HF_HOME" && chmod -R 777 /app/.cache /tmp/uploads

EXPOSE 7860

CMD ["sh", "-c", "uvicorn backend.main:app --host 0.0.0.0 --port ${PORT:-7860}"]