Spaces:
Sleeping
Sleeping
| # Use Python 3.12 | |
| FROM python:3.12 | |
| # Set the working directory (Created as root by default) | |
| WORKDIR /app | |
| # Create the user (ID 1000 is required for HF Spaces) | |
| RUN useradd -m -u 1000 user | |
| # Copy requirements and install (Run as root to install globally or easily) | |
| COPY requirements.txt . | |
| RUN pip install --no-cache-dir -r requirements.txt | |
| # --- CRITICAL FIX --- | |
| # Change ownership of the working directory to the user | |
| RUN chown user:user /app | |
| # -------------------- | |
| # Switch to the non-root user | |
| USER user | |
| ENV PATH="/home/user/.local/bin:$PATH" | |
| # Copy the rest of the application code with correct ownership | |
| COPY --chown=user . . | |
| # Run the setup script (Now has permission to write to /app/models) | |
| RUN python setup_models.py | |
| # Expose the port | |
| EXPOSE 7860 | |
| # Start the application | |
| CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"] |