# Use an official PyTorch image as a base FROM pytorch/pytorch:2.1.0-cuda11.8-cudnn8-runtime # Set the working directory inside the container WORKDIR /app # Install system dependencies RUN apt-get update && apt-get install -y \ build-essential \ && rm -rf /var/lib/apt/lists/* # Create a non-root user RUN useradd -m -u 1000 appuser # Create cache directories and set permissions RUN mkdir -p /.cache/huggingface && \ mkdir -p /.cache/torch && \ mkdir -p /.cache/sentence_transformers && \ chown -R appuser:appuser /.cache && \ chmod -R 777 /.cache # Set environment variables for cache locations ENV HF_HOME="/.cache/huggingface" ENV TORCH_HOME="/.cache/torch" ENV SENTENCE_TRANSFORMERS_HOME="/.cache/sentence_transformers" # Install Python dependencies RUN pip install --no-cache-dir \ pandas \ torch \ sentence-transformers \ transformers \ numpy \ faiss-cpu \ fastapi \ uvicorn[standard] \ pydantic \ python-multipart \ huggingface_hub \ accelerate>=0.26.0 # Copy the necessary files into the container COPY plant_data_chunks_and_embeddings.csv /app/plant_data_chunks_and_embeddings.csv COPY main.py /app/main.py # Set proper permissions for the app directory RUN chown -R appuser:appuser /app # Switch to non-root user USER appuser # Set the environment variable to point to the app directory ENV PYTHONPATH=/app # Expose the port the app will run on EXPOSE 5000 # Command to run the app using Uvicorn CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "5000"]