curu-caption 3.3.0__tar.gz → 3.4.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (119) hide show
  1. {curu_caption-3.3.0 → curu_caption-3.4.1}/Cargo.lock +3 -3
  2. {curu_caption-3.3.0 → curu_caption-3.4.1}/Cargo.toml +1 -1
  3. {curu_caption-3.3.0 → curu_caption-3.4.1}/PKG-INFO +20 -2
  4. {curu_caption-3.3.0 → curu_caption-3.4.1}/README.md +18 -0
  5. {curu_caption-3.3.0 → curu_caption-3.4.1}/pyproject.toml +6 -4
  6. {curu_caption-3.3.0 → curu_caption-3.4.1}/src/curu_caption/cli.py +5 -2
  7. {curu_caption-3.3.0 → curu_caption-3.4.1}/src/curu_caption/commands/corpus_cli.py +158 -8
  8. {curu_caption-3.3.0 → curu_caption-3.4.1}/src/curu_caption/corpus/bundle.py +181 -1
  9. {curu_caption-3.3.0 → curu_caption-3.4.1}/src/curu_caption/corpus/timeline.py +21 -0
  10. {curu_caption-3.3.0 → curu_caption-3.4.1}/src/curu_caption/corpus/timeline_av.py +83 -1
  11. {curu_caption-3.3.0 → curu_caption-3.4.1}/LICENSE +0 -0
  12. {curu_caption-3.3.0 → curu_caption-3.4.1}/crates/curu-core/Cargo.toml +0 -0
  13. {curu_caption-3.3.0 → curu_caption-3.4.1}/crates/curu-core/assets/SEETAFACE_MODEL_LICENSE +0 -0
  14. {curu_caption-3.3.0 → curu_caption-3.4.1}/crates/curu-core/assets/seeta_fd_frontal_v1.0.bin +0 -0
  15. {curu_caption-3.3.0 → curu_caption-3.4.1}/crates/curu-core/benches/filter_1080p.rs +0 -0
  16. {curu_caption-3.3.0 → curu_caption-3.4.1}/crates/curu-core/benches/frame_extraction.rs +0 -0
  17. {curu_caption-3.3.0 → curu_caption-3.4.1}/crates/curu-core/benches/similarity.rs +0 -0
  18. {curu_caption-3.3.0 → curu_caption-3.4.1}/crates/curu-core/src/aesthetic.rs +0 -0
  19. {curu_caption-3.3.0 → curu_caption-3.4.1}/crates/curu-core/src/ahash.rs +0 -0
  20. {curu_caption-3.3.0 → curu_caption-3.4.1}/crates/curu-core/src/atomic_write.rs +0 -0
  21. {curu_caption-3.3.0 → curu_caption-3.4.1}/crates/curu-core/src/backpressure.rs +0 -0
  22. {curu_caption-3.3.0 → curu_caption-3.4.1}/crates/curu-core/src/blur_type.rs +0 -0
  23. {curu_caption-3.3.0 → curu_caption-3.4.1}/crates/curu-core/src/clip.rs +0 -0
  24. {curu_caption-3.3.0 → curu_caption-3.4.1}/crates/curu-core/src/decode.rs +0 -0
  25. {curu_caption-3.3.0 → curu_caption-3.4.1}/crates/curu-core/src/embed.rs +0 -0
  26. {curu_caption-3.3.0 → curu_caption-3.4.1}/crates/curu-core/src/error.rs +0 -0
  27. {curu_caption-3.3.0 → curu_caption-3.4.1}/crates/curu-core/src/face.rs +0 -0
  28. {curu_caption-3.3.0 → curu_caption-3.4.1}/crates/curu-core/src/filter.rs +0 -0
  29. {curu_caption-3.3.0 → curu_caption-3.4.1}/crates/curu-core/src/histogram.rs +0 -0
  30. {curu_caption-3.3.0 → curu_caption-3.4.1}/crates/curu-core/src/lib.rs +0 -0
  31. {curu_caption-3.3.0 → curu_caption-3.4.1}/crates/curu-core/src/phash.rs +0 -0
  32. {curu_caption-3.3.0 → curu_caption-3.4.1}/crates/curu-core/src/quality.rs +0 -0
  33. {curu_caption-3.3.0 → curu_caption-3.4.1}/crates/curu-core/src/shard_layout.rs +0 -0
  34. {curu_caption-3.3.0 → curu_caption-3.4.1}/crates/curu-core/src/sharpness.rs +0 -0
  35. {curu_caption-3.3.0 → curu_caption-3.4.1}/crates/curu-core/src/shot.rs +0 -0
  36. {curu_caption-3.3.0 → curu_caption-3.4.1}/crates/curu-core/src/sobel.rs +0 -0
  37. {curu_caption-3.3.0 → curu_caption-3.4.1}/crates/curu-ondisk/Cargo.toml +0 -0
  38. {curu_caption-3.3.0 → curu_caption-3.4.1}/crates/curu-ondisk/src/atomic_write.rs +0 -0
  39. {curu_caption-3.3.0 → curu_caption-3.4.1}/crates/curu-ondisk/src/facts.rs +0 -0
  40. {curu_caption-3.3.0 → curu_caption-3.4.1}/crates/curu-ondisk/src/lib.rs +0 -0
  41. {curu_caption-3.3.0 → curu_caption-3.4.1}/crates/curu-ondisk/src/png_meta.rs +0 -0
  42. {curu_caption-3.3.0 → curu_caption-3.4.1}/src/curu_caption/__init__.py +0 -0
  43. {curu_caption-3.3.0 → curu_caption-3.4.1}/src/curu_caption/__main__.py +0 -0
  44. {curu_caption-3.3.0 → curu_caption-3.4.1}/src/curu_caption/_core.pyi +0 -0
  45. {curu_caption-3.3.0 → curu_caption-3.4.1}/src/curu_caption/_tui_launcher.py +0 -0
  46. {curu_caption-3.3.0 → curu_caption-3.4.1}/src/curu_caption/adapters/__init__.py +0 -0
  47. {curu_caption-3.3.0 → curu_caption-3.4.1}/src/curu_caption/adapters/_vision_media.py +0 -0
  48. {curu_caption-3.3.0 → curu_caption-3.4.1}/src/curu_caption/adapters/combined_captioner.py +0 -0
  49. {curu_caption-3.3.0 → curu_caption-3.4.1}/src/curu_caption/adapters/embeddinggemma.py +0 -0
  50. {curu_caption-3.3.0 → curu_caption-3.4.1}/src/curu_caption/adapters/vision_service.py +0 -0
  51. {curu_caption-3.3.0 → curu_caption-3.4.1}/src/curu_caption/adapters/vlm_captioner.py +0 -0
  52. {curu_caption-3.3.0 → curu_caption-3.4.1}/src/curu_caption/adapters/vlm_judge.py +0 -0
  53. {curu_caption-3.3.0 → curu_caption-3.4.1}/src/curu_caption/adapters/wd14_tagger.py +0 -0
  54. {curu_caption-3.3.0 → curu_caption-3.4.1}/src/curu_caption/aitk/__init__.py +0 -0
  55. {curu_caption-3.3.0 → curu_caption-3.4.1}/src/curu_caption/aitk/emitter.py +0 -0
  56. {curu_caption-3.3.0 → curu_caption-3.4.1}/src/curu_caption/audio_models.py +0 -0
  57. {curu_caption-3.3.0 → curu_caption-3.4.1}/src/curu_caption/batch.py +0 -0
  58. {curu_caption-3.3.0 → curu_caption-3.4.1}/src/curu_caption/caption_grounding.py +0 -0
  59. {curu_caption-3.3.0 → curu_caption-3.4.1}/src/curu_caption/comfy/__init__.py +0 -0
  60. {curu_caption-3.3.0 → curu_caption-3.4.1}/src/curu_caption/comfy/infer.py +0 -0
  61. {curu_caption-3.3.0 → curu_caption-3.4.1}/src/curu_caption/comfy/workflow.py +0 -0
  62. {curu_caption-3.3.0 → curu_caption-3.4.1}/src/curu_caption/commands/__init__.py +0 -0
  63. {curu_caption-3.3.0 → curu_caption-3.4.1}/src/curu_caption/commands/comfy.py +0 -0
  64. {curu_caption-3.3.0 → curu_caption-3.4.1}/src/curu_caption/commands/media.py +0 -0
  65. {curu_caption-3.3.0 → curu_caption-3.4.1}/src/curu_caption/config.py +0 -0
  66. {curu_caption-3.3.0 → curu_caption-3.4.1}/src/curu_caption/content_version.py +0 -0
  67. {curu_caption-3.3.0 → curu_caption-3.4.1}/src/curu_caption/corpus/__init__.py +0 -0
  68. {curu_caption-3.3.0 → curu_caption-3.4.1}/src/curu_caption/corpus/audio_extractors.py +0 -0
  69. {curu_caption-3.3.0 → curu_caption-3.4.1}/src/curu_caption/corpus/avdm_adapter.py +0 -0
  70. {curu_caption-3.3.0 → curu_caption-3.4.1}/src/curu_caption/corpus/bundle_review.py +0 -0
  71. {curu_caption-3.3.0 → curu_caption-3.4.1}/src/curu_caption/corpus/cheap_extractors.py +0 -0
  72. {curu_caption-3.3.0 → curu_caption-3.4.1}/src/curu_caption/corpus/claim_check.py +0 -0
  73. {curu_caption-3.3.0 → curu_caption-3.4.1}/src/curu_caption/corpus/conform.py +0 -0
  74. {curu_caption-3.3.0 → curu_caption-3.4.1}/src/curu_caption/corpus/cull.py +0 -0
  75. {curu_caption-3.3.0 → curu_caption-3.4.1}/src/curu_caption/corpus/cut.py +0 -0
  76. {curu_caption-3.3.0 → curu_caption-3.4.1}/src/curu_caption/corpus/derive.py +0 -0
  77. {curu_caption-3.3.0 → curu_caption-3.4.1}/src/curu_caption/corpus/encode.py +0 -0
  78. {curu_caption-3.3.0 → curu_caption-3.4.1}/src/curu_caption/corpus/enrich.py +0 -0
  79. {curu_caption-3.3.0 → curu_caption-3.4.1}/src/curu_caption/corpus/extractors.py +0 -0
  80. {curu_caption-3.3.0 → curu_caption-3.4.1}/src/curu_caption/corpus/motion.py +0 -0
  81. {curu_caption-3.3.0 → curu_caption-3.4.1}/src/curu_caption/corpus/music.py +0 -0
  82. {curu_caption-3.3.0 → curu_caption-3.4.1}/src/curu_caption/corpus/origin.py +0 -0
  83. {curu_caption-3.3.0 → curu_caption-3.4.1}/src/curu_caption/corpus/probe.py +0 -0
  84. {curu_caption-3.3.0 → curu_caption-3.4.1}/src/curu_caption/corpus/projection.py +0 -0
  85. {curu_caption-3.3.0 → curu_caption-3.4.1}/src/curu_caption/corpus/provenance.py +0 -0
  86. {curu_caption-3.3.0 → curu_caption-3.4.1}/src/curu_caption/corpus/review_page.html +0 -0
  87. {curu_caption-3.3.0 → curu_caption-3.4.1}/src/curu_caption/corpus/role.py +0 -0
  88. {curu_caption-3.3.0 → curu_caption-3.4.1}/src/curu_caption/corpus/select.py +0 -0
  89. {curu_caption-3.3.0 → curu_caption-3.4.1}/src/curu_caption/corpus/shot_frames.py +0 -0
  90. {curu_caption-3.3.0 → curu_caption-3.4.1}/src/curu_caption/corpus/sound_fusion.py +0 -0
  91. {curu_caption-3.3.0 → curu_caption-3.4.1}/src/curu_caption/corpus/speech.py +0 -0
  92. {curu_caption-3.3.0 → curu_caption-3.4.1}/src/curu_caption/corpus/store.py +0 -0
  93. {curu_caption-3.3.0 → curu_caption-3.4.1}/src/curu_caption/corpus/timeline_audio.py +0 -0
  94. {curu_caption-3.3.0 → curu_caption-3.4.1}/src/curu_caption/corpus/timeline_visual.py +0 -0
  95. {curu_caption-3.3.0 → curu_caption-3.4.1}/src/curu_caption/corpus/trainer_config.py +0 -0
  96. {curu_caption-3.3.0 → curu_caption-3.4.1}/src/curu_caption/corpus/trainers.py +0 -0
  97. {curu_caption-3.3.0 → curu_caption-3.4.1}/src/curu_caption/corpus/window.py +0 -0
  98. {curu_caption-3.3.0 → curu_caption-3.4.1}/src/curu_caption/curation/__init__.py +0 -0
  99. {curu_caption-3.3.0 → curu_caption-3.4.1}/src/curu_caption/curation/dedup.py +0 -0
  100. {curu_caption-3.3.0 → curu_caption-3.4.1}/src/curu_caption/curation/judge.py +0 -0
  101. {curu_caption-3.3.0 → curu_caption-3.4.1}/src/curu_caption/facts.py +0 -0
  102. {curu_caption-3.3.0 → curu_caption-3.4.1}/src/curu_caption/infra.py +0 -0
  103. {curu_caption-3.3.0 → curu_caption-3.4.1}/src/curu_caption/local_staging_sync.py +0 -0
  104. {curu_caption-3.3.0 → curu_caption-3.4.1}/src/curu_caption/media_extensions.py +0 -0
  105. {curu_caption-3.3.0 → curu_caption-3.4.1}/src/curu_caption/meta.py +0 -0
  106. {curu_caption-3.3.0 → curu_caption-3.4.1}/src/curu_caption/models.py +0 -0
  107. {curu_caption-3.3.0 → curu_caption-3.4.1}/src/curu_caption/ort_providers.py +0 -0
  108. {curu_caption-3.3.0 → curu_caption-3.4.1}/src/curu_caption/pipeline.py +0 -0
  109. {curu_caption-3.3.0 → curu_caption-3.4.1}/src/curu_caption/ports/__init__.py +0 -0
  110. {curu_caption-3.3.0 → curu_caption-3.4.1}/src/curu_caption/ports/captioning.py +0 -0
  111. {curu_caption-3.3.0 → curu_caption-3.4.1}/src/curu_caption/ports/judging.py +0 -0
  112. {curu_caption-3.3.0 → curu_caption-3.4.1}/src/curu_caption/ports/tagging.py +0 -0
  113. {curu_caption-3.3.0 → curu_caption-3.4.1}/src/curu_caption/progress_report.py +0 -0
  114. {curu_caption-3.3.0 → curu_caption-3.4.1}/src/curu_caption/quality.py +0 -0
  115. {curu_caption-3.3.0 → curu_caption-3.4.1}/src/curu_caption/shard_layout.py +0 -0
  116. {curu_caption-3.3.0 → curu_caption-3.4.1}/src/curu_caption/sidecar.py +0 -0
  117. {curu_caption-3.3.0 → curu_caption-3.4.1}/src/curu_caption/staged_processing.py +0 -0
  118. {curu_caption-3.3.0 → curu_caption-3.4.1}/src/curu_caption/video/__init__.py +0 -0
  119. {curu_caption-3.3.0 → curu_caption-3.4.1}/src/curu_caption/video/midpoint_frame.py +0 -0
