jrrribeiro commited on
Commit
72de27a
·
verified ·
1 Parent(s): fbd4a81

Sync app from GitHub Actions (main)

Browse files
Files changed (2) hide show
  1. .gitignore +2 -2
  2. README.md +73 -631
.gitignore CHANGED
@@ -3,10 +3,10 @@ __pycache__/
3
  .venv/
4
  .venv-ci/
5
  .pytest_cache/
 
6
  .env
7
  .env.*
8
  .DS_Store
9
  .vscode/
10
  dist/
11
- build/release/
12
- build/pyinstaller_uploader/
 
3
  .venv/
4
  .venv-ci/
5
  .pytest_cache/
6
+ .sixth/
7
  .env
8
  .env.*
9
  .DS_Store
10
  .vscode/
11
  dist/
12
+ build/
 
README.md CHANGED
@@ -13,678 +13,120 @@ hf_oauth_scopes:
13
  pinned: false
14
  ---
15
 
16
- # BirdNET-Validator-App
17
 
18
- BirdNET-Validator-App is a multi-purpose BirdNET workflow repository with two complementary entry points:
 
 
 
19
 
20
- 1. A Gradio-based web application for human validation of BirdNET detections in multi-project workflows.
21
- 2. A local command-line uploader for resumable Hugging Face dataset uploads with checkpoints, deduplication, and a Windows-friendly interactive flow.
22
 
23
- The validator app focuses on review, authorization, and auditability. The uploader CLI focuses on reliable dataset ingestion for large audio collections.
24
 
25
- ## Contents
 
 
 
 
 
 
 
 
26
 
