Skip to content
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
30 changes: 30 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,36 @@ jobs:
- name: Format check (ruff format --check)
run: uv run --project core --no-sync ruff format --check docs/assets/scripts

demo:
name: demo
runs-on: ubuntu-latest
defaults:
run:
working-directory: demo
steps:
- uses: actions/checkout@v6

- name: Install uv
uses: astral-sh/setup-uv@v8.1.0
with:
python-version: "3.11"
enable-cache: true

- name: Sync dev dependencies (core)
run: uv sync --only-group dev
working-directory: core

- name: Lint (ruff check)
run: uv run --project ../core --no-sync ruff check .

- name: Format check (ruff format --check)
run: uv run --project ../core --no-sync ruff format --check .

# The tests cover the app's pure helpers; the models are imported lazily,
# so gradio is enough (no torch).
- name: Test
run: uv run --no-project --with gradio --with pytest python -m pytest test_app.py -v

viewer:
name: viewer
runs-on: ubuntu-latest
Expand Down
39 changes: 39 additions & 0 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,45 @@ jobs:
${{ env.BACKEND_IMAGE_NAME }}:${{ env.VERSION }}
${{ env.BACKEND_IMAGE_NAME }}:latest

sync-space:
# The demo follows each repo's latest release and caches the models it
# loaded, so restart it even when demo/ is unchanged (no upload commit).
needs: publish-model
runs-on: ubuntu-latest
env:
SPACE: pyronear/Pyronear-Wildfire-Detection
HF_TOKEN: ${{ secrets.HF_TOKEN }} # needs write access to the Space
steps:
- uses: actions/checkout@v6
- name: Install uv
uses: astral-sh/setup-uv@v8.1.0
- name: Sync demo/ to the Space
working-directory: demo
run: make push SPACE="$SPACE"
- name: Restart the Space and wait until it runs
run: |
uv run --no-project --with huggingface_hub python - <<'EOF'
import os
import time

from huggingface_hub import HfApi

api, space = HfApi(), os.environ["SPACE"]
api.restart_space(space)
time.sleep(30) # let the stage leave RUNNING before polling
deadline = time.time() + 20 * 60
while time.time() < deadline:
stage = api.get_space_runtime(space).stage
print(stage, flush=True)
if stage == "RUNNING":
break
if stage.endswith("ERROR") or stage == "NO_APP_FILE":
raise SystemExit(f"{space} failed to start: {stage}")
time.sleep(20)
else:
raise SystemExit(f"{space} not RUNNING after 20 min")
EOF

release:
needs: docker
runs-on: ubuntu-latest
Expand Down
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ install: ## uv sync every package

lint: ## ruff check every package + docs scripts
@fail=0; for pkg in $(PACKAGES); do echo "==> $$pkg"; $(MAKE) -C $$pkg lint || fail=1; done; exit $$fail
@echo "==> docs/assets/scripts"
uv run --project core ruff check docs/assets/scripts
@echo "==> docs/assets/scripts + demo"
uv run --project core ruff check docs/assets/scripts demo

format: ## ruff format every package + docs scripts
@fail=0; for pkg in $(PACKAGES); do echo "==> $$pkg"; $(MAKE) -C $$pkg format || fail=1; done; exit $$fail
@echo "==> docs/assets/scripts"
uv run --project core ruff format docs/assets/scripts
@echo "==> docs/assets/scripts + demo"
uv run --project core ruff format docs/assets/scripts demo

