File size: 1,290 Bytes
c6abe34
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9f19a74
 
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
42
43
44
45
46
# 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"]