File size: 1,434 Bytes
d229a19
755842e
ab4421a
d229a19
6458940
c700bd5
d229a19
 
 
 
 
 
6458940
 
d229a19
ad94d02
 
 
d229a19
 
7b879b9
d229a19
 
ad94d02
d229a19
7b879b9
c8f8ff0
d229a19
 
b87e018
d229a19
b87e018
3fee54e
b87e018
d229a19
 
af95e31
d229a19
c700bd5
4448c19
d229a19
 
 
 
8fc2ed8
d229a19
 
 
56c49c7
d229a19
b5868b6
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
47
48
49
50
51
# Use PyTorch with CUDA 12.1 for L4 GPU compatibility
FROM pytorch/pytorch:2.2.2-cuda12.1-cudnn8-runtime

# Install system dependencies
RUN apt-get update && \
    apt-get install -y --no-install-recommends \
        git \
        git-lfs \
        build-essential \
        ffmpeg \
        curl \
        wget && \
    rm -rf /var/lib/apt/lists/*

# Create non-root user for Hugging Face Spaces
RUN useradd -m -u 1000 user
USER user
WORKDIR /app

# Set environment variables
ENV PATH="/home/user/.local/bin:$PATH"
ENV HF_HOME=/app/.cache
ENV PYTHONPATH="/app:$PYTHONPATH"

# Copy application files
COPY --chown=user . /app

# Upgrade pip and install Python dependencies
RUN pip install --upgrade pip

# Install requirements
COPY --chown=user requirements.txt .
RUN pip install -r requirements.txt # --no-cache-dir 

# Install additional optimizations for L4 GPU
RUN pip install --no-cache-dir flash-attn --no-build-isolation || echo "Flash attention not available, continuing..."

# Expose port for Hugging Face Spaces
EXPOSE 7860

# Environment variables for the application
ENV PYTHONUNBUFFERED=1
ENV UVICORN_HOST=0.0.0.0
ENV UVICORN_PORT=7860

# Health check using FastAPI health endpoint
HEALTHCHECK --interval=30s --timeout=30s --start-period=60s --retries=3 \
    CMD curl -f http://localhost:7860/health || exit 1

# Start the FastAPI application with uvicorn
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]