test: ## pytest every package
@fail=0; for pkg in $(PACKAGES); do echo "==> $$pkg"; $(MAKE) -C $$pkg test || fail=1; done; exit $$fail
Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,18 @@ with the model, and splits it into **To Review** (worth a human's eyes) and
above are the *consumer* flow (no annotator credentials, no model, no Docker);
producing new data needs credentials — see `triage/README.md`.

### Try the models in a browser

```bash
cd demo && make install && make run # http://localhost:7860
```

`demo/` is a Gradio app mirrored to the HuggingFace Space
[`pyronear/Pyronear-Wildfire-Detection`](https://huggingface.co/spaces/pyronear/Pyronear-Wildfire-Detection):
one tab for the single-frame detector (`pyronear/yolov11s`), one for this
repo's temporal model on a whole sequence. Each release tag syncs the folder to
the Space (`HF_TOKEN=... make push` does it by hand). See `demo/README.md`.

## Origin

Ported from the Pyronear [`vision-rd`](https://github.com/pyronear/vision-rd)
Expand Down
35 changes: 35 additions & 0 deletions demo/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
*.7z filter=lfs diff=lfs merge=lfs -text
*.arrow filter=lfs diff=lfs merge=lfs -text
*.bin filter=lfs diff=lfs merge=lfs -text
*.bz2 filter=lfs diff=lfs merge=lfs -text
*.ckpt filter=lfs diff=lfs merge=lfs -text
*.ftz filter=lfs diff=lfs merge=lfs -text
*.gz filter=lfs diff=lfs merge=lfs -text
*.h5 filter=lfs diff=lfs merge=lfs -text
*.joblib filter=lfs diff=lfs merge=lfs -text
*.lfs.* filter=lfs diff=lfs merge=lfs -text
*.mlmodel filter=lfs diff=lfs merge=lfs -text
*.model filter=lfs diff=lfs merge=lfs -text
*.msgpack filter=lfs diff=lfs merge=lfs -text
*.npy filter=lfs diff=lfs merge=lfs -text
*.npz filter=lfs diff=lfs merge=lfs -text
*.onnx filter=lfs diff=lfs merge=lfs -text
*.ot filter=lfs diff=lfs merge=lfs -text
*.parquet filter=lfs diff=lfs merge=lfs -text
*.pb filter=lfs diff=lfs merge=lfs -text
*.pickle filter=lfs diff=lfs merge=lfs -text
*.pkl filter=lfs diff=lfs merge=lfs -text
*.pt filter=lfs diff=lfs merge=lfs -text
*.pth filter=lfs diff=lfs merge=lfs -text
*.rar filter=lfs diff=lfs merge=lfs -text
*.safetensors filter=lfs diff=lfs merge=lfs -text
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
*.tar.* filter=lfs diff=lfs merge=lfs -text
*.tar filter=lfs diff=lfs merge=lfs -text
*.tflite filter=lfs diff=lfs merge=lfs -text
*.tgz filter=lfs diff=lfs merge=lfs -text
*.wasm filter=lfs diff=lfs merge=lfs -text
*.xz filter=lfs diff=lfs merge=lfs -text
*.zip filter=lfs diff=lfs merge=lfs -text
*.zst filter=lfs diff=lfs merge=lfs -text
*tfevents* filter=lfs diff=lfs merge=lfs -text
3 changes: 3 additions & 0 deletions demo/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.venv/
__pycache__/
.cache/
24 changes: 24 additions & 0 deletions demo/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# This folder is a mirror of the HuggingFace Space, so it is shaped like one
# (app.py + requirements.txt + README.md), not like the repo's uv packages.
SPACE ?= pyronear/Pyronear-Wildfire-Detection

.PHONY: install run lint format push

install: ## build .venv from requirements.txt (pulls torch — large)
uv venv --python 3.12
uv pip install --python .venv -r requirements.txt

run: ## serve the demo at http://localhost:7860
.venv/bin/python app.py

lint: ## ruff check
uv run --project ../core ruff check .

format: ## ruff format
uv run --project ../core ruff format .

push: ## mirror this folder to the Space (needs `hf auth login` or HF_TOKEN)
uvx --from huggingface_hub hf upload $(SPACE) . . \
--repo-type space --exclude ".venv/*" --exclude ".cache/*" --exclude "*__pycache__/*" \
--delete "*" \
--commit-message "Sync from temporal-model/demo"
74 changes: 74 additions & 0 deletions demo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
---
title: Pyronear Wildfire Detection
emoji: 🔥
colorFrom: blue
colorTo: pink
sdk: gradio
python_version: "3.12"
app_file: app.py
pinned: false
license: apache-2.0
models:
- pyronear/yolov11s
- pyronear/temporal-model
---

# Pyronear — smoke detection demo

Gradio Space to try the two Pyronear wildfire-smoke models side by side. Source
lives in [`pyronear/temporal-model`](https://github.com/pyronear/temporal-model)
under `demo/`; the Space is a mirror of that folder.

| Tab | Model | Input | Output |
|---|---|---|---|
| Single frame — detection | [`pyronear/yolov11s`](https://huggingface.co/pyronear/yolov11s) latest | one image | boxes + confidences |
| Sequence — temporal model | [`pyronear/temporal-model`](https://huggingface.co/pyronear/temporal-model) latest | ordered frames, or a video | smoke / no-smoke, per-tube probabilities, trigger frame |

Both tabs run the detector at the pipeline's production settings
(`conf=0.1`, `iou=0.2`, `imgsz=1024`). The temporal `model.zip` bundles its own
pinned YOLO, so tab 2's boxes come from that one — they can differ from tab 1's.

Frames of a sequence are ordered **by filename**, the production convention
(`<prefix>_<YYYY-MM-DDTHH-MM-SS>.jpg`). A video is sampled into evenly spaced
frames instead.

The sequence tab answers with an animated WebP of the scored frames plus a
frame-by-frame carousel under it. The model scores only the first `max_frames`
(20) of a sequence, so the extra frames are reported as dropped and are shown in
neither view — displaying frames the model never looked at would misrepresent
the result. (WebP rather than GIF: a GIF's 256-colour palette is picked from the
photo and quantizes the magenta boxes away to grey.)

The trigger frame (earliest frame the model would have fired on) is off by
default: it re-scores growing prefixes of each tube, which is slow on CPU.

## Run locally

```bash
make install
make run # http://localhost:7860
```

`make install` builds `.venv` from `requirements.txt`, which pulls
`temporal-model-core[torch]` (torch, timm, ultralytics) — the first run is a
large download. Model weights are fetched from the Hub on first use and cached.

Both tabs follow the latest release of each repo (its `main` branch). Pin a
version or switch repo with `DETECTOR_REPO` / `DETECTOR_REVISION` /
`TEMPORAL_REPO` / `TEMPORAL_REVISION`.

## Examples

Drop a folder of frames in `demo/examples/<name>/` and it shows up as a
one-click example in the sequence tab. Committed examples are mirrored to the
Space; none are bundled today.

## Deploy

```bash
hf auth login # once, or set HF_TOKEN
make push
```

Mirrors this folder to the Space, deleting anything there that is no longer
here.
Loading
Loading