Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

interactive ml container #212

Merged
merged 1 commit into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions examples/interactive_ml/app/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Setup a Debian 12 based image with a Python virtualenv
FROM debian:12-slim AS build
RUN apt-get update && \
apt-get install --no-install-suggests --no-install-recommends --yes python3-venv gcc libpython3-dev && \
python3 -m venv /venv && \
/venv/bin/pip install --upgrade pip setuptools wheel

# Install Geo Engine library and its dependencies
FROM build AS build-venv
COPY pyproject.toml setup.cfg setup.py /library/
COPY geoengine /library/geoengine
WORKDIR /library
RUN /venv/bin/pip install --disable-pip-version-check .[dev,test,examples]

# Copy the virtualenv into a distroless image
# Hint: Use the `:debug` tag to get a shell in the image
FROM gcr.io/distroless/python3-debian12
COPY --from=build-venv /venv /venv

# Copy the example notebook to run
COPY examples/interactive_ml /app

WORKDIR /app

ENV GEOENGINE_INSTANCE_URL=https://zentrale.app.geoengine.io/api
ENV GEOENGINE_SESSION_TOKEN=<SESSION_TOKEN>

EXPOSE 8866

ENTRYPOINT [ \
"/venv/bin/python3", \
"-m", \
"voila", \
"--no-browser", \
"--Voila.ip='0.0.0.0'", \
"app/Simple Random Forest Two-Class Classifier on Sentinel-2 Images.ipynb" \
]
42 changes: 42 additions & 0 deletions examples/interactive_ml/app/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Interactive ML App

This app demonstrates a complete workflow for binary classification using Sentinel-2 satellite imagery and a Random Forest classifier. The workflow includes data acquisition, preprocessing, model training, and result visualization. Initially, the environment is set up and necessary libraries are imported. The spatial and temporal bounds for the data query are then defined through a query rectangle. A workflow is created to fetch and preprocess Sentinel-2 data, which is followed by the use of a labeling tool to create training data for water and non-water classes.

## Local setup

To run the app locally, you need to install the dependencies and start the app. You can install the dependencies with:

```bash
pip install --disable-pip-version-check -e .[dev,test,examples]

GEOENGINE_INSTANCE_URL=https://zentrale.app.geoengine.io/api \
GEOENGINE_SESSION_TOKEN=<SESSION_TOKEN> \
./examples/interactive_ml/app/app.sh
```

The app will be available at [http://localhost:8866](http://localhost:8866).

## Container setup

To run the app in a container, you need to build the container image and start the container.
You can build the container image with:

```bash
./examples/interactive_ml/app/build.sh

podman run --rm \
-p 8866:8866 \
-e GEOENGINE_INSTANCE_URL=https://zentrale.app.geoengine.io/api \
-e GEOENGINE_SESSION_TOKEN=<SESSION_TOKEN> \
geoengine-interactive-ml:latest
```

### Upload to quay.io

To upload the container image to quay.io, you need to log in and push the image.
You can do this with:

```bash
podman login quay.io
podman push geoengine-interactive-ml:latest quay.io/geoengine/geoengine-interactive-ml:latest
```
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
"outputs": [],
"source": [
"import ipyvuetify as vue\n",
"import IPython.display\n",
"import base64\n",
"from dataclasses import dataclass\n",
"from collections.abc import Callable, Coroutine\n",
"from enum import Enum\n",
Expand Down Expand Up @@ -341,6 +343,22 @@
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"with open(\"assets/favicon.ico\", \"rb\") as image_file:\n",
" favicon = base64.b64encode(image_file.read()).decode()\n",
"\n",
"favicon_changer = IPython.display.Javascript(f'''\n",
" document.querySelector(\"link[rel='icon']\").href = \"data:image/x-icon;base64,{favicon}\";\n",
"''')\n",
"\n",
"IPython.display.display(favicon_changer)"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down Expand Up @@ -399,7 +417,7 @@
" padding: 0 !important;\n",
" margin: 0 !important;\n",
" }\n",
"</style>\n"
"</style>"
]
},
{
Expand Down Expand Up @@ -489,7 +507,7 @@
" self.error_bar,\n",
" vue.Html(tag='br'),\n",
" ]),\n",
" vue.Footer(children=[vue.Col(children=['2024 – Geo Engine GmbH'], class_='text-center')], app=True),\n",
" vue.Footer(children=[vue.Col(children=['2025 – Geo Engine GmbH'], class_='text-center')], app=True),\n",
" ]\n",
"\n",
" def register_location_button(self, callback: Callable[[Location, str, str], None]) -> None:\n",
Expand Down Expand Up @@ -742,7 +760,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.3"
"version": "3.10.12"
}
},
"nbformat": 4,
Expand Down
Binary file added examples/interactive_ml/app/assets/favicon.ico
Binary file not shown.
5 changes: 5 additions & 0 deletions examples/interactive_ml/app/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

podman build -f $SCRIPT_DIR/Dockerfile --tag geoengine-interactive-ml:latest .
201 changes: 0 additions & 201 deletions examples/ml_water_bodies/labeling.py

This file was deleted.

Loading