participatory-planner / Dockerfile.hf
thadillo
Fix: Model cache permissions for Hugging Face Spaces
d6a961e
# Hugging Face Spaces Dockerfile
FROM python:3.11-slim
# Set working directory
WORKDIR /app
# Install system dependencies
RUN apt-get update && apt-get install -y \
build-essential \
curl \
&& rm -rf /var/lib/apt/lists/*
# Copy requirements
COPY requirements.txt .
# Install Python dependencies
RUN pip install --no-cache-dir -r requirements.txt
# Copy application code
COPY . .
# Create data directory in a writable location for HF Spaces
# HF Spaces has persistent storage at /data
RUN mkdir -p /data && chmod 777 /data
# Create cache directory for Hugging Face models
RUN mkdir -p /data/.cache/huggingface && chmod -R 777 /data/.cache
# Hugging Face Spaces uses port 7860
EXPOSE 7860
# Set environment variables
ENV FLASK_ENV=production
ENV PYTHONUNBUFFERED=1
ENV PORT=7860
ENV DATABASE_PATH=/data/app.db
ENV HF_HOME=/data/.cache/huggingface
ENV TRANSFORMERS_CACHE=/data/.cache/huggingface
ENV HUGGINGFACE_HUB_CACHE=/data/.cache/huggingface
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
CMD curl -f http://localhost:7860/login || exit 1
# Run the application
CMD ["python", "app_hf.py"]