# Use a lightweight Python image FROM python:3.9-slim # Set environment variables for cache directories ENV HF_HOME=/tmp/huggingface_cache ENV TRANSFORMERS_CACHE=/tmp/transformers_cache ENV HF_HUB_CACHE=/tmp/hf_hub_cache ENV SENTENCE_TRANSFORMERS_HOME=/tmp/sentence_transformers_cache ENV STREAMLIT_CONFIG_DIR=/tmp/.streamlit # Set the working directory in the container WORKDIR /app # Create cache directories and set permissions RUN mkdir -p /tmp/huggingface_cache /tmp/transformers_cache /tmp/hf_hub_cache /tmp/sentence_transformers_cache /tmp/.streamlit && \ chmod -R 777 /tmp # Copy the requirements file and install dependencies COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt # Copy the application files and the document COPY rag_components.py . COPY app.py . COPY me.txt . # Create a non-root user for better security in HF Spaces RUN useradd -m -u 1000 user RUN chown -R user:user /app /tmp USER user # Expose the port Streamlit runs on EXPOSE 8501 # Command to run the Streamlit application ENTRYPOINT ["streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0"]