Spaces:
Sleeping
Sleeping
build: docker files
Browse files- Dockerfile +38 -0
- README-docker.md +87 -0
- run_mosaic_docker.sh +52 -0
Dockerfile
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.10-slim AS env-builder
|
| 2 |
+
|
| 3 |
+
# Install system build tools
|
| 4 |
+
RUN apt-get update && apt-get install -y \
|
| 5 |
+
build-essential \
|
| 6 |
+
curl \
|
| 7 |
+
git gh \
|
| 8 |
+
vim \
|
| 9 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 10 |
+
|
| 11 |
+
# Install uv
|
| 12 |
+
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
|
| 13 |
+
|
| 14 |
+
# Clone paladin repo
|
| 15 |
+
WORKDIR /deps
|
| 16 |
+
RUN --mount=type=secret,id=github_token \
|
| 17 |
+
export GITHUB_TOKEN=$(cat /run/secrets/github_token) && \
|
| 18 |
+
git clone --branch dev https://oauth2:$GITHUB_TOKEN@github.com/pathology-data-mining/paladin.git
|
| 19 |
+
|
| 20 |
+
# Create non-root user for runtime
|
| 21 |
+
RUN useradd -m -u 1000 user
|
| 22 |
+
RUN chown -R user:user /deps
|
| 23 |
+
|
| 24 |
+
WORKDIR /app
|
| 25 |
+
RUN chown -R user:user /app
|
| 26 |
+
|
| 27 |
+
USER user
|
| 28 |
+
COPY --chown=user pyproject.toml README.md ./
|
| 29 |
+
COPY --chown=user src/ ./src/
|
| 30 |
+
|
| 31 |
+
RUN uv sync
|
| 32 |
+
ENV PATH="/app/.venv/bin:$PATH"
|
| 33 |
+
|
| 34 |
+
EXPOSE 7877
|
| 35 |
+
|
| 36 |
+
# HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
|
| 37 |
+
|
| 38 |
+
ENTRYPOINT ["gradio_app"]
|
README-docker.md
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Mosaic: Docker deployment
|
| 2 |
+
|
| 3 |
+
The Mosaic app been packaged as a Docker image, which may be easier to use than
|
| 4 |
+
installing the app in a Python environment.
|
| 5 |
+
|
| 6 |
+
## Table of Contents
|
| 7 |
+
|
| 8 |
+
- [Installation](#installation)
|
| 9 |
+
- [Usage](#usage)
|
| 10 |
+
|
| 11 |
+
### System requirements
|
| 12 |
+
|
| 13 |
+
Supported systems:
|
| 14 |
+
|
| 15 |
+
- Linux (x86) with GPU (NVIDIA CUDA)
|
| 16 |
+
|
| 17 |
+
### Pre-requisites
|
| 18 |
+
|
| 19 |
+
You will need to have Docker or Podman installed on your system, and at least 8G of
|
| 20 |
+
storage space for the docker image.
|
| 21 |
+
|
| 22 |
+
You will need to have the NVidia Container Toolkit installed on the machine where
|
| 23 |
+
you want to run the Mosaic app. For instructions, see
|
| 24 |
+
[Installing the NVIDIA Container Toolkit](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/install-guide.html)
|
| 25 |
+
|
| 26 |
+
### Installation
|
| 27 |
+
|
| 28 |
+
1. Pull the image into your local Docker repository
|
| 29 |
+
|
| 30 |
+
```bash
|
| 31 |
+
docker pull docker.io/tomp/mosaic-gradio
|
| 32 |
+
```
|
| 33 |
+
|
| 34 |
+
2. Set the HF_TOKEN to your HuggingFace access token
|
| 35 |
+
|
| 36 |
+
The models for Mosaic are not yet public. To access the models, you need to be
|
| 37 |
+
a member of the [Pathology Data Mining Group](https://huggingface.co/PDM-Group)
|
| 38 |
+
organization on HuggingFace.
|
| 39 |
+
|
| 40 |
+
To download the models, you need to set the HF_TOKEN environment variable to your
|
| 41 |
+
HuggingFace access token.
|
| 42 |
+
|
| 43 |
+
If you don not already have one, create an access token by logging in to your account
|
| 44 |
+
of HuggingFace, and clicking on the user icon at the top right corner of the site and
|
| 45 |
+
selecting "Access Tokens". When creating the token, select all read options for your
|
| 46 |
+
private space and the PDM-Group space.
|
| 47 |
+
|
| 48 |
+
```bash
|
| 49 |
+
export HF_TOKEN="TOKEN-FROM-HUGGINGFACE"
|
| 50 |
+
```
|
| 51 |
+
|
| 52 |
+
## Usage
|
| 53 |
+
|
| 54 |
+
1. Start up the web app using the command
|
| 55 |
+
|
| 56 |
+
```bash
|
| 57 |
+
docker run -it \
|
| 58 |
+
--gpus=all --runtime=nvidia \
|
| 59 |
+
--env HF_TOKEN=${HF_TOKEN} \
|
| 60 |
+
--shm-size=500m \
|
| 61 |
+
-p 7860:7860 \
|
| 62 |
+
tomp/mosaic-gradio
|
| 63 |
+
```
|
| 64 |
+
|
| 65 |
+
2. Access the webapp at the URL [http://localhost:7860/](http://localhost:7860)
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
*. You can also start up the docker container using the `run_mosaic_docker.sh` script
|
| 69 |
+
in this repo. That executes the `docker run` command (shown above) for you, and lets
|
| 70 |
+
you specify the port you want to use to access the app (if 7860 is not available).
|
| 71 |
+
|
| 72 |
+
To run it, you would just execute
|
| 73 |
+
|
| 74 |
+
```bash
|
| 75 |
+
./run_mosaic_docker.sh
|
| 76 |
+
|
| 77 |
+
or
|
| 78 |
+
|
| 79 |
+
./run_mosaic_docker.sh --port 7863
|
| 80 |
+
```
|
| 81 |
+
|
| 82 |
+
### Notes
|
| 83 |
+
|
| 84 |
+
- After you start up the application, it will download the necessary models from
|
| 85 |
+
HuggingFace. This may take some time (up to a few minutes) depending on your
|
| 86 |
+
internet connection.
|
| 87 |
+
|
run_mosaic_docker.sh
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
|
| 3 |
+
DOCKER_NAME="tomp/mosaic-gradio"
|
| 4 |
+
MOSAIC_PORT=7860
|
| 5 |
+
|
| 6 |
+
SHORT_HOST=$(hostname --short)
|
| 7 |
+
LONG_HOST=$(hostname --long)
|
| 8 |
+
|
| 9 |
+
die () { echo "FATAL: $*"; exit 1; }
|
| 10 |
+
|
| 11 |
+
usage () {
|
| 12 |
+
[[ -n $* ]] && echo "ERROR: $*"
|
| 13 |
+
cat <<END
|
| 14 |
+
Usage: $0 [--port <port>]
|
| 15 |
+
Options:
|
| 16 |
+
-p|--port ..... set port used to access the webapp (default: 7860)
|
| 17 |
+
-h|--help ..... print this summary
|
| 18 |
+
|
| 19 |
+
This starts up a mosaic-docker container to provide a local instance
|
| 20 |
+
of the Mosaic web app.
|
| 21 |
+
END
|
| 22 |
+
[[ -n $* ]] && exit 1
|
| 23 |
+
exit 0
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
while [[ $# -gt 0 ]]; do
|
| 27 |
+
ARG="$1"; shift
|
| 28 |
+
case "$ARG" in
|
| 29 |
+
-p|--port) MOSAIC_PORT="${1?missing port number}"; shift;;
|
| 30 |
+
-h|--help) usage;;
|
| 31 |
+
-*) usage "Unrecognized option '$ARG'";;
|
| 32 |
+
*) usage "Unrecognized argument '$ARG'";;
|
| 33 |
+
esac
|
| 34 |
+
done
|
| 35 |
+
|
| 36 |
+
[[ -n $HF_TOKEN ]] || die "HF_TOKEN is undefined"
|
| 37 |
+
|
| 38 |
+
echo "Access the Mosaic app at"
|
| 39 |
+
echo " http://${SHORT_HOST}:${MOSAIC_PORT}/"
|
| 40 |
+
echo "or"
|
| 41 |
+
echo " http://${LONG_HOST}:${MOSAIC_PORT}/"
|
| 42 |
+
echo
|
| 43 |
+
echo "You may need to wait a minute or so for the models to download before the site appears."
|
| 44 |
+
echo
|
| 45 |
+
|
| 46 |
+
docker run -it \
|
| 47 |
+
--gpus=all --runtime=nvidia \
|
| 48 |
+
--env HF_TOKEN=${HF_TOKEN} \
|
| 49 |
+
--shm-size=500m \
|
| 50 |
+
-p ${MOSAIC_PORT}:7860 \
|
| 51 |
+
docker.io/${DOCKER_NAME}
|
| 52 |
+
|