File size: 2,267 Bytes
7f40db3
08f8699
7f40db3
 
 
 
08f8699
7f40db3
 
 
08f8699
 
 
 
 
dd80b32
08f8699
 
 
dd80b32
7f40db3
08f8699
dd80b32
 
 
08f8699
 
 
7f40db3
08f8699
27caebd
08f8699
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d2b2154
 
7f40db3
d2b2154
08f8699
 
 
 
27caebd
 
 
d2b2154
08f8699
 
7f40db3
08f8699
 
 
dd80b32
d2b2154
 
7f40db3
 
27caebd
d2b2154
08f8699
 
 
27caebd
08f8699
 
27caebd
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
77
78
79
# PhysiX-Live demo Space — CPU-only env + UI on :7860
#
#   uvicorn _space_app:app
#     ├─ /reset, /step      OpenEnv stateless API
#     ├─ /interactive/*     browser session API + LLM-step
#     └─ /web/              built React SPA
#
# No torch / vLLM / GPU here. LLM inference is forwarded to whatever
# OpenAI-compatible base URL the browser provides (HF Router, OpenAI,
# Ollama, or our sister L4 Space `Pratyush-01/physix-infer`).

############################
# Stage 1: build the SPA
############################
FROM node:20-alpine AS frontend
WORKDIR /spa
RUN corepack enable

COPY frontend/ ./

# Same-origin API fetches at runtime (Space serves both API and UI).
ENV VITE_PHYSIX_API_URL=""

RUN pnpm install --frozen-lockfile \
    && pnpm exec tsc -b \
    && pnpm exec vite build --base=/web/

############################
# Stage 2: runtime
############################
FROM python:3.11-slim AS runtime

ENV PYTHONUNBUFFERED=1 \
    PIP_NO_CACHE_DIR=1 \
    PIP_DISABLE_PIP_VERSION_CHECK=1 \
    HOME=/tmp/home \
    HF_HOME=/tmp/hf_cache \
    XDG_CACHE_HOME=/tmp/xdg-cache \
    PORT=7860 \
    PHYSIX_HOST=0.0.0.0 \
    PHYSIX_CORS_ORIGINS=*

RUN apt-get update \
    && apt-get install -y --no-install-recommends curl \
    && rm -rf /var/lib/apt/lists/*

WORKDIR /app

# Inference deps only — no torch / unsloth / trl. Training runs on HF Jobs.
RUN pip install \
        "openenv-core[core]>=0.2.2" \
        "numpy>=1.24" \
        "scipy>=1.10" \
        "sympy>=1.12" \
        "fastapi>=0.110" \
        "uvicorn[standard]>=0.29" \
        "pydantic>=2.5" \
        "openai>=1.40" \
        "requests>=2.31"

COPY pyproject.toml README.md ./
COPY physix ./physix
RUN pip install --no-deps -e .

COPY --from=frontend /spa/dist /app/static
COPY scripts/space_app.py /app/_space_app.py

# HF Spaces runs as a non-root UID with no /etc/passwd; pre-create
# writable cache dirs so $HOME-based caches work.
RUN mkdir -p "$HOME" "$HF_HOME" "$XDG_CACHE_HOME" \
    && chmod -R 0777 /tmp /app

EXPOSE 7860

HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \
    CMD curl -fsS "http://127.0.0.1:${PORT}/health" || exit 1

CMD ["python3", "-m", "uvicorn", "_space_app:app", "--host", "0.0.0.0", "--port", "7860"]