# Backend-only Dockerfile for Hugging Face Spaces FROM python:3.11-slim # Install system dependencies RUN apt-get update && apt-get install -y \ curl \ && rm -rf /var/lib/apt/lists/* WORKDIR /app # Set environment variables for Hugging Face cache ENV TRANSFORMERS_CACHE=/tmp/transformers_cache ENV HF_HOME=/tmp/hf_home ENV HUGGINGFACE_HUB_CACHE=/tmp/huggingface_hub # Create cache directories with proper permissions RUN mkdir -p /tmp/transformers_cache /tmp/hf_home /tmp/huggingface_hub && \ chmod -R 777 /tmp/transformers_cache /tmp/hf_home /tmp/huggingface_hub # Copy and install Python requirements COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt # Copy backend code COPY backend/ ./backend/ COPY app.py . # Create a simple health check endpoint HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ CMD curl -f http://localhost:7860/health || exit 1 # Expose the Hugging Face Spaces default port EXPOSE 7860 # Run the FastAPI app with Uvicorn CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]