FROM python:3.9-slim # Set working directory RUN useradd -m -u 1000 user WORKDIR /app # Set environment variables for optimization ENV PYTHONUNBUFFERED=1 ENV PYTHONDONTWRITEBYTECODE=1 ENV TOKENIZERS_PARALLELISM=false ENV HF_HUB_DISABLE_SYMLINKS_WARNING=1 ENV HF_HOME=/data/.huggingface RUN mkdir -p /data/chroma_db && chown -R user:user /data/chroma_db # Set environment variables for persistent mode ENV PERSISTENT_MODE=true ENV CHROMA_PERSIST_DIR=/data/chroma_db ENV CHROMA_COLLECTION_NAME=creative_jobs_rag RUN apt-get update && apt-get install -y \ build-essential \ curl \ git \ && rm -rf /var/lib/apt/lists/* # Copy requirements first for better caching COPY --chown=user requirements.txt . # Install Python dependencies RUN pip install --no-cache-dir -r requirements.txt # Download NLTK data during build RUN python -c "import nltk; \ nltk.download('punkt', quiet=True); \ nltk.download('punkt_tab', quiet=True); \ nltk.download('wordnet', quiet=True); \ nltk.download('omw-1.4', quiet=True); \ nltk.download('stopwords', quiet=True); \ nltk.download('averaged_perceptron_tagger', quiet=True); \ nltk.download('maxent_ne_chunker', quiet=True); \ nltk.download('words', quiet=True);" || true # Pre-download SentenceTransformer model to avoid meta tensor issues RUN python -c "from sentence_transformers import SentenceTransformer; \ import torch; \ torch.set_num_threads(1); \ model = SentenceTransformer('all-MiniLM-L6-v2', device='cpu'); \ model.encode(['test'], show_progress_bar=False);" || true # Copy application code COPY --chown=user . . # Create necessary directories RUN mkdir -p /app/temp /app/cache # Expose port EXPOSE 8501 # Health check HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health # Run the application ENTRYPOINT ["streamlit", "run", "streamlit_app.py", "--server.port=8501", "--server.address=0.0.0.0"]