FROM python:3.11-slim WORKDIR /app # Send caches to /data (persistent & writable on Spaces) ENV XDG_CACHE_HOME=/data/.cache ENV HF_HOME=/data/.cache/huggingface ENV HUGGINGFACE_HUB_CACHE=/data/.cache/huggingface ENV TRANSFORMERS_CACHE=/data/.cache/huggingface/transformers ENV STREAMLIT_BROWSER_GATHERUSAGESTATS=false # Optional: if you want to *disable* Torch Inductor JIT (no C++ compile at runtime) # ENV TORCHINDUCTOR_DISABLE=1 COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt COPY src/ ./src/ # Run as non-root USER user # Port & healthcheck expected by the Space EXPOSE 8501 HEALTHCHECK CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8501/_stcore/health')" || exit 1 # Launch Streamlit CMD ["streamlit", "run", "src/streamlit_app.py", "--server.port=8501", "--server.address=0.0.0.0"] FROM python:3.11-slim ENV PYTHONDONTWRITEBYTECODE=1 ENV PYTHONUNBUFFERED=1 ENV HOME=/home/user # Install git so pip can install from GitHub (transformers fork) RUN apt-get update \ && apt-get install -y --no-install-recommends git \ && rm -rf /var/lib/apt/lists/* # Create non-root user and writable dirs (avoid /.streamlit, /.cache perms) RUN useradd -m -u 1000 user \ && mkdir -p /data ${HOME}/.streamlit \ && chown -R user:user /data ${HOME} WORKDIR /app # Send caches to /data (persistent & writable on Spaces) ENV XDG_CACHE_HOME=/data/.cache ENV HF_HOME=/data/.cache/huggingface ENV HUGGINGFACE_HUB_CACHE=/data/.cache/huggingface ENV TRANSFORMERS_CACHE=/data/.cache/huggingface/transformers ENV STREAMLIT_BROWSER_GATHERUSAGESTATS=false COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt COPY src/ ./src/ # Run as non-root USER user # Port & healthcheck expected by the Space EXPOSE 8501 HEALTHCHECK CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8501/_stcore/health')" || exit 1 # Launch Streamlit CMD ["streamlit", "run", "src/streamlit_app.py", "--server.port=8501", "--server.address=0.0.0.0"]