Spaces:
Sleeping
Sleeping
File size: 1,337 Bytes
6b6e223 677f286 6b6e223 dcd9854 6b6e223 677f286 6b6e223 677f286 6b6e223 677f286 c5fbcdb 54c9011 c5fbcdb 6b6e223 c5fbcdb 677f286 6b6e223 c5fbcdb 677f286 6b6e223 c5fbcdb | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | # 1. Use Python 3.11 (Matches your Mac version to prevent dependency errors)
FROM python:3.11-slim
# 2. Force Python to print logs immediately (Helps us debug if it crashes)
ENV PYTHONUNBUFFERED=1
# 2b. MEMORY FIX: Limit PyTorch threads to prevent memory bloat
ENV OMP_NUM_THREADS=1
ENV MKL_NUM_THREADS=1
ENV TORCH_NUM_THREADS=1
# 3. Set the working directory inside the container
WORKDIR /app
# 4. Copy requirements file first
COPY requirements.txt .
# 5. Install dependencies
# Added default-timeout to prevent "ReadTimeoutError" on slow connections
RUN pip install --default-timeout=1000 --no-cache-dir -r requirements.txt
# 5b. HF SPACES: Create a non-root user
RUN useradd -m -u 1000 user
RUN chown -R user:user /app
# 6. Copy the rest of your code
COPY --chown=user . .
# 7. Run the seed script to "bake" the AI models into the image
# We run as root first to ensure permissions, or we can run as user if pip installed locally.
# However, usually pip installs are global here. Let's switch to user.
USER user
# Pre-load/Seed models (as user 1000 to avoid permission issues)
RUN python seed_references.py
# 8. Start the app (The Critical Fix)
# We use "sh -c" so we can read the ${PORT} variable from Render/HF.
# Spaces uses 7860 by default.
ENV PORT=7860
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"] |