# Basketball Analysis API Backend - Hugging Face Deployment FROM python:3.10-slim # Set environment variables ENV PYTHONDONTWRITEBYTECODE=1 \ PYTHONUNBUFFERED=1 \ PYTHONPATH=/home/user/app \ PATH="/home/user/.local/bin:$PATH" \ PORT=7860 # Install system dependencies RUN apt-get update && apt-get install -y \ libgl1 \ libglib2.0-0 \ libsm6 \ libxext6 \ curl \ git \ ffmpeg \ && rm -rf /var/lib/apt/lists/* # Create a non-root user (Hugging Face requires UID 1000) RUN useradd -m -u 1000 user USER user WORKDIR /home/user/app # Install Python dependencies COPY --chown=user requirements.txt . RUN pip install --no-cache-dir --upgrade pip && \ pip install --no-cache-dir -r requirements.txt # Copy application code COPY --chown=user . . # Create necessary directories and set permissions RUN mkdir -p uploads models stubs output_videos/clips uploads/personal_output # Expose Hugging Face's default port EXPOSE 7860 # Health check HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \ CMD curl -f http://localhost:7860/api/health || exit 1 # Download models using HF_TOKEN at runtime, then start the API server CMD ["sh", "-c", "python download_models.py && uvicorn app.main:app --host 0.0.0.0 --port 7860"]