@@ -495,7 +495,7 @@ checksum = "460fbee9c2c2f33933d720630a6a0bac33ba7053db5344fac858d4b8952d77d5"
495
495
 
496
496
  [[package]]
497
497
  name = "curu-core"
498
- version = "3.3.0"
498
+ version = "3.4.1"
499
499
  dependencies = [
500
500
  "anyhow",
501
501
  "crc32fast",
@@ -519,7 +519,7 @@ dependencies = [
519
519
 
520
520
  [[package]]
521
521
  name = "curu-ondisk"
522
- version = "3.3.0"
522
+ version = "3.4.1"
523
523
  dependencies = [
524
524
  "anyhow",
525
525
  "crc32fast",
@@ -532,7 +532,7 @@ dependencies = [
532
532
 
533
533
  [[package]]
534
534
  name = "curu-tui"
535
- version = "3.3.0"
535
+ version = "3.4.1"
536
536
  dependencies = [
537
537
  "anyhow",
538
538
  "clap",
@@ -11,7 +11,7 @@ members = ["crates/curu-core", "crates/curu-ondisk"]
11
11
  resolver = "2"
12
12
 
13
13
  [workspace.package]
14
- version = "3.3.0"
14
+ version = "3.4.1"
15
15
  edition = "2021"
16
16
 
17
17
  [profile.release]
@@ -1,8 +1,8 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: curu-caption
3
- Version: 3.3.0
3
+ Version: 3.4.1
4
4
  Requires-Dist: avdm>=0.3.4,<0.4
5
- Requires-Dist: curu-vision[gpu]>=0.35.1,<0.36
5
+ Requires-Dist: curu-vision[gpu]>=0.36.0,<0.37
6
6
  Requires-Dist: av>=17
7
7
  Requires-Dist: click>=8
8
8
  Requires-Dist: curu-infra>=0.66,<0.73
@@ -55,6 +55,7 @@ default, and no step needs a cloud account.
55
55
  | Find the items that match a description | `curu-caption cut --corpus corpus/ --out training/ --want "a wide shot" --dry-run` | [Find items by meaning](#find-items-by-meaning) |
56
56
  | Make a training set for one model | `curu-caption cut --corpus corpus/ --out training/ --projection wan-t2v --caption` | [Make a training set](#make-a-training-set) |
57
57
  | Make a training set for MiniMax H3 | `curu-caption cut --corpus clips-corpus/ --out h3-training/ --projection h3 --caption` | [Make a training set for MiniMax H3](#make-a-training-set-for-minimax-h3) |
58
+ | Add timelines to a bundle you already made | `curu-caption timeline --bundle bundle/ --out bundle-timelines/` | [Add timelines to a bundle you already made](#add-timelines-to-a-bundle-you-already-made) |
58
59
  | Make an audio-visual bundle for amoral | `curu-caption cut --corpus clips-corpus/ --out bundle/ --trainer amoral-av --golden golden-v1/ --estate-root media/` | [Make a bundle for amoral](#make-a-bundle-for-amoral) |
59
60
  | Look at a corpus or a cut, and correct it | `curu-caption review --corpus corpus/` | [Review a corpus or a cut](#review-a-corpus-or-a-cut) |
60
61
  | Caption each file in a folder | `curu-caption caption photos/` | [Caption a folder](#caption-a-folder) |
@@ -440,6 +441,23 @@ curu-caption cut --corpus clips-corpus/ --out bundle/ --trainer amoral-av \
440
441
  The bundle format, the five changes and the clips that the cut leaves out are in
441
442
  [docs/amoral-av.md](docs/amoral-av.md).
442
443
 
444
+ ## Add timelines to a bundle you already made
445
+
446
+ A bundle that was cut before the timeline existed gets its timelines without a new cut.
447
+ The clips stay the clips that amoral's held-out rows name:
448
+
449
+ ```bash
450
+ curu-caption timeline --bundle bundle/ --out bundle-timelines/
451
+ ```
452
+
453
+ - The command copies the bundle into the new folder, media byte for byte, and writes
454
+ `timelines/<id>.jsonl` beside the copied rows.
455
+ - `--device cpu` or `--device cuda` names where the face, person, sync and speaking
456
+ models run.
457
+ - The output's README names the source bundle and its `manifest.sha256`.
458
+
459
+ The detail is in [docs/amoral-av.md](docs/amoral-av.md).
460
+
443
461
  ## Review a corpus or a cut
444
462
 
445
463
  `review` opens a corpus or a cut in the terminal. Look at each item, correct its caption, and
@@ -21,6 +21,7 @@ default, and no step needs a cloud account.
21
21
  | Find the items that match a description | `curu-caption cut --corpus corpus/ --out training/ --want "a wide shot" --dry-run` | [Find items by meaning](#find-items-by-meaning) |
22
22
  | Make a training set for one model | `curu-caption cut --corpus corpus/ --out training/ --projection wan-t2v --caption` | [Make a training set](#make-a-training-set) |
23
23
  | Make a training set for MiniMax H3 | `curu-caption cut --corpus clips-corpus/ --out h3-training/ --projection h3 --caption` | [Make a training set for MiniMax H3](#make-a-training-set-for-minimax-h3) |
24
+ | Add timelines to a bundle you already made | `curu-caption timeline --bundle bundle/ --out bundle-timelines/` | [Add timelines to a bundle you already made](#add-timelines-to-a-bundle-you-already-made) |
24
25
  | Make an audio-visual bundle for amoral | `curu-caption cut --corpus clips-corpus/ --out bundle/ --trainer amoral-av --golden golden-v1/ --estate-root media/` | [Make a bundle for amoral](#make-a-bundle-for-amoral) |
25
26
  | Look at a corpus or a cut, and correct it | `curu-caption review --corpus corpus/` | [Review a corpus or a cut](#review-a-corpus-or-a-cut) |
26
27
  | Caption each file in a folder | `curu-caption caption photos/` | [Caption a folder](#caption-a-folder) |
@@ -406,6 +407,23 @@ curu-caption cut --corpus clips-corpus/ --out bundle/ --trainer amoral-av \
406
407
  The bundle format, the five changes and the clips that the cut leaves out are in
407
408
  [docs/amoral-av.md](docs/amoral-av.md).
408
409
 
410
+ ## Add timelines to a bundle you already made
411
+
412
+ A bundle that was cut before the timeline existed gets its timelines without a new cut.
413
+ The clips stay the clips that amoral's held-out rows name:
414
+
415
+ ```bash
416
+ curu-caption timeline --bundle bundle/ --out bundle-timelines/
417
+ ```
418
+
419
+ - The command copies the bundle into the new folder, media byte for byte, and writes
420
+ `timelines/<id>.jsonl` beside the copied rows.
421
+ - `--device cpu` or `--device cuda` names where the face, person, sync and speaking
422
+ models run.
423
+ - The output's README names the source bundle and its `manifest.sha256`.
424
+
425
+ The detail is in [docs/amoral-av.md](docs/amoral-av.md).
426
+
409
427
  ## Review a corpus or a cut
410
428
 
411
429
  `review` opens a corpus or a cut in the terminal. Look at each item, correct its caption, and
@@ -4,7 +4,7 @@ build-backend = "maturin"
4
4
 
5
5
  [project]
6
6
  name = "curu-caption"
7
- version = "3.3.0"
7
+ version = "3.4.1"
8
8
  readme = "README.md"
9
9
  license = "MIT"
10
10
  license-files = ["LICENSE"]
@@ -26,9 +26,11 @@ dependencies = [
26
26
  # OpenAI-compatible server to the vlm port (#183).
27
27
  # 0.33.0 (the sync port, the 1 MP face tracker and `measured_threshold()`,
28
28
  # issue #205) is the floor; 0.35.1 (the face entry keyed to `face-track-2`
29
- # at the 1 MP bound, curu-vision#164) is the floor of the face gate. The
30
- # range is one minor, as curu-vision's ports move together.
31
- "curu-vision[gpu]>=0.35.1,<0.36",
29
+ # at the 1 MP bound, curu-vision#164) is the floor of the face gate, and
30
+ # 0.36.0 (the speaker-face link and the speaking threshold, curu-vision#141)
31
+ # is the floor of the speaker-face records. The range is one minor, as
32
+ # curu-vision's ports move together.
33
+ "curu-vision[gpu]>=0.36.0,<0.37",
32
34
  "av>=17",
33
35
  "click>=8",
34
36
  # The sister capability, not a vendored copy of one. Captioning is the only
@@ -18,7 +18,7 @@ import click
18
18
 
19
19
  from curu_caption import __version__
20
20
  from curu_caption.commands.comfy import comfy as comfy_cmd
21
- from curu_caption.commands.corpus_cli import cut_cmd, index_cmd, ingest_cmd
21
+ from curu_caption.commands.corpus_cli import cut_cmd, index_cmd, ingest_cmd, timeline_cmd
22
22
  from curu_caption.commands.media import caption_files as caption_files_cmd
23
23
  from curu_caption.commands.media import curate as curate_cmd
24
24
  from curu_caption.commands.media import emit_dataset as emit_dataset_cmd
@@ -34,7 +34,7 @@ class _WorkflowGroupedGroup(click.Group):
34
34
  """
35
35
 
36
36
  COMMAND_GROUPS = [
37
- ("Build a training set", ["ingest", "index", "cut", "review"]),
37
+ ("Build a training set", ["ingest", "index", "cut", "review", "timeline"]),
38
38
  (
39
39
  "Loose images & folders (no corpus)",
40
40
  ["caption", "curate", "judge", "dataset-config", "comfy"],
@@ -229,6 +229,9 @@ main.add_command(ingest_cmd)
229
229
  main.add_command(index_cmd)
230
230
  main.add_command(cut_cmd)
231
231
 
232
+ # The retrofit verb: timelines for a bundle that was cut without them (--213).
233
+ main.add_command(timeline_cmd)
234
+
232
235
  # The loose-media track: no corpus, just a file or a folder. `caption` is a
233
236
  # plain command again -- the group that disambiguated it from the dataset-shaped
234
237
  # `caption` went when that command did.
@@ -27,7 +27,7 @@ import shutil
27
27
  import sys
28
28
  from collections.abc import Callable, Mapping
29
29
  from pathlib import Path
30
- from typing import Any
30
+ from typing import Any, Literal, cast
31
31
 
32
32
  import click
33
33
  import httpx
@@ -1550,8 +1550,28 @@ def _check_bundle_options(trainer: str, *, golden: str | None, estate_root: str
1550
1550
  raise click.UsageError(f"--trainer {trainer} needs {flag}: {why}.")
1551
1551
 
1552
1552
 
1553
+ def _moss_transcriber(device: str | None = None): # noqa: ANN001, ANN202
1554
+ """The MOSS transcriber the speaker-face link reads (curu-vision#141).
1555
+
1556
+ MOSS is a second transcription engine, besides the speech fact's: the
1557
+ link's port wants the transcript whose segments carry speaker labels.
1558
+ Without it, the speaker-face kind is left out, and the cut says so. The
1559
+ weights load here, when the flag announces the work, only if the sync
1560
+ detector loaded too.
1561
+ """
1562
+ from curu_vision.transcription import TranscriptionConfig, load_transcriber
1563
+
1564
+ config = (
1565
+ TranscriptionConfig(engine="moss")
1566
+ if device is None
1567
+ else TranscriptionConfig(engine="moss", device=cast(Literal["cpu", "cuda"], device))
1568
+ )
1569
+ return load_transcriber(config)
1570
+
1571
+
1553
1572
  def _timeline_builder(
1554
1573
  console,
1574
+ device: str | None = None,
1555
1575
  ) -> Callable[[Path, Mapping], list] | None: # noqa: ANN001
1556
1576
  """The per-clip callable that turns a bundle clip into timeline records.
1557
1577
 
@@ -1577,7 +1597,8 @@ def _timeline_builder(
1577
1597
  tasks.extend((b.kind, lambda clip, row, b=b: b.extract_window(clip)) for b in sound)
1578
1598
  console.print(f" [dim]timeline sound events with {TAGGER_MODEL}[/]")
1579
1599
 
1580
- visual, audiovisual = _timeline_models(console)
1600
+ sync_cell: list = [None]
1601
+ visual, audiovisual = _timeline_models(console, device, sync_cell)
1581
1602
  tracks_cell: list = [None]
1582
1603
 
1583
1604
  face = None
@@ -1592,6 +1613,36 @@ def _timeline_builder(
1592
1613
 
1593
1614
  tasks.append(("face", run_face))
1594
1615
  tasks.extend((e.kind, lambda clip, row, e=e: e.extract(clip)) for e in visual[1:])
1616
+ if audiovisual and sync_cell[0] is not None and face is not None:
1617
+ try:
1618
+ import numpy as np
1619
+ from curu_vision.audiovisual import link_speakers
1620
+ from curu_vision.embedding import Audio as LinkAudio
1621
+
1622
+ import curu_caption.corpus.timeline_av as _timeline_av
1623
+
1624
+ moss = _moss_transcriber(device)
1625
+
1626
+ def transcript_of(samples): # noqa: ANN001
1627
+ (item,) = moss.transcribe(
1628
+ [LinkAudio(np.asarray(samples, dtype=np.float32), 16_000)]
1629
+ )
1630
+ if getattr(item, "error", None) is not None and hasattr(item, "error"):
1631
+ raise item.error
1632
+ return item
1633
+
1634
+ link = _timeline_av.SpeakerLinkExtractor(
1635
+ linker=link_speakers, transcript=transcript_of, sync=sync_cell[0]
1636
+ )
1637
+
1638
+ def run_link(clip, row, link=link): # noqa: ANN001
1639
+ return link.extract(clip, tracks_cell[0])
1640
+
1641
+ tasks.append(("speaker-face", run_link))
1642
+ console.print(" [dim]timeline speaker-face link from curu-vision[/]")
1643
+ except Exception as exc: # noqa: BLE001 -- one missing kind, not one dead run
1644
+ console.print(f" [yellow]timeline speaker-face unavailable[/]: {exc}")
1645
+
1595
1646
  if audiovisual:
1596
1647
  if face is None:
1597
1648
  console.print(
@@ -1632,18 +1683,21 @@ def _timeline_builder(
1632
1683
  return build
1633
1684
 
1634
1685
 
1635
- def _timeline_models(console): # noqa: ANN001
1686
+ def _timeline_models(console, device: str | None = None, sync_cell: list | None = None): # noqa: ANN001, ANN202
1636
1687
  """Load the curu-vision models the visual and audiovisual timeline needs.
1637
1688
 
1638
1689
  Answers two lists. Sync and speaking take the face tracks at extract time,
1639
1690
  so their loaders sit in the second list; the face extractor rides first in
1640
1691
  the first list, because the tracks must exist before the ports see them.
1641
- A kind whose model does not load prints a yellow line and is left out.
1692
+ A kind whose model does not load prints a yellow line and is left out. With
1693
+ *device*, the loaders that take where to run are asked for it; without, each
1694
+ keeps its own default.
1642
1695
  """
1643
1696
  visual: list = []
1644
1697
  audiovisual: list = []
1645
1698
  try:
1646
1699
  from curu_vision.entities import (
1700
+ SegmentationConfig,
1647
1701
  load_face_detector,
1648
1702
  load_person_detector,
1649
1703
  load_person_tracker,
@@ -1658,17 +1712,39 @@ def _timeline_models(console): # noqa: ANN001
1658
1712
 
1659
1713
  media = load_media()
1660
1714
  visual.append(FaceTrackExtractor(load_face_detector(), media))
1661
- visual.append(PersonTrackExtractor(load_person_tracker(), media))
1715
+ person_tracker = load_person_tracker()
1716
+ if device is not None:
1717
+ person_tracker = load_person_tracker(
1718
+ SegmentationConfig(device=cast(Literal["cpu", "cuda"], device))
1719
+ )
1720
+ visual.append(PersonTrackExtractor(person_tracker, media))
1662
1721
  visual.append(PersonDetectExtractor(load_person_detector(), media))
1663
1722
  except Exception as exc: # noqa: BLE001 -- one missing kind, not one dead run
1664
1723
  console.print(f" [yellow]timeline faces unavailable[/]: {exc}")
1665
1724
  try:
1666
- from curu_vision.audiovisual import load_speaker_detector, load_sync_detector
1725
+ from curu_vision.audiovisual import (
1726
+ SpeakerConfig,
1727
+ SyncConfig,
1728
+ load_speaker_detector,
1729
+ load_sync_detector,
1730
+ )
1667
1731
 
1668
1732
  from curu_caption.corpus.timeline_av import SpeakerExtractor, SyncExtractor
1669
1733
 
1670
- audiovisual.append(SyncExtractor(load_sync_detector()))
1671
- audiovisual.append(SpeakerExtractor(load_speaker_detector()))
1734
+ sync_detector = load_sync_detector()
1735
+ if device is not None:
1736
+ sync_detector = load_sync_detector(
1737
+ SyncConfig(device=cast(Literal["cpu", "cuda"], device))
1738
+ )
1739
+ speaker_detector = load_speaker_detector()
1740
+ if device is not None:
1741
+ speaker_detector = load_speaker_detector(
1742
+ SpeakerConfig(device=cast(Literal["cpu", "cuda"], device))
1743
+ )
1744
+ audiovisual.append(SyncExtractor(sync_detector))
1745
+ audiovisual.append(SpeakerExtractor(speaker_detector))
1746
+ if sync_cell is not None:
1747
+ sync_cell[0] = sync_detector
1672
1748
  except Exception as exc: # noqa: BLE001 -- one missing kind, not one dead run
1673
1749
  console.print(f" [yellow]timeline sync and speaking unavailable[/]: {exc}")
1674
1750
  return visual, audiovisual
@@ -1685,6 +1761,7 @@ def _bundle( # noqa: PLR0913 -- one call site
1685
1761
  seed: int,
1686
1762
  dry_run: bool,
1687
1763
  timeline: bool,
1764
+ limit: int | None,
1688
1765
  selection: dict,
1689
1766
  console, # noqa: ANN001
1690
1767
  ) -> tuple[int, int, int, int]:
@@ -1711,6 +1788,7 @@ def _bundle( # noqa: PLR0913 -- one call site
1711
1788
  selection=selection,
1712
1789
  dry_run=dry_run,
1713
1790
  timeline=builder,
1791
+ limit=limit,
1714
1792
  )
1715
1793
  except GoldenConflictError as exc:
1716
1794
  console.print(f"[red]refusing:[/] {exc}. Nothing was written.")
@@ -1895,6 +1973,7 @@ def _cut( # noqa: PLR0913 -- one call site; the alternative is a params object
1895
1973
  seed=seed,
1896
1974
  dry_run=dry_run,
1897
1975
  timeline=timeline,
1976
+ limit=limit,
1898
1977
  selection={"want": want or None, "lowest_score_kept": lowest_score_kept},
1899
1978
  console=console,
1900
1979
  )
@@ -2105,3 +2184,74 @@ def _cut( # noqa: PLR0913 -- one call site; the alternative is a params object
2105
2184
 
2106
2185
 
2107
2186
  __all__ = ["cut_cmd", "ingest_cmd"]
2187
+
2188
+
2189
+ @click.command("timeline")
2190
+ @click.option(
2191
+ "--bundle",
2192
+ "bundle",
2193
+ required=True,
2194
+ type=click.Path(exists=True, file_okay=False),
2195
+ help="The amoral-av bundle to read. It is a read-only input: nothing is written there",
2196
+ )
2197
+ @click.option(
2198
+ "--out",
2199
+ "out",
2200
+ required=True,
2201
+ type=click.Path(),
2202
+ help="A new folder to write: a copy of the bundle plus timelines/. It must not exist "
2203
+ "or be empty; never point it into the source bundle",
2204
+ )
2205
+ @click.option(
2206
+ "--device",
2207
+ type=click.Choice(["cpu", "cuda"]),
2208
+ default=None,
2209
+ help="Where the face, person, sync and speaking models run. Without it, each model "
2210
+ "keeps its own default. On a CUDA box name the GPU with CUDA_VISIBLE_DEVICES",
2211
+ )
2212
+ def timeline_cmd(bundle: str, out: str, device: str | None) -> None:
2213
+ """Write timelines/<id>.jsonl for each clip of an EXISTING amoral-av bundle.
2214
+
2215
+ The bundle's media is copied byte for byte into OUT. The same records and
2216
+ gates that `cut --timeline` writes are written beside them. Nothing is
2217
+ re-encoded, re-selected or changed in the source. Use it when a bundle was
2218
+ cut before the timeline existed. Its clips must stay the clips that amoral's
2219
+ held-out rows and calibration pairs name. The source bundle stays a
2220
+ read-only input; point --out at a folder on this computer's disk.
2221
+ """
2222
+ from curu_caption.corpus.bundle import add_timelines
2223
+
2224
+ console = _console()
2225
+ source, out_path = Path(bundle), Path(out)
2226
+ if source == out_path or out_path in source.parents or source in out_path.parents:
2227
+ console.print("[red]refusing:[/] --out must be outside --bundle, never inside it")
2228
+ sys.exit(1)
2229
+
2230
+ console.print(f" reading {source} read-only; writing {out_path}")
2231
+ builder = _timeline_builder(console, device)
2232
+ try:
2233
+ result = add_timelines(source, out_path, timeline=builder)
2234
+ except FileNotFoundError as exc:
2235
+ console.print(f"[red]refusing:[/] {exc}")
2236
+ sys.exit(1)
2237
+ except FileExistsError as exc:
2238
+ console.print(f"[red]refusing:[/] {exc}")
2239
+ sys.exit(1)
2240
+ except ValueError as exc:
2241
+ console.print(f"[red]refusing:[/] {exc}")
2242
+ sys.exit(1)
2243
+
2244
+ for name, why in result.timeline_failed[:5]:
2245
+ console.print(f" [red]{name}[/]: {why}")
2246
+ if len(result.timeline_failed) > 5:
2247
+ console.print(f" [dim]...and {len(result.timeline_failed) - 5} more[/]")
2248
+ for line in result.problems[:5]:
2249
+ console.print(f" [red]{line}[/]")
2250
+ if len(result.problems) > 5:
2251
+ console.print(f" [dim]...and {len(result.problems) - 5} more[/]")
2252
+ console.print(
2253
+ f"[green]wrote[/] {result.timeline_written} timeline(s) for {result.clips} "
2254
+ f"clip(s); the new README names the source bundle and its manifest sha256"
2255
+ )
2256
+ if result.timeline_failed or result.problems:
2257
+ sys.exit(1)
@@ -42,6 +42,7 @@ import hashlib
42
42
  import json
43
43
  import os
44
44
  import re
45
+ import shutil
45
46
  import subprocess
46
47
  import unicodedata
47
48
  from collections import Counter
@@ -69,6 +70,7 @@ FACTS = "facts.jsonl"
69
70
  TIMELINES = "timelines"
70
71
  README = "README.md"
71
72
  MANIFEST = "manifest.sha256"
73
+ MEDIA_DIR = "media"
72
74
  CLIPS = "media/clips"
73
75
  AUDIO = "media/audio"
74
76
 
@@ -238,6 +240,177 @@ def _blank(clip: d.Clip) -> str | None:
238
240
  return None
239
241
 
240
242
 
243
+ @dataclass
244
+ class RetrofitResult:
245
+ """What `add_timelines` made, counted from what was written (issue #213)."""
246
+
247
+ #: How many rows of the source bundle's `items.jsonl`.
248
+ clips: int = 0
249
+ #: Timelines written, one JSONL per clip.
250
+ timeline_written: int = 0
251
+ #: (id, why) for clips whose timeline could not be made.
252
+ timeline_failed: list[tuple[str, str]] = field(default_factory=list)
253
+ #: Rows whose media is missing in the source, or whose copy differs by a byte.
254
+ problems: list[str] = field(default_factory=list)
255
+ #: The sha256 of the source's `manifest.sha256`, as the README names it.
256
+ source_manifest_sha256: str = ""
257
+ #: The sha256 of the new `manifest.sha256`, for the caller to name.
258
+ manifest_sha256: str = ""
259
+
260
+
261
+ def add_timelines(
262
+ source: Path,
263
+ out: Path,
264
+ *,
265
+ timeline: Callable[[Path, Mapping[str, Any]], Sequence[TimelineRecord]] | None = None,
266
+ ) -> RetrofitResult:
267
+ """Write *out* as a copy of the bundle at *source*, plus `timelines/` (issue #213).
268
+
269
+ The media is copied byte for byte, `items.jsonl` and `facts.jsonl` are copied
270
+ unchanged, no clip is re-encoded and nothing is selected again -- the clip and
271
+ its media are what the timeline is about. `README.md` is the record, not a copy:
272
+ it names the source bundle and its `manifest.sha256`. Nothing is written into
273
+ *source*, which stays a read-only input. With no *timeline* callable, the retrofit
274
+ copies the bundle and leaves `timelines/` out; the caller's extractors are the
275
+ same builder `cut --timeline` uses.
276
+ """
277
+ if out.exists() and any(out.iterdir()):
278
+ raise FileExistsError(f"{out} is not empty -- remove it or choose another path.")
279
+
280
+ result = RetrofitResult()
281
+ missing = [
282
+ name
283
+ for name, path in (
284
+ (ITEMS, source / ITEMS),
285
+ (FACTS, source / FACTS),
286
+ (MANIFEST, source / MANIFEST),
287
+ (CLIPS, source / CLIPS),
288
+ )
289
+ if not path.exists()
290
+ ]
291
+ if missing:
292
+ raise ValueError(f"{source} is not an amoral-av bundle: no {', '.join(missing)}")
293
+
294
+ result.source_manifest_sha256 = hashlib.sha256((source / MANIFEST).read_bytes()).hexdigest()
295
+
296
+ out.mkdir(parents=True)
297
+ for name in (ITEMS, FACTS):
298
+ shutil.copy2(source / name, out / name)
299
+ if (source / REVIEW).is_file():
300
+ shutil.copy2(source / REVIEW, out / REVIEW)
301
+
302
+ copied: dict[str, str] = {} # relative under media/ -> sha256 of the source bytes
303
+ for part in ("clips", "audio"):
304
+ src_dir = source / MEDIA_DIR / part
305
+ if not src_dir.is_dir():
306
+ continue
307
+ (out / MEDIA_DIR / part).mkdir(parents=True)
308
+ for media in sorted(src_dir.glob("*")):
309
+ if not media.is_file():
310
+ continue
311
+ shutil.copy2(media, out / MEDIA_DIR / part / media.name)
312
+ copied[f"{part}/{media.name}"] = hashlib.sha256(media.read_bytes()).hexdigest()
313
+
314
+ rows = _read_jsonl(source / ITEMS)
315
+ result.clips = len(rows)
316
+ if timeline is not None:
317
+ (out / TIMELINES).mkdir()
318
+ for row in rows:
319
+ problem = _copy_problem(row, copied)
320
+ if problem:
321
+ result.problems.append(f"{row['id']}: {problem}")
322
+ continue
323
+ try:
324
+ records = timeline(out / MEDIA_DIR / row["path"], row)
325
+ write_records(out / TIMELINES / f"{row['id']}.jsonl", records)
326
+ result.timeline_written += 1
327
+ except Exception as exc: # noqa: BLE001 -- one bad clip, not one bad run
328
+ result.timeline_failed.append((row["id"], str(exc)))
329
+ continue
330
+
331
+ for row in rows:
332
+ if _copy_problem(row, copied):
333
+ continue
334
+ media_out = out / MEDIA_DIR / row["path"]
335
+ if hashlib.sha256(media_out.read_bytes()).hexdigest() != copied[_media_key(row)]:
336
+ result.problems.append(f"{row['id']}: {row['path']} differs from the source")
337
+
338
+ _write_retrofit_readme(out, source, result)
339
+ _write_manifest(out)
340
+ result.manifest_sha256 = hashlib.sha256((out / MANIFEST).read_bytes()).hexdigest()
341
+ return result
342
+
343
+
344
+ def _media_key(row: Mapping[str, Any]) -> str:
345
+ """The `copied` key of a row's clip, which sits under `media/clips`."""
346
+ return f"clips/{PurePosixPath(row['path']).name}"
347
+
348
+
349
+ def _copy_problem(row: Mapping[str, Any], copied: Mapping[str, str]) -> str:
350
+ """Why the copy of *row*'s media is not whole, or "" when it is.
351
+
352
+ `media/` is where the paths of `items.jsonl` start, so a relative goes under
353
+ that.
354
+ """
355
+ for name in ("path", "audio"):
356
+ relative = row.get(name)
357
+ if not relative:
358
+ continue
359
+ if str(relative) not in copied:
360
+ return f"{relative} is missing in the source"
361
+ return ""
362
+
363
+
364
+ def _write_retrofit_readme(out: Path, source: Path, result: RetrofitResult) -> None:
365
+ from importlib.metadata import version # noqa: PLC0415
366
+
367
+ record = {
368
+ "made": datetime.now(UTC).isoformat(timespec="seconds").replace("+00:00", "Z"),
369
+ "source_bundle": str(source),
370
+ "source_manifest_sha256": result.source_manifest_sha256,
371
+ "clips": result.clips,
372
+ "timelines_written": result.timeline_written,
373
+ "timeline_failed": len(result.timeline_failed),
374
+ "problems": len(result.problems),
375
+ "versions": {
376
+ "curu-caption": version("curu-caption"),
377
+ "curu-vision": version("curu-vision"),
378
+ "ffmpeg": _ffmpeg_version(),
379
+ },
380
+ }
381
+ failed = "\n".join(f"| `{name}` | {why} |" for name, why in result.timeline_failed)
382
+ problems = "\n".join(f"| {line} |" for line in result.problems)
383
+ problems_section = f"\n## Problems\n\n| problem |\n|---|\n{problems}\n" if problems else ""
384
+ failed_section = (
385
+ f"\n## Timelines not written\n\nThe models could not read this clip; the rest of "
386
+ f"its bundle row stands.\n\n| id | why |\n|---|---|\n{failed}\n"
387
+ if failed
388
+ else ""
389
+ )
390
+ (out / README).write_text(
391
+ f"""# amoral-av bundle, with timelines
392
+
393
+ Timelines added by `curu-caption timeline` on {record["made"]}.
394
+
395
+ - The clips and the audio of this bundle are byte-for-byte copies of the source
396
+ bundle `{record["source_bundle"]}`. `items.jsonl` and `facts.jsonl` are its rows,
397
+ unchanged. Each `timelines/<id>.jsonl` sits beside them with the records and the
398
+ gates that `cut --timeline` writes.
399
+
400
+ | clip count | timelines written | timelines not written |
401
+ |---|---|---|
402
+ | {result.clips} | {result.timeline_written} | {len(result.timeline_failed)} |
403
+ {problems_section}{failed_section}
404
+ ## Record
405
+
406
+ ```json
407
+ {json.dumps(record, indent=2, sort_keys=True)}
408
+ ```
409
+ """,
410
+ encoding="utf-8",
411
+ )
412
+
413
+
241
414
  def write_bundle(
242
415
  corpus: Corpus,
243
416
  items: Sequence[str],
@@ -248,6 +421,7 @@ def write_bundle(
248
421
  per_clip: int,
249
422
  seed: int,
250
423
  selection: Mapping[str, Any] | None = None,
424
+ limit: int | None = None,
251
425
  at: str | None = None,
252
426
  dry_run: bool = False,
253
427
  timeline: Callable[[Path, Mapping[str, Any]], Sequence[TimelineRecord]] | None = None,
@@ -345,7 +519,9 @@ def write_bundle(
345
519
  _write_jsonl(out / ITEMS, rows)
346
520
  _write_jsonl(out / FACTS, [_facts_row(out, row) for row in rows])
347
521
  _write_readme(out, result, golden=golden, estate_root=estate_root, per_clip=per_clip,
348
- seed=seed, selection=selection or {}, at=at) # fmt: skip
522
+ seed=seed, selection=selection or {}, at=at,
523
+ corpus=str(corpus.root) if corpus is not None else None,
524
+ limit=limit) # fmt: skip
349
525
  write_review(out, rows)
350
526
  _write_manifest(out)
351
527
  result.problems = check_bundle(out, {o.id: o.clip.channels for o in originals})
@@ -505,6 +681,8 @@ def _write_readme(
505
681
  seed: int,
506
682
  selection: Mapping[str, Any],
507
683
  at: str,
684
+ corpus: str | None = None,
685
+ limit: int | None = None,
508
686
  ) -> None:
509
687
  from importlib.metadata import version # noqa: PLC0415
510
688
 
@@ -520,6 +698,8 @@ def _write_readme(
520
698
  "estate_root": str(estate_root),
521
699
  "golden": str(golden),
522
700
  "golden_sources_checked": result.golden_sources,
701
+ "corpus": corpus,
702
+ "limit": limit,
523
703
  "derive_per_clip": per_clip,
524
704
  "seed": seed,
525
705
  "donor_strategy": d.DONOR_STRATEGY,
@@ -36,6 +36,7 @@ RecordType = Literal[
36
36
  "sam3-track",
37
37
  "sync",
38
38
  "active-speaker",
39
+ "speaker-face",
39
40
  ]
40
41
 
41
42
  _RECORD_TYPES: frozenset[str] = frozenset(
@@ -48,6 +49,7 @@ _RECORD_TYPES: frozenset[str] = frozenset(
48
49
  "sam3-track",
49
50
  "sync",
50
51
  "active-speaker",
52
+ "speaker-face",
51
53
  )
52
54
  )
53
55
 
@@ -92,6 +94,25 @@ class Gate:
92
94
  version=entry.version,
93
95
  )
94
96
 
97
+ @classmethod
98
+ def from_measured(cls, entry: Any) -> Gate:
99
+ """The generic form, for an entry whose kind curu-vision names itself.
100
+
101
+ The event builder fixes `kind` to `event`; this one carries the entry's
102
+ own kind, so a `speaker-face` gate keeps saying `speaker-face`.
103
+ """
104
+ return cls(
105
+ kind=str(entry.kind),
106
+ entry_name=entry.name,
107
+ threshold=entry.threshold,
108
+ precision=entry.precision,
109
+ judged=entry.judged,
110
+ measured_on=entry.measured_on,
111
+ repository=entry.repository,
112
+ revision=entry.revision,
113
+ version=entry.version,
114
+ )
115
+
95
116
  @classmethod
96
117
  def from_sync_measured(cls, mt: Any) -> Gate:
97
118
  """From curu-vision's `MeasuredSyncThreshold`: the sync gate (curu-vision#140).
@@ -40,7 +40,7 @@ from pathlib import Path
40
40
  from typing import Any
41
41
 
42
42
  import numpy as np
43
- from curu_vision.audiovisual import MEASURED, measured_threshold
43
+ from curu_vision.audiovisual import MEASURED, measured_link, measured_threshold
44
44
  from curu_vision.embedding import Audio
45
45
  from curu_vision.embedding.port import ItemFailure
46
46
  from curu_vision.media import VideoSource
@@ -311,3 +311,85 @@ class SpeakerExtractor:
311
311
 
312
312
 
313
313
  __all__ = ["SpeakerExtractor", "SyncExtractor"]
314
+
315
+
316
+ class SpeakerLinkExtractor:
317
+ """The speaker-to-face link, one `speaker-face` record per MOSS segment.
318
+
319
+ curu-vision 0.36.0's `link_speakers` reads a video, its 16 kHz sound, its MOSS
320
+ transcript and its face tracks, and answers one `SpeakerLink` per speaker
321
+ segment. The link is measured (curu-vision#141): 35 of 35 links right, with
322
+ precision 1.000 at the sync threshold, and the entry's kind is
323
+ `speaker-face`. A link whose outcome is `face` carries that gate entry; the
324
+ measured sheet judged the linked decisions, and `not-on-screen` and
325
+ `unknown` are the other answers, unmeasured on their own. So their records
326
+ stay selection signals with `gate: null`.
327
+
328
+ The caller gives the MOSS transcript: the transcriber runs `engine='moss'`,
329
+ a different engine from the speech fact's; it is this extractor's first
330
+ argument after the linker, and the CLI transcribes the clip before it calls.
331
+ A transcript whose engine is not MOSS raises `InputError` in the port, which
332
+ surfaces here as an `ExtractionError` naming the transcript, never a silent
333
+ skip (Article X).
334
+ """
335
+
336
+ kind = "speaker-face"
337
+
338
+ def __init__(
339
+ self,
340
+ linker: Callable[..., Any],
341
+ transcript: Callable[[Path], Any],
342
+ *,
343
+ sync: Any = None,
344
+ audio_loader: Callable[[Path], Any] | None = None,
345
+ ) -> None:
346
+ self._linker = linker
347
+ self._transcript = transcript
348
+ self._sync = sync
349
+ self._audio_loader = (
350
+ audio_loader if audio_loader is not None else partial(_samples_of, kind=self.kind)
351
+ )
352
+
353
+ def provenance(self) -> Provenance:
354
+ return Provenance(producer="speaker-link", params={"port": "audiovisual.links"})
355
+
356
+ def extract(self, media: Path, tracks: Any) -> list[TimelineRecord]:
357
+ samples = _samples_for(self.kind, self._audio_loader, media)
358
+ try:
359
+ result = self._linker(
360
+ VideoSource(path=str(media)),
361
+ Audio(np.asarray(samples, dtype=np.float32), _AUDIO_SR),
362
+ self._transcript(samples),
363
+ tracks,
364
+ sync=self._sync,
365
+ )
366
+ except Exception as exc: # noqa: BLE001 -- one bad item, not one bad run
367
+ raise ExtractionError(
368
+ f"{media.name}: the speaker link failed: {describe(exc)}"
369
+ ) from exc
370
+ measured = measured_link(result)
371
+ gate = Gate.from_measured(measured.precision) if measured is not None else None
372
+ # The link's provenance is not the AudioVisualProvenance the other
373
+ # producers name, so the pin carries the link version, which is the pin
374
+ # the measured entry is keyed on.
375
+ producer = {
376
+ "producer": "speaker-link",
377
+ "link_version": str(result.provenance.link_version),
378
+ }
379
+ return [
380
+ TimelineRecord(
381
+ id=media.stem,
382
+ type="speaker-face",
383
+ start_s=link.start,
384
+ end_s=link.end,
385
+ value={
386
+ "speaker": str(link.speaker),
387
+ "track_id": link.track_id,
388
+ "outcome": link.outcome,
389
+ },
390
+ confidence=link.confidence,
391
+ producer=producer,
392
+ gate=gate if (link.outcome == "face" and gate is not None) else None,
393
+ )
394
+ for link in result.links
395
+ ]
File without changes