Spaces:
Running
Running
| # Use official Python runtime as a parent image | |
| FROM python:3.9-slim | |
| # Create user with ID 1000 (Hugging Face requirement) | |
| RUN useradd -m -u 1000 user | |
| # Set environment variables for writable directories | |
| ENV HOME=/home/user \ | |
| PATH="/home/user/.local/bin:$PATH" \ | |
| HF_HOME=/home/user/.cache/huggingface \ | |
| TORCH_HOME=/home/user/.cache/torch \ | |
| PYTHONUNBUFFERED=1 | |
| WORKDIR /app | |
| # Switch to root to install system deps | |
| USER root | |
| RUN apt-get update && apt-get install -y \ | |
| build-essential \ | |
| libgl1 \ | |
| libglib2.0-0 \ | |
| git \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # Create cache directories and ensure permissions | |
| RUN mkdir -p $HF_HOME && mkdir -p $TORCH_HOME && \ | |
| chown -R user:user /home/user | |
| USER user | |
| # Copy requirements first | |
| COPY --chown=user ./requirements.txt requirements.txt | |
| # Install Python dependencies | |
| RUN pip install --no-cache-dir --upgrade -r requirements.txt | |
| # Copy the rest of the application | |
| COPY --chown=user . . | |
| # Expose port 7860 | |
| EXPOSE 7860 | |
| # Run the application | |
| CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"] | |