Spaces:
Sleeping
Sleeping
Update Dockerfile
Browse files- Dockerfile +49 -36
Dockerfile
CHANGED
|
@@ -1,47 +1,60 @@
|
|
| 1 |
-
# Dockerfile
|
| 2 |
-
FROM python:3.
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
STREAMLIT_SERVER_RUN_ON_SAVE=false \
|
| 8 |
-
STREAMLIT_SERVER_ENABLECORS=false \
|
| 9 |
-
STREAMLIT_SERVER_PORT=8501 \
|
| 10 |
-
STREAMLIT_SERVER_ADDRESS=0.0.0.0
|
| 11 |
|
|
|
|
| 12 |
WORKDIR /app
|
| 13 |
|
| 14 |
-
#
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
libopenblas-dev \
|
| 18 |
-
ca-certificates \
|
| 19 |
-
&& rm -rf /var/lib/apt/lists/*
|
| 20 |
-
|
| 21 |
-
# Copy project files into image
|
| 22 |
-
COPY . /app
|
| 23 |
|
| 24 |
-
#
|
| 25 |
-
|
| 26 |
-
RUN mkdir -p /tmp/model && \
|
| 27 |
-
cp /app/best_overall_XGBoost.joblib /tmp/model/best_overall_XGBoost.joblib 2>/dev/null || true && \
|
| 28 |
-
chown -R 1000:1000 /tmp/model && \
|
| 29 |
-
chmod -R a+rwx /tmp/model
|
| 30 |
|
| 31 |
-
#
|
| 32 |
-
RUN
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
-
|
| 36 |
-
RUN
|
| 37 |
-
USER user
|
| 38 |
-
ENV HOME=/home/user PATH=/home/user/.local/bin:$PATH
|
| 39 |
|
| 40 |
-
#
|
| 41 |
-
|
| 42 |
-
RUN cp -r /app/* $HOME/app/ || true
|
| 43 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
EXPOSE 8501
|
| 45 |
|
| 46 |
-
#
|
| 47 |
-
CMD ["streamlit", "run", "app.py", "--server.port=8501", "--server.
|
|
|
|
| 1 |
+
# Dockerfile
|
| 2 |
+
FROM python:3.10-slim
|
| 3 |
|
| 4 |
+
# Set non-root user if you want (optional)
|
| 5 |
+
# RUN adduser --disabled-password appuser
|
| 6 |
+
# USER appuser
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
+
ENV DEBIAN_FRONTEND=noninteractive
|
| 9 |
WORKDIR /app
|
| 10 |
|
| 11 |
+
# Build args for secret/token usage at build time (if you provide it)
|
| 12 |
+
ARG HF_TOKEN
|
| 13 |
+
ENV HF_TOKEN=${HF_TOKEN}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
+
# Copy requirements first for better caching
|
| 16 |
+
COPY requirements.txt /app/requirements.txt
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
+
# Install system deps and python deps
|
| 19 |
+
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 20 |
+
build-essential \
|
| 21 |
+
ca-certificates \
|
| 22 |
+
git \
|
| 23 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 24 |
|
| 25 |
+
RUN pip install --upgrade pip
|
| 26 |
+
RUN pip install -r /app/requirements.txt
|
|
|
|
|
|
|
| 27 |
|
| 28 |
+
# Copy app source
|
| 29 |
+
COPY . /app
|
|
|
|
| 30 |
|
| 31 |
+
# Pre-download model during build (if HF_TOKEN / repo available)
|
| 32 |
+
# This will try to download the model and save it to the HF cache; it will also
|
| 33 |
+
# leave a copy in the default cache path which is fine for runtime.
|
| 34 |
+
RUN python - <<'PY'
|
| 35 |
+
import os, sys
|
| 36 |
+
from huggingface_hub import hf_hub_download
|
| 37 |
+
repo = os.getenv("HF_MODEL_REPO", "sathishaiuse/wellness-classifier-model")
|
| 38 |
+
fname = os.getenv("HF_MODEL_FILENAME", "best_overall_XGBoost.joblib")
|
| 39 |
+
token = os.getenv("HF_TOKEN") or None
|
| 40 |
+
try:
|
| 41 |
+
print("Attempting to pre-download model:", repo, fname, "token_present=", bool(token))
|
| 42 |
+
path = hf_hub_download(repo_id=repo, filename=fname, token=token)
|
| 43 |
+
print("Model downloaded to:", path)
|
| 44 |
+
# Also copy to /app for easier direct loading if desired
|
| 45 |
+
import shutil
|
| 46 |
+
dest = os.path.join("/app", os.path.basename(path))
|
| 47 |
+
try:
|
| 48 |
+
shutil.copy(path, dest)
|
| 49 |
+
print("Copied model to", dest)
|
| 50 |
+
except Exception as e:
|
| 51 |
+
print("Could not copy model to /app:", e)
|
| 52 |
+
except Exception as e:
|
| 53 |
+
print("Pre-download failed (continues build). Error:", e)
|
| 54 |
+
PY
|
| 55 |
+
|
| 56 |
+
# Expose port for local testing (Streamlit default 8501)
|
| 57 |
EXPOSE 8501
|
| 58 |
|
| 59 |
+
# default command for Streamlit (adjust if your original app uses different flags)
|
| 60 |
+
CMD ["streamlit", "run", "app.py", "--server.port=8501", "--server.headless=true"]
|