27
- - [Overview](#overview)
28
- - [Validator App](#validator-app)
29
- - [Local Uploader CLI](#local-uploader-cli)
30
- - [Quick Start](#quick-start)
31
- - [Configuration](#configuration)
32
- - [Typical Flows](#typical-flows)
33
- - [Repository Structure](#repository-structure)
34
- - [Troubleshooting](#troubleshooting)
35
- - [Development Notes](#development-notes)
36
 
37
- ## Overview
 
 
 
 
 
 
 
38
 
39
- This repository is designed for two high-confidence operations:
40
 
41
- - controlled, multi-project human validation of detections
42
- - reliable, resumable upload of large audio datasets to Hugging Face
43
-
44
- The validator workflow emphasizes:
45
-
46
- - controlled access by user and project
47
- - rapid decision flow for detections
48
- - auditability through append-only events
49
- - conflict-aware updates for concurrent validators
50
- - compatibility with `HF_Dataset_Uploader` datasets using `index/files.parquet`
51
-
52
- The uploader workflow emphasizes:
53
-
54
- - single-flow login → repo → scan → upload
55
- - resumable sessions stored locally
56
- - remote deduplication with a local cache
57
- - progress tracking and checkpoint recovery
58
- - compatibility with the validator app's expected dataset structure
59
-
60
- ## Validator App
61
-
62
- The validator is a Gradio application for human review of BirdNET detections in multi-project workflows.
63
-
64
- ### Key Usability Features
65
-
66
- 1. Multi-project login with role-based access
67
- 2. Project selection for authorized datasets
68
- 3. Detection queue with filters and pagination
69
- 4. Audio loading on demand with ephemeral cache
70
- 5. Fast validation actions (positive, negative, uncertain, skip)
71
- 6. Concurrency-safe writes with optimistic lock feedback
72
- 7. Conflict resolution support and validation reporting
73
-
74
- ### Quick Start (Local)
75
-
76
- 1. Create and activate a Python 3.11+ virtual environment.
77
- 2. Install dependencies:
78
-
79
- ```bash
80
- pip install -r requirements.txt
81
- ```
82
-
83
- 3. Run the app:
84
-
85
- ```bash
86
- python app.py
87
- ```
88
-
89
- Default port is `7860`.
90
-
91
- ### Runtime Configuration
92
-
93
- Optional runtime configuration:
94
-
95
- - `BIRDNET_DETECTIONS_FILE`: path to JSON file with detections grouped by project slug.
96
- - `BIRDNET_VALIDATIONS_DIR`: custom directory for append-only validation events and snapshot files.
97
- - `BIRDNET_PAGE_SIZE`: queue page size (default: `25`).
98
- - `BIRDNET_PROJECTS_FILE`: JSON file with project catalog used at app startup.
99
- - `BIRDNET_USER_ACCESS_FILE`: JSON file mapping users to project roles (`admin`/`validator`).
100
- - `BIRDNET_INVITES_FILE`: JSON file storing pending invites.
101
- - `BIRDNET_INVITE_TTL_HOURS`: invite expiration in hours (default: `72`).
102
- - `BIRDNET_BOOTSTRAP_DIR`: base directory for bootstrap state files (`projects.json`, `user_access.json`, `invites.json`).
103
- - `BIRDNET_ENABLE_DEMO_BOOTSTRAP`: set to `true` only for local/demo mode to load built-in sample users/projects.
104
-
105
- Invite email settings (EmailJS):
106
-
107
- - `BIRDNET_EMAILJS_ENABLED`: set to `true` to send invite emails via EmailJS.
108
- - `BIRDNET_INVITE_EMAIL_ENABLED`: set to `true` to enable invite delivery.
109
- - `BIRDNET_INVITE_EMAIL_SENDER`: sender label shown in the invite email.
110
- - `BIRDNET_INVITE_EMAIL_LOGIN_URL`: login URL included in invitation instructions.
111
- - `BIRDNET_EMAILJS_SERVICE_ID`: EmailJS service ID.
112
- - `BIRDNET_EMAILJS_TEMPLATE_ID`: default/fallback EmailJS template ID.
113
- - `BIRDNET_EMAILJS_TEMPLATE_ID_USERNAME_ONLY`: optional template for username-only mode.
114
- - `BIRDNET_EMAILJS_TEMPLATE_ID_EMAIL_ONLY`: optional template for email-only mode.
115
- - `BIRDNET_EMAILJS_TEMPLATE_ID_DUAL`: optional template for dual mode (username + email).
116
- - `BIRDNET_EMAILJS_PUBLIC_KEY`: EmailJS public key.
117
- - `BIRDNET_EMAILJS_ENDPOINT`: EmailJS API endpoint (default: `https://api.emailjs.com/api/v1.0/email/send`).
118
- - `BIRDNET_EMAILJS_TIMEOUT_SECONDS`: request timeout in seconds (default: `20`).
119
-
120
- ### Validation Data Shapes
121
-
122
- Detection seed file example:
123
-
124
- ```json
125
- {
126
- "kenya-2024": [
127
- {
128
- "detection_key": "0000000000001001",
129
- "audio_id": "audio_1001",
130
- "scientific_name": "Cyanocorax cyanopogon",
131
- "confidence": 0.91,
132
- "start_time": 0.0,
133
- "end_time": 1.0
134
- }
135
- ]
136
- }
137
- ```
138
-
139
- Projects bootstrap file example (`BIRDNET_PROJECTS_FILE`):
140
-
141
- ```json
142
- [
143
- {
144
- "project_slug": "kenya-2024",
145
- "name": "Kenya Survey 2024",
146
- "dataset_repo_id": "org/kenya-2024-dataset",
147
- "active": true
148
- }
149
- ]
150
- ```
151
-
152
- User access bootstrap file example (`BIRDNET_USER_ACCESS_FILE`):
153
-
154
- ```json
155
- {
156
- "admin_user": {
157
- "kenya-2024": "admin"
158
- },
159
- "validator_a": {
160
- "kenya-2024": "validator"
161
- }
162
- }
163
- ```
164
-
165
- ### Typical Validation Flow
166
-
167
- 1. Login with a valid user.
168
- 2. Select an authorized project.
169
- 3. Load queue items and apply filters when needed.
170
- 4. Listen to selected audio and submit validation status.
171
- 5. Resolve conflicts when concurrent updates occur.
172
- 6. Export or inspect project validation report.
173
-
174
- ### Deploy on Hugging Face Spaces
175
-
176
- 1. Create a new Space with:
177
- - SDK: `Gradio`
178
- - Python: `3.11`
179
- - OAuth: enabled (`hf_oauth: true` in this README metadata)
180
- - OAuth scopes: `read-repos` only; in administrator-owned storage mode user OAuth is used only for identity
181
-
182
- 2. Push this repository to the Space.
183
-
184
- 3. Configure Variables/Secrets in the Space settings.
185
-
186
- Required for production bootstrap:
187
-
188
- - `BIRDNET_PROJECTS_FILE` (example: `docs/spaces/projects.sample.json`)
189
- - `BIRDNET_USER_ACCESS_FILE` (example: `docs/spaces/user_access.sample.json`)
190
-
191
- Optional runtime settings:
192
-
193
- - `BIRDNET_DETECTIONS_FILE` (seed detections JSON)
194
- - `BIRDNET_VALIDATIONS_DIR` (recommended: `/data/validations`)
195
- - `BIRDNET_BOOTSTRAP_DIR` (recommended: `/data/bootstrap`)
196
- - `BIRDNET_INVITES_FILE` (recommended: `/data/bootstrap/invites.json`)
197
- - `BIRDNET_INVITE_TTL_HOURS` (default `72`)
198
- - `BIRDNET_PAGE_SIZE` (default `25`)
199
- - `BIRDNET_ENABLE_DEMO_BOOTSTRAP` (`false` in production)
200
- - `BIRDNET_HF_PROJECT_STATE_WRITES_ENABLED=true` (legacy migration support for existing `_state` projects)
201
- - `BIRDNET_HF_BUCKET_VALIDATIONS_ENABLED=true` (legacy experimental access for existing Bucket projects)
202
- - `BIRDNET_HF_ADMIN_STORAGE_MODE_ENABLED=true` (private HF-only delivery mode for a small trusted team)
203
- - `BIRDNET_HF_PROJECT_STATE_REPOS=jrrribeiro/audio-dataset_state` (optional manual recovery list; administrator-owned mode discovers companion state repos automatically)
204
-
205
- The HF administrator-owned storage mode is intended for confidential projects run by a small trusted research team. The source audio dataset must already be private in the administrator's personal Hugging Face namespace. When a project is created, the app creates a private `_state` repository for project/ACL/invite recovery and a private Storage Bucket for validation events and snapshots in that same namespace. Select `collaborative` inside the app: this enables app-managed validators and does not make any Hugging Face resource public.
206
-
207
- The Space stores the administrator storage credential as a protected secret. Validators log in with their own Hugging Face identity and are invited or assigned inside the app; they do not need repository or Bucket permissions, organization membership, or the administrator token. Resource operations are performed server-side only after the app confirms the user's project role.
208
-
209
- When this mode is enabled it takes precedence over any existing Supabase settings: project ACL/invites are restored from private `*_state` repositories and validations are read and written in the project's private Bucket. Configuring the dedicated `BIRDNET_HF_STORAGE_TOKEN` Secret also enables this mode automatically, preventing a configured private-storage credential from remaining unused behind a legacy backend.
210
-
211
- Recommended administrator-owned Space settings:
212
 
213
  ```text
214
- BIRDNET_HF_ADMIN_STORAGE_MODE_ENABLED=true
215
- BIRDNET_AUTH_MODE=hf_token
216
- BIRDNET_HF_STORAGE_TOKEN=<administrator token stored only as a Space secret>
217
  ```
218
 
219
- `HF_TOKEN` remains a compatibility fallback for the server-side storage credential, but `BIRDNET_HF_STORAGE_TOKEN` is preferred because its purpose is explicit. Users sign in through Hugging Face OAuth; no personal-token login is exposed in the production interface. On restart the app uses the protected credential to find the administrator's companion `*_state` repositories automatically; `BIRDNET_HF_PROJECT_STATE_REPOS` remains available as an explicit fallback or migration list.
220
-
221
- Projects previously created with a private `_state` repository in this mode can be recovered from the **Admin** tab using **Connect Existing State**. Sign in as an administrator recorded in its `acl.json`, then provide the `_state` repo id (for example, `jrrribeiro/audio_dataset_state`). Recovery accepts only a manifest with private Bucket validation storage and a private personal-namespace source dataset accessible to the configured storage account. The app loads the saved manifest, ACL, and pending invites.
222
 
223
- Legacy Supabase state backend, available while migrating existing projects:
224
-
225
- - `BIRDNET_STATE_BACKEND=supabase`
226
- - `SUPABASE_URL` (Secret, example: `https://xxxx.supabase.co`)
227
- - `SUPABASE_SERVICE_ROLE_KEY` (Secret)
228
-
229
- When Supabase is enabled, projects, ACL, invites, validation events, and current validation snapshots are stored in Supabase instead of `/data`. For eventual public distribution, the planned backend is administrator-owned Supabase provisioned through OAuth with an Edge Function validating Hugging Face identity; see `docs/TEMP_BYO_SUPABASE_EDGE_FUNCTION_HF_IDENTITY_PLAN.md`.
230
-
231
- Optional invite email settings:
232
-
233
- - `BIRDNET_INVITE_EMAIL_ENABLED=true`
234
- - `BIRDNET_INVITE_EMAIL_SENDER`
235
- - `BIRDNET_INVITE_EMAIL_LOGIN_URL`
236
- - `BIRDNET_EMAILJS_ENABLED`
237
- - `BIRDNET_EMAILJS_SERVICE_ID`
238
- - `BIRDNET_EMAILJS_TEMPLATE_ID`
239
- - `BIRDNET_EMAILJS_PUBLIC_KEY`
240
- - `BIRDNET_EMAILJS_ENDPOINT`
241
- - `BIRDNET_EMAILJS_TIMEOUT_SECONDS`
242
-
243
- 4. For first smoke test only, you may temporarily set:
244
-
245
- - `BIRDNET_ENABLE_DEMO_BOOTSTRAP=true`
246
-
247
- Then log in with one of the demo users:
248
-
249
- - `admin_user`
250
- - `demo_user`
251
- - `validator_demo`
252
-
253
- 5. After validation, switch to production bootstrap:
254
-
255
- - Set `BIRDNET_ENABLE_DEMO_BOOTSTRAP=false`
256
- - Provide real `BIRDNET_PROJECTS_FILE` and `BIRDNET_USER_ACCESS_FILE`
257
-
258
- Notes:
259
-
260
- - The app entrypoint reads `PORT` automatically in Spaces.
261
- - Keep user/project bootstrap files private if they contain sensitive assignments.
262
- - Use Supabase or persistent Space storage to keep projects, invites, ACL, and validations across redeploys. The free Space filesystem is ephemeral.
263
- - In administrator-owned storage mode, each collaborator signs in with their own Hugging Face identity, while only the Space backend credential accesses private project storage.
264
- - Datasets uploaded by `HF_Dataset_Uploader` are read from `index/files.parquet` first; older `index/shards/*.parquet`, CSV, JSONL, and audio-path fallback layouts remain supported.
265
-
266
- ## Local Uploader CLI
267
-
268
- The repository also includes a local uploader CLI designed for large dataset ingest and resume support.
269
-
270
- ### Release Pipeline
271
-
272
- The repository includes a release pipeline that produces a portable uploader bundle and can publish it to Hugging Face.
273
-
274
- One-command Windows pipeline:
275
-
276
- ```powershell
277
- .\build\release_pipeline.ps1 -Version 0.1.0
278
- ```
279
-
280
- Build and publish in one step:
281
-
282
- ```powershell
283
- $env:HF_TOKEN = "hf_xxx"
284
- .\build\release_pipeline.ps1 -Version 0.1.0 -PublishToHf -RepoId jrrribeiro/birdnet-uploader-releases -RepoType dataset
285
- ```
286
-
287
- Validation-only step (recommended before publish):
288
-
289
- ```powershell
290
- .\build\validate_release.ps1 -Version 0.1.0
291
- ```
292
-
293
- Local build steps:
294
-
295
- ```bash
296
- python -m pip install --upgrade pip
297
- pip install -r requirements.txt
298
- pip install pyinstaller
299
- python build/release_uploader.py --version 0.1.0
300
- ```
301
-
302
- The build produces:
303
-
304
- - a zipped release bundle under `build/release/`
305
- - a `.sha256` checksum file next to the zip
306
-
307
- To publish a release bundle to Hugging Face from a local machine:
308
-
309
- ```bash
310
- set HF_TOKEN=hf_xxx
311
- python build/publish_release_to_hf.py ^
312
- --repo-id jrrribeiro/birdnet-uploader-releases ^
313
- --repo-type dataset ^
314
- --bundle build\release\birdnet-uploader-0.1.0-windows.zip ^
315
- --checksum build\release\birdnet-uploader-0.1.0-windows.zip.sha256 ^
316
- --version 0.1.0
317
- ```
318
-
319
- Recommended Hugging Face release repo layout:
320
 
321
  ```text
322
- birdnet-uploader-releases/
323
- releases/
324
- v0.1.0/
325
- birdnet-uploader-0.1.0-windows.zip
326
- birdnet-uploader-0.1.0-windows.zip.sha256
 
327
  ```
328
 
329
- Workflow on GitHub Actions:
330
-
331
- - run the release workflow manually
332
- - build the Windows executable with PyInstaller
333
- - archive the bundle as a workflow artifact
334
- - optionally upload the bundle and checksum to a Hugging Face repo
335
-
336
- Recommended user-facing validation after publishing:
337
-
338
- 1. Download the zip from Hugging Face.
339
- 2. Unzip into a clean folder.
340
- 3. Run the executable without Python installed.
341
- 4. Authenticate with a Hugging Face token.
342
- 5. Create a session and confirm resume/recovery works.
343
-
344
- ### What It Does
345
-
346
- - authenticates with a Hugging Face token stored in the OS keyring
347
- - creates or validates dataset repositories
348
- - scans a local audio folder recursively
349
- - computes per-file SHA-256 hashes
350
- - deduplicates against a cached remote index
351
- - uploads files with retries and session checkpoints
352
- - resumes from the last checkpoint after close or crash
353
-
354
- ### Main Commands
355
-
356
-
357
- The CLI entrypoint is:
358
-
359
- ```bash
360
- python -m src.uploader_cli.main --help
361
- ```
362
-
363
- Commands:
364
-
365
- - `login`: validate and store a Hugging Face token
366
- - `init-repo`: create and initialize a dataset repository
367
- - `scan`: scan a local folder and summarize audio files
368
- - `start`: create a local upload session checkpoint
369
- - `resume`: print the saved checkpoint for a session
370
-
371
- ### Example Workflow
372
-
373
- ```bash
374
- # Authenticate once
375
- python -m src.uploader_cli.main login
376
-
377
- # Create or initialize the dataset repository
378
- python -m src.uploader_cli.main init-repo --repo-id alice/birdnet-2026 --private
379
-
380
- # Inspect the local folder before upload
381
- python -m src.uploader_cli.main scan --segments C:\audio\segments
382
-
383
- # Create a resumable local session checkpoint
384
- python -m src.uploader_cli.main start --repo-id alice/birdnet-2026 --segments C:\audio\segments
385
-
386
-
387
- # Resume and inspect the checkpoint later
388
- python -m src.uploader_cli.main resume upload-20260429T120000Z
389
- ```
390
-
391
- ### Upload Engine Building Blocks
392
-
393
- The uploader CLI is built from the following modules:
394
-
395
- - `src/uploader_cli/auth_service.py`: token validation and keyring storage
396
- - `src/uploader_cli/repo_service.py`: dataset creation and structure initialization
397
- - `src/uploader_cli/scanner.py`: recursive audio discovery and metadata collection
398
- - `src/uploader_cli/hash_utils.py`: streaming SHA-256 helpers
399
- - `src/uploader_cli/deduplicator.py`: remote index cache and skip/upload decisions
400
- - `src/uploader_cli/session_manager.py`: checkpoint and session metadata persistence
401
- - `src/uploader_cli/batch_uploader.py`: retrying upload orchestration
402
- - `src/uploader_cli/error_handler.py`: user-friendly error formatting
403
-
404
- ### Local Data Layout
405
-
406
- The uploader stores local state under the user's profile directory by default:
407
-
408
- ```text
409
- ~/.birdnet-uploader/
410
- sessions/
411
- upload-YYYYMMDDTHHMMSSZ/
412
- metadata.json
413
- checkpoint.json
414
- cache/
415
- dedup/
416
- <repo-hash>.json
417
- logs/
418
- ```
419
-
420
- Environment overrides are supported:
421
-
422
- - `BIRDNET_UPLOADER_SESSION_DIR`
423
- - `BIRDNET_UPLOADER_CACHE_DIR`
424
- - `BIRDNET_UPLOADER_LOG_DIR`
425
-
426
- ### Dataset Layout Expected by the Validator
427
-
428
- The uploader is designed to preserve the validator's expected structure:
429
 
430
  ```text
431
- audio/{project_slug}/... # uploaded audio files
432
- index/shards/... # parquet shard files
433
- index/manifest.json # index manifest
434
- validations/... # validation outputs
435
- audit/ingestion-runs/... # ingestion run history
436
  ```
437
 
438
- ### Uploader Configuration
439
-
440
- Runtime constants are centralized in `src/uploader_cli/config.py`:
441
-
442
- - `APP_NAME`
443
- - `SCHEMA_VERSION`
444
- - `AUDIO_EXTENSIONS`
445
- - `INDEX_SHARD_SIZE`
446
- - `MAX_BATCH_SIZE`
447
- - `RETRY_MAX_ATTEMPTS`
448
- - `RETRY_INITIAL_BACKOFF_SECONDS`
449
- - `RETRY_MAX_BACKOFF_SECONDS`
450
- - `KEYRING_SERVICE`
451
- - `KEYRING_ACCOUNT`
452
-
453
- ### Resumability Guarantees
454
-
455
- The uploader uses local checkpoints so it can recover from:
456
-
457
- - process crashes
458
- - app close
459
- - transient network failures
460
- - partial progress during large uploads
461
-
462
- The checkpoint stores session metadata and cumulative counters such as:
463
-
464
- - uploaded count
465
- - skipped count
466
- - failed count
467
- - last completed file
468
- - last failed file
469
- - total uploaded bytes
470
-
471
- ## Quick Start
472
-
473
- ### Local Development
474
-
475
- 1. Create and activate a Python 3.11+ virtual environment.
476
- 2. Install dependencies:
477
 
478
  ```bash
 
 
 
479
  pip install -r requirements.txt
480
- ```
481
-
482
- 3. Run the validator app:
483
-
484
- ```bash
485
  python app.py
486
  ```
487
 
488
- 4. Run the uploader CLI help:
489
 
490
- ```bash
491
- python -m src.uploader_cli.main --help
492
  ```
493
 
494
- ### First-Time Uploader Setup
495
-
496
- 1. Log in with a Hugging Face token:
497
-
498
- ```bash
499
- python -m src.uploader_cli.main login
500
- ```
501
 
502
- 2. Validate your target repository exists or create it:
503
 
504
  ```bash
505
- python -m src.uploader_cli.main init-repo --repo-id alice/birdnet-2026 --private
506
  ```
507
 
508
- 3. Scan your local dataset folder:
509
 
510
  ```bash
511
- python -m src.uploader_cli.main scan --segments C:\audio\segments
512
  ```
513
 
514
- 4. Start a resumable session:
515
 
516
- ```bash
517
- python -m src.uploader_cli.main start --repo-id alice/birdnet-2026 --segments C:\audio\segments
 
 
 
 
 
 
 
 
 
518
  ```
519
 
520
- ## Configuration
521
-
522
- ### Validator App Environment Variables
523
-
524
- - `BIRDNET_DETECTIONS_FILE`
525
- - `BIRDNET_VALIDATIONS_DIR`
526
- - `BIRDNET_PAGE_SIZE`
527
- - `BIRDNET_PROJECTS_FILE`
528
- - `BIRDNET_USER_ACCESS_FILE`
529
- - `BIRDNET_INVITES_FILE`
530
- - `BIRDNET_INVITE_TTL_HOURS`
531
- - `BIRDNET_BOOTSTRAP_DIR`
532
- - `BIRDNET_ENABLE_DEMO_BOOTSTRAP`
533
- - `BIRDNET_EMAILJS_ENABLED`
534
- - `BIRDNET_INVITE_EMAIL_ENABLED`
535
- - `BIRDNET_INVITE_EMAIL_SENDER`
536
- - `BIRDNET_INVITE_EMAIL_LOGIN_URL`
537
- - `BIRDNET_EMAILJS_SERVICE_ID`
538
- - `BIRDNET_EMAILJS_TEMPLATE_ID`
539
- - `BIRDNET_EMAILJS_TEMPLATE_ID_USERNAME_ONLY`
540
- - `BIRDNET_EMAILJS_TEMPLATE_ID_EMAIL_ONLY`
541
- - `BIRDNET_EMAILJS_TEMPLATE_ID_DUAL`
542
- - `BIRDNET_EMAILJS_PUBLIC_KEY`
543
- - `BIRDNET_EMAILJS_ENDPOINT`
544
- - `BIRDNET_EMAILJS_TIMEOUT_SECONDS`
545
- - `BIRDNET_STATE_BACKEND`
546
- - `SUPABASE_URL`
547
- - `SUPABASE_SERVICE_ROLE_KEY`
548
- - `BIRDNET_HF_ADMIN_STORAGE_MODE_ENABLED`
549
- - `BIRDNET_HF_STORAGE_TOKEN` (Secret)
550
- - `BIRDNET_HF_PROJECT_STATE_REPOS`
551
- - `BIRDNET_HF_PROJECT_STATE_WRITES_ENABLED`
552
- - `BIRDNET_HF_BUCKET_VALIDATIONS_ENABLED`
553
-
554
- ### Uploader CLI Environment Variables
555
-
556
- - `BIRDNET_UPLOADER_SESSION_DIR`
557
- - `BIRDNET_UPLOADER_CACHE_DIR`
558
- - `BIRDNET_UPLOADER_LOG_DIR`
559
-
560
- ## Typical Flows
561
-
562
- ### Validation Flow
563
-
564
- 1. Login with a valid user.
565
- 2. Select an authorized project.
566
- 3. Load queue items and apply filters when needed.
567
- 4. Listen to selected audio and submit validation status.
568
- 5. Resolve conflicts when concurrent updates occur.
569
- 6. Export or inspect project validation report.
570
-
571
- ### Upload Flow
572
-
573
- 1. Authenticate once with a Hugging Face token.
574
- 2. Create or validate a dataset repository.
575
- 3. Scan the local folder recursively.
576
- 4. Deduplicate against remote files.
577
- 5. Upload with retries and checkpoints.
578
- 6. Resume later from the saved session metadata if needed.
579
-
580
- ## Repository Structure
581
-
582
- - `app.py`: validator app entrypoint
583
- - `src/auth`: authentication/session and ACL logic
584
- - `src/domain`: domain models
585
- - `src/repositories`: in-memory and append-only persistence
586
- - `src/services`: queue, validation, and audio fetch services
587
- - `src/ui`: Gradio interface composition and callbacks
588
- - `src/uploader_cli`: local uploader CLI, session persistence, deduplication, and retrying uploads
589
- - `tests`: unit and integration test suites
590
- - `docs`: collaborative workflow and QA checklists
591
-
592
- ## Project Status
593
-
594
- Validator workflow is active and under continuous development, with emphasis on reliability, auditability, and operator productivity.
595
-
596
- The uploader CLI is being built as a companion local workflow for large ingest tasks, with a focus on resumability and validator compatibility.
597
-
598
- ## FAQ
599
-
600
- ### Is this app intended for production use?
601
-
602
- Yes, for validator workflows. It is structured for multi-project access control, audit-friendly writes, and collaborative validation.
603
-
604
- ### Is the uploader CLI meant to replace the validator app?
605
-
606
- No. It is a companion tool for large dataset uploads and repository initialization.
607
-
608
- ### Does the app preload all audio files?
609
-
610
- No. Audio is fetched on demand for the selected detection, helping keep memory and network usage under control.
611
-
612
- ### Can multiple validators work at the same time?
613
-
614
- Yes. The validation flow uses optimistic concurrency checks to detect and handle conflicting updates.
615
-
616
- ### Can this run on Hugging Face Spaces?
617
-
618
- Yes. The validator app is designed for Gradio deployment on Hugging Face Spaces.
619
-
620
- ### Can the uploader resume after closing the app?
621
-
622
- Yes. It persists checkpoints and session metadata locally and can be resumed later.
623
-
624
- ### Does the uploader support deduplication?
625
-
626
- Yes. It checks the remote dataset index, caches the remote file list locally, and skips files that are already present.
627
-
628
- ## Troubleshooting
629
-
630
- ### The app does not start locally
631
-
632
- 1. Confirm Python 3.11+ is active.
633
- 2. Reinstall dependencies with `pip install -r requirements.txt`.
634
- 3. Run `python app.py` from the repository root.
635
-
636
- ### Port 7860 is already in use
637
-
638
- Stop the existing process using that port, or launch after setting a different `GRADIO_SERVER_PORT` environment variable.
639
-
640
- ### Login works but no project appears
641
-
642
- Your user likely has no project assignment. Verify `BIRDNET_PROJECTS_FILE` and `BIRDNET_USER_ACCESS_FILE`, or add project access through the admin flow.
643
-
644
- ### Seed warning appears in Validation tab
645
-
646
- If you see a seed warning banner:
647
-
648
- 1. Verify `BIRDNET_DETECTIONS_FILE` points to an existing file.
649
- 2. Confirm the file is valid UTF-8 JSON.
650
- 3. Confirm each project maps to a list of detections, or each list item includes `project_slug`.
651
- 4. If needed, unset `BIRDNET_DETECTIONS_FILE` to fall back to default demo detections.
652
-
653
- ### Audio does not load for a detection
654
-
655
- Check that:
656
-
657
- 1. `audio_id` exists and is valid for the selected project.
658
- 2. The dataset repository is reachable.
659
- 3. You have permission to read the project dataset.
660
-
661
- ### I get conflict messages while validating
662
-
663
- This means another validator updated the same detection first. Refresh and reapply your decision on the newest version.
664
-
665
- ### The uploader says the token cannot be saved
666
-
667
- Make sure your OS keyring backend is available. On Windows, the default credential store should work automatically.
668
-
669
- ### The uploader skips files unexpectedly
670
-
671
- It may have found them in the remote dataset index cache. Clear the uploader cache directory if you want to force a fresh remote listing.
672
-
673
- ### Resume shows an empty checkpoint
674
-
675
- Check that you ran the uploader `start` command at least once and that the session directory still exists.
676
-
677
- ## Recent Updates
678
-
679
- - Integrated Validation tab flow in the multi-project app (no placeholder stage).
680
- - Added project-scoped queue badge (`Queue: N`) and improved queue context feedback.
681
- - Added seed-file warning banner with actionable remediation guidance in Validation.
682
- - Standardized all user-facing UI text and feedback messages in English.
683
- - Updated authentication/session timestamps to timezone-aware UTC handling.
684
- - Added a local uploader CLI with login, repository initialization, scan, deduplication, checkpointing, and resumable upload foundations.
685
 
686
- ## Related Documents
 
687
 
688
- - `BIRDNET_UPLOADER_REDESIGN.md`: uploader UX and architecture notes
689
- - `SPRINT_ROADMAP.md`: implementation roadmap
690
- - `SPRINT1_KICKOFF.md`: sprint kickoff details
 
13
  pinned: false
14
  ---
15
 
16
+ # BirdNET Validator
17
 
18
+ BirdNET Validator is a Gradio app for collaborative review of BirdNET audio
19
+ segments stored in Hugging Face datasets. It is designed for research teams that
20
+ need authenticated validators, private project state, validation progress, and
21
+ downloadable scientific tables.
22
 
23
+ The uploader is maintained separately in `HF_Dataset_Uploader`. This repository
24
+ contains only the validator app.
25
 
26
+ ## Current Architecture
27
 
28
+ - Hugging Face OAuth identifies the signed-in validator.
29
+ - Each project points to one Hugging Face dataset containing audio segments and
30
+ metadata/index files.
31
+ - Project metadata and access rules live in a private companion dataset repo
32
+ named with the `_state` suffix.
33
+ - Validation events and current validation snapshots are stored in private
34
+ Hugging Face storage controlled by the app backend.
35
+ - Project access, invitations, validation status, progress, and exports are
36
+ managed from the app UI.
37
 
38
+ ## Main Features
 
 
 
 
 
 
 
 
39
 
40
+ - Secure Hugging Face sign-in with app-managed project access.
41
+ - Admin project creation, state connection, token management, invitations, and
42
+ safe deletion.
43
+ - Validation queue organized by species, confidence, and pending status.
44
+ - Audio playback, spectrogram preview, keyboard shortcuts, and correction rules.
45
+ - Required corrected species when rejecting a segment.
46
+ - Progress dashboards by species, validator, and recent activity.
47
+ - CSV/XLSX export combining the original detection table with validation fields.
48
 
49
+ ## Required Space Secret
50
 
51
+ For the current private HF storage mode, configure this secret in the Hugging
52
+ Face Space:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
 
54
  ```text
55
+ BIRDNET_HF_STORAGE_TOKEN
 
 
56
  ```
57
 
58
+ Use a Hugging Face token from the Space/project owner account with enough
59
+ permission to create, read, write, and delete the private project state repos and
60
+ validation storage used by the app.
61
 
62
+ ## Useful Optional Settings
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
 
64
  ```text
65
+ BIRDNET_PAGE_SIZE=10
66
+ BIRDNET_VALIDATOR_HOST=0.0.0.0
67
+ BIRDNET_VALIDATOR_PORT=7860
68
+ BIRDNET_INVITE_EMAIL_MODE=off
69
+ BIRDNET_INVITE_FROM_EMAIL=
70
+ BIRDNET_INVITE_REPLY_TO=
71
  ```
72
 
73
+ EmailJS settings are optional and only needed when email invitations are enabled:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
 
75
  ```text
76
+ BIRDNET_EMAILJS_SERVICE_ID=
77
+ BIRDNET_EMAILJS_TEMPLATE_ID=
78
+ BIRDNET_EMAILJS_PUBLIC_KEY=
79
+ BIRDNET_EMAILJS_PRIVATE_KEY=
 
80
  ```
81
 
82
+ ## Local Development
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83
 
84
  ```bash
85
+ python -m venv .venv
86
+ .venv\Scripts\activate
87
+ python -m pip install --upgrade pip
88
  pip install -r requirements.txt
 
 
 
 
 
89
  python app.py
90
  ```
91
 
92
+ Then open:
93
 
94
+ ```text
95
+ http://127.0.0.1:7860
96
  ```
97
 
98
+ ## Verification
 
 
 
 
 
 
99
 
100
+ Run the automated tests:
101
 
102
  ```bash
103
+ pytest -q
104
  ```
105
 
106
+ Run a lightweight deployment check:
107
 
108
  ```bash
109
+ python scripts/check_deployment.py
110
  ```
111
 
112
+ ## Repository Layout
113
 
114
+ ```text
115
+ app.py Gradio app entry point
116
+ src/auth/ Hugging Face identity and access helpers
117
+ src/cache/ Ephemeral audio/cache utilities
118
+ src/config/ Runtime configuration
119
+ src/domain/ Shared data models
120
+ src/repositories/ Project state and validation persistence
121
+ src/services/ Queue, audio, validation, deletion, email services
122
+ src/ui/ Gradio screens, components, and theme
123
+ scripts/check_deployment.py Pre-deployment smoke check
124
+ tests/ Unit and integration tests
125
  ```
126
 
127
+ ## Deployment
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
128
 
129
+ The GitHub workflow `sync-hf-space.yml` uploads `main` to the Hugging Face Space.
130
+ Set the GitHub Actions secret `HF_TOKEN` with write access to the target Space.
131
 
132
+ The CI workflow runs tests on every push and pull request to `main`.