FROM python:3.10-slim WORKDIR /app # Install required system dependencies RUN apt-get update && apt-get install -y \ build-essential \ git \ && rm -rf /var/lib/apt/lists/* # Copy requirements first for better caching COPY requirements.txt . # Install Python dependencies RUN pip install --no-cache-dir -r requirements.txt # Create all cache directories with proper permissions RUN mkdir -p /.cache && chmod 777 /.cache RUN mkdir -p /root/.cache && chmod 777 /root/.cache RUN mkdir -p /app/.cache && chmod 777 /app/.cache RUN mkdir -p /tmp/.cache && chmod 777 /tmp/.cache RUN mkdir -p /home/.cache && chmod 777 /home/.cache # Create models directory with proper permissions RUN mkdir -p /app/models && chmod 777 /app/models # Copy the rest of the application COPY . . # Create necessary directories with proper permissions and unique vector_db folders RUN mkdir -p data/documents && chmod -R 777 data/documents RUN mkdir -p data/vector_db && chmod -R 777 data/vector_db # Create multiple vector_db instances to avoid collisions RUN mkdir -p data/vector_db_1 data/vector_db_2 data/vector_db_3 && \ chmod -R 777 data/vector_db_* # Set environment variables for cache locations ENV TRANSFORMERS_CACHE=/app/models ENV TOKENIZERS_PARALLELISM=false ENV HF_HOME=/app/.cache ENV XDG_CACHE_HOME=/app/.cache ENV HUGGINGFACEHUB_API_TOKEN="" ENV HF_API_KEY="" # Use small local models that don't require API access # distilgpt2 is a small model that works well locally ENV LLM_MODEL="distilgpt2" # all-MiniLM-L6-v2 is small and efficient for embeddings ENV EMBEDDING_MODEL="sentence-transformers/all-MiniLM-L6-v2" # Set moderate temperature and token limit ENV DEFAULT_TEMPERATURE=0.7 ENV MAX_TOKENS=256 ENV CHUNK_SIZE=512 ENV CHUNK_OVERLAP=128 # Set server.maxMessageSize for Streamlit to handle large uploads ENV STREAMLIT_SERVER_MAX_MESSAGE_SIZE=200 # Set shared memory settings to improve performance ENV PYTHONHASHSEED=0 # Expose port for Hugging Face Spaces EXPOSE 7860 # Run the Streamlit app on the correct port CMD ["streamlit", "run", "app/ui/streamlit_app.py", "--server.port=7860", "--server.address=0.0.0.0", "--server.maxUploadSize=10"]