File size: 3,373 Bytes
b6f80c5
 
 
 
 
fe6e5bc
b6f80c5
 
 
 
fe6e5bc
 
 
 
 
 
 
 
b6f80c5
fe6e5bc
 
 
 
b6f80c5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fe6e5bc
 
 
 
 
 
 
0a56fb7
 
 
fe6e5bc
b6f80c5
650568a
 
 
b6f80c5
 
 
 
 
 
 
fe6e5bc
b6f80c5
 
 
fe6e5bc
b6f80c5
c031c5d
 
b6f80c5
 
 
 
 
c031c5d
 
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
FROM python:3.11-slim

LABEL maintainer="OpenEnv Hackathon"
LABEL description="Autonomous Traffic Control – OpenEnv Environment (self-contained)"

# ── Install system deps (as root) ──────────────────────────────────────────
RUN apt-get update && apt-get install -y --no-install-recommends \

        build-essential \
    && rm -rf /var/lib/apt/lists/*

# ── Create user for Hugging Face Spaces (UID 1000) ─────────────────────────
RUN useradd -m -u 1000 user
USER user
ENV HOME=/home/user \
    PATH=/home/user/.local/bin:$PATH

WORKDIR $HOME/app

# ── Copy packaging manifest first (layer-cache friendly) ──────────────────
COPY --chown=user pyproject.toml README.md ./

# Fix the setuptools package lookup to not scan the root filesystem in Docker
RUN sed -i 's|where = \[".."\]|where = \["."\]|g' pyproject.toml || true

# ── Install Python deps ────────────────────────────────────────────────────
RUN pip install --no-cache-dir \

    "openenv-core[core]>=0.2.2" \
    "openai>=1.0.0" \
    "gradio>=4.0.0" \
    "numpy>=1.24.0" \
    "python-dotenv>=1.0.0" \
    "fastapi>=0.104.0" \
    "uvicorn[standard]>=0.24.0" \
    "pydantic>=2.5.0" \
    "requests>=2.31.0" \
    "python-multipart>=0.0.6"

# ── Copy source (self-contained; no root-level deps needed) ───────────────
COPY --chown=user models.py ./traffic_control/models.py
COPY --chown=user environment.py ./traffic_control/environment.py
COPY --chown=user tasks.py ./traffic_control/tasks.py
COPY --chown=user client.py ./traffic_control/client.py
COPY --chown=user __init__.py ./traffic_control/__init__.py
COPY --chown=user inference.py ./traffic_control/inference.py
COPY --chown=user openenv.yaml ./traffic_control/openenv.yaml
COPY --chown=user dashboard.py ./traffic_control/dashboard.py
COPY --chown=user analytics.py ./traffic_control/analytics.py
COPY --chown=user arena.py ./traffic_control/arena.py
COPY --chown=user server/ ./traffic_control/server/

# inference.py must also be at the container root (validator requirement)
COPY --chown=user inference.py ./inference.py

# ── Create package anchor so Python treats traffic_control/ as the package ─
RUN echo "" > ./traffic_control/__init__.py || true

# ── Install the package in editable mode ──────────────────────────────────
RUN pip install --no-cache-dir -e .

# ── Runtime config ────────────────────────────────────────────────────────
ENV PORT=7860
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1

EXPOSE 7860

# Single worker is required: Gradio's mount_gradio_app is not fork-safe.
# HF Spaces expects a single healthy process on port 7860.
ENV ENABLE_WEB_INTERFACE=true
CMD ["sh", "-c", \

     "uvicorn traffic_control.server.app:app \

      --host 0.0.0.0 \

      --port ${PORT} \

      --workers 1 \

      --timeout-keep-alive 75"]