# Use lightweight Python base FROM python:3.10-slim # Set working directory WORKDIR /app # Copy files COPY . . # Install dependencies RUN pip install --no-cache-dir -r requirements.txt # Create cache directory and make it writable for non-root RUN mkdir -p /app/hf_cache && chmod -R 777 /app/hf_cache # Set environment variables for Hugging Face cache ENV HF_HOME=/app/hf_cache ENV TRANSFORMERS_CACHE=/app/hf_cache # Expose Space port EXPOSE 7860 # Switch to non-root user RUN useradd -m appuser USER appuser # Run Flask directly (no Gunicorn) CMD ["python", "api_inference.py"]