Spaces:
Sleeping
Sleeping
FROM python:3.11-slim | |
WORKDIR /app | |
ENV PYTHONDONTWRITEBYTECODE=1 | |
ENV PYTHONUNBUFFERED=1 | |
ENV DOCKER_ENV=true | |
# Install system dependencies | |
RUN apt-get update && apt-get install -y \ | |
build-essential \ | |
curl \ | |
&& rm -rf /var/lib/apt/lists/* | |
# Copy requirements and install | |
COPY requirements.txt . | |
RUN pip install --no-cache-dir --upgrade pip && \ | |
pip install --no-cache-dir -r requirements.txt | |
# Pre-download embedding models with correct names | |
RUN python -c "from sentence_transformers import SentenceTransformer; SentenceTransformer('all-MiniLM-L6-v2')" || echo "Failed to download all-MiniLM-L6-v2" | |
RUN python -c "from sentence_transformers import SentenceTransformer; SentenceTransformer('all-mpnet-base-v2')" || echo "Failed to download all-mpnet-base-v2" | |
# Create writable directories in /tmp | |
RUN mkdir -p /tmp/researchmate/data \ | |
/tmp/researchmate/logs \ | |
/tmp/researchmate/chroma_persist \ | |
/tmp/researchmate/uploads \ | |
/tmp/researchmate/chroma_db \ | |
/tmp/researchmate/config \ | |
/tmp/researchmate/tmp && \ | |
chmod -R 777 /tmp/researchmate | |
# Set environment variables for writable paths | |
ENV DATA_DIR=/tmp/researchmate/data | |
ENV LOGS_DIR=/tmp/researchmate/logs | |
ENV CHROMA_DIR=/tmp/researchmate/chroma_persist | |
ENV UPLOADS_DIR=/tmp/researchmate/uploads | |
ENV CHROMA_DB_DIR=/tmp/researchmate/chroma_db | |
# Set all cache directories to writable locations | |
ENV MPLCONFIGDIR=/tmp/matplotlib | |
ENV TRANSFORMERS_CACHE=/tmp/transformers | |
ENV HF_HOME=/tmp/huggingface | |
ENV SENTENCE_TRANSFORMERS_HOME=/tmp/sentence_transformers | |
ENV HF_DATASETS_CACHE=/tmp/datasets | |
ENV HUGGINGFACE_HUB_CACHE=/tmp/huggingface_hub | |
ENV XDG_CACHE_HOME=/tmp/cache | |
RUN mkdir -p /tmp/matplotlib \ | |
/tmp/transformers \ | |
/tmp/huggingface \ | |
/tmp/sentence_transformers \ | |
/tmp/datasets \ | |
/tmp/huggingface_hub \ | |
/tmp/cache && \ | |
chmod -R 777 /tmp/matplotlib \ | |
/tmp/transformers \ | |
/tmp/huggingface \ | |
/tmp/sentence_transformers \ | |
/tmp/datasets \ | |
/tmp/huggingface_hub \ | |
/tmp/cache | |
# Copy application code | |
COPY . . | |
# Spaces uses port 7860 | |
EXPOSE 7860 | |
# Health check | |
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \ | |
CMD curl -f http://localhost:7860/health || exit 1 | |
# Start the application | |
CMD ["python", "main.py"] |