File size: 1,266 Bytes
f3dcb14 | 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 | FROM python:3.11-slim AS base
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PIP_NO_CACHE_DIR=1 \
TOKENIZERS_PARALLELISM=false \
MODEL_OUTPUT_DIR=/app/arabguard_model \
CHECKPOINT_DIR=/tmp/arabguard_checkpoints \
DASHBOARD_DATA_DIR=/app/dashboard_data
WORKDIR /app
COPY requirements.txt ./requirements.txt
RUN pip install --upgrade pip && pip install -r requirements.txt
FROM base AS trainer
# Keep downloads and checkpoints in this disposable build stage.
ENV HF_HOME=/tmp/huggingface
# Only source code is copied from Git. The dataset and base model are downloaded,
# trained, and saved into the image while Hugging Face builds the Space.
COPY train_model.py ./
RUN python train_model.py
FROM base AS runtime
# Copy only the trained artifacts, not the dataset cache or checkpoints.
COPY --from=trainer --chown=1000:1000 /app/arabguard_model ./arabguard_model
COPY --from=trainer --chown=1000:1000 /app/dashboard_data ./dashboard_data
COPY app.py ./
ENV HOME=/home/user \
HF_HOME=/home/user/.cache/huggingface
RUN useradd --create-home --uid 1000 user \
&& chown -R user:user /app
USER user
EXPOSE 7860
CMD ["streamlit", "run", "app.py", "--server.address=0.0.0.0", "--server.port=7860", "--server.headless=true"]
|