File size: 1,698 Bytes
f234112
160ca5d
f234112
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
160ca5d
f234112
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
160ca5d
f234112
 
32b6488
 
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
52
53
54
# =======================================================================
# AI-TRAFFIC-ADAPTION Docker image for Hugging Face Spaces and AWS ECS
# =======================================================================

FROM python:3.11-slim

# Prevent Python from writing .pyc files and buffer stdout/stderr
ENV PYTHONDONTWRITEBYTECODE=1 \
    PYTHONUNBUFFERED=1 \
    PORT=7860 \
    DEBIAN_FRONTEND=noninteractive

# Install essential system libraries for OpenCV, Video I/O, and PyTorch
RUN apt-get update && apt-get install -y --no-install-recommends \
    ffmpeg \
    libgl1 \
    libglib2.0-0 \
    libsm6 \
    libxext6 \
    libxrender-dev \
    curl \
    && rm -rf /var/lib/apt/lists/*

# Run the application as a non-root user
RUN useradd -m -u 1000 user
ENV HOME=/home/user \
    PATH=/home/user/.local/bin:$PATH

WORKDIR $HOME/app

# Pre-install CPU PyTorch wheels for fast, lightweight build
RUN pip install --no-cache-dir --upgrade pip && \
    pip install --no-cache-dir torch torchvision --index-url https://download.pytorch.org/whl/cpu

# Install application dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# Copy application source code, pre-built frontend, models, and configurations
COPY --chown=user:user . .

# Ensure directory permissions for runtime uploads and output generation
RUN mkdir -p data/uploads outputs/videos state && \
    chown -R user:user $HOME/app

# Switch to non-root user
USER user

# Container port used by Hugging Face Spaces and the AWS ECS Express service
EXPOSE 7860

# Launch the FastAPI dashboard with REST API, WebSockets, and React SPA
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]