File size: 1,146 Bytes
20cbff3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
32
33
# HuggingFace Spaces runs containers as non-root user (uid=1000)
FROM python:3.11-slim

# Required by HuggingFace Spaces
RUN useradd -m -u 1000 user
USER user
ENV HOME=/home/user \
    PATH=/home/user/.local/bin:$PATH

WORKDIR $HOME/app

# Install CPU-only torch first (saves ~1.5GB vs CUDA build)
RUN pip install --no-cache-dir torch --index-url https://download.pytorch.org/whl/cpu

# Copy and install dependencies
COPY --chown=user requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# Copy source code
COPY --chown=user fraud_model.py .
COPY --chown=user main.py .

# Pre-download model at build time for fast startup
# HF_HOME points to a writable location for the non-root user
ENV HF_HOME=/home/user/.cache/huggingface
RUN python -c "from transformers import AutoTokenizer, AutoModelForSequenceClassification; \
    AutoTokenizer.from_pretrained('austinb/fraud_text_detection'); \
    AutoModelForSequenceClassification.from_pretrained('austinb/fraud_text_detection')"

# HuggingFace Spaces exposes port 7860
EXPOSE 7860

CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]