Spaces:
Runtime error
Runtime error
FROM python:3.10 | |
WORKDIR /app | |
# Create cache directories with proper permissions | |
RUN mkdir -p /app/.cache /app/.huggingface /app/.huggingface/.locks && \ | |
chmod -R 777 /app/.cache /app/.huggingface | |
# Set environment variables for cache directories | |
ENV HF_HOME=/app/.huggingface | |
ENV TRANSFORMERS_CACHE=/app/.huggingface | |
ENV HF_DATASETS_CACHE=/app/.huggingface | |
ENV TORCH_HOME=/app/.cache | |
ENV SENTENCE_TRANSFORMERS_HOME=/app/.huggingface | |
# Install system dependencies for building Python packages | |
RUN apt-get update && apt-get install -y \ | |
gcc \ | |
g++ \ | |
build-essential \ | |
&& rm -rf /var/lib/apt/lists/* | |
# Upgrade pip and install wheel to use pre-compiled packages when possible | |
RUN pip install --upgrade pip wheel | |
# Copy requirements and install dependencies | |
COPY requirements.txt . | |
# Install packages with timeout and prefer binary wheels | |
RUN pip install --no-cache-dir --timeout 300 --prefer-binary -r requirements.txt | |
# Copy application files first | |
COPY . . | |
# Create necessary directories | |
RUN mkdir -p templates static/css static/js | |
# Pre-download models during build to avoid runtime downloads | |
# This helps reduce startup time in HuggingFace Spaces | |
RUN python -c "from sentence_transformers import SentenceTransformer; SentenceTransformer('all-MiniLM-L6-v2')" || echo "Model download failed, will download at runtime" | |
# Ensure all cache directories have proper permissions after model downloads | |
RUN chmod -R 777 /app/.cache /app/.huggingface || true | |
# Expose port for HuggingFace Spaces (7860 is the standard) | |
EXPOSE 7860 | |
# Run the Flask app with host binding for HuggingFace Spaces | |
CMD ["python", "app.py"] | |