# Use an official Python image FROM python:3.10-slim # Set standard Python environment variables for containerized apps ENV PYTHONDONTWRITEBYTECODE=1 ENV PYTHONUNBUFFERED=1 # Set the working directory WORKDIR /api # --- Cache Configuration --- # Create a single, unified directory for all model caches. # Make it fully writable to prevent "Permission Denied" errors when downloading models. RUN mkdir -p /api/cache && chmod -R 777 /api/cache # Tell all relevant libraries (Hugging Face, SentenceTransformers, PyTorch) # to use this new writable directory. HF_HOME is the most important one. ENV HF_HOME=/api/cache ENV SENTENCE_TRANSFORMERS_HOME=/api/cache ENV TORCH_HOME=/api/cache # --- End Cache Configuration --- # Install dependencies # Copy only the requirements file first to leverage Docker layer caching COPY requirements.txt . RUN pip install --upgrade pip RUN pip install -r requirements.txt # Copy the rest of the application code into the container COPY . . # Expose the port the app runs on EXPOSE 7860 # Command to run the application CMD ["uvicorn", "api.main:app", "--host", "0.0.0.0", "--port", "7860"]