File size: 1,103 Bytes
50f0958
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
34
35
36
37
38
39
40
41
# Hugging Face Spaces Dockerfile for SafeSpace FastAPI Backend
FROM python:3.11-slim

# Set environment variables for HF Spaces
ENV PYTHONDONTWRITEBYTECODE=1 \
    PYTHONUNBUFFERED=1 \
    PYTHONPATH=/app

# Install system dependencies (minimal for HF Spaces)
RUN apt-get update && apt-get install -y \

    gcc \
    g++ \
    curl \
    wget \
    && rm -rf /var/lib/apt/lists/*

# Set work directory
WORKDIR /app

# Copy requirements first (for better Docker layer caching)
COPY requirements.txt .

# Install Python dependencies
RUN pip install --no-cache-dir --upgrade pip && \

    pip install --no-cache-dir -r requirements.txt

# Copy application code
COPY . .

# Create models directory
RUN mkdir -p /app/models

# Download models if needed (uncomment and modify as needed)
# RUN python -c "import gdown; gdown.download('your-google-drive-link', 'models/model.pkl')"

# Expose port (HF Spaces uses port 7860 by default)
EXPOSE 7860

# HF Spaces command - single worker for free tier
CMD ["uvicorn", "server.main:app", "--host", "0.0.0.0", "--port", "7860"]