# 1. Use a lightweight Python version FROM python:3.9-slim # 2. Set the working directory inside the container WORKDIR /app # 3. Copy requirements and install them COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt # 4. Pre-download the Fashion-CLIP model during the build process # (This prevents the app from timing out when it first starts up) RUN python -c "from transformers import CLIPModel, CLIPProcessor; \ model = CLIPModel.from_pretrained('patrickjohncyh/fashion-clip'); \ processor = CLIPProcessor.from_pretrained('patrickjohncyh/fashion-clip'); \ print('Fashion-CLIP model preloaded!')" # 5. Copy the rest of the application code COPY . . # 6. Create a user to run the app (Security best practice for HF Spaces) RUN useradd -m -u 1000 user USER user ENV HOME=/home/user \ PATH=/home/user/.local/bin:$PATH # 7. Start the application CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]