Spaces:
Sleeping
Sleeping
| # 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"] | |