Commit graph

8 commits

Author SHA1 Message Date
1dec0dd1af chore/dead-code-removal (#4)
All checks were successful
CI / backend-tests (push) Successful in 28s
CI / frontend-build (push) Successful in 20s
Reviewed-on: #4
Co-authored-by: pedro-bento <mail@pbento.pt>
Co-committed-by: pedro-bento <mail@pbento.pt>
2026-10-04 22:11:11 +01:00
719946b3cd refactor/package-layout (#3)
All checks were successful
CI / backend-tests (push) Successful in 29s
CI / frontend-build (push) Successful in 9m48s
Reviewed-on: #3
Co-authored-by: pedro-bento <mail@pbento.pt>
Co-committed-by: pedro-bento <mail@pbento.pt>
2026-10-04 20:47:12 +01:00
juancarlos.cavero
4cc2fe32e0 fix(selection): score every window and enforce the clip floor
A 9:10 source delivered 3 clips in prod where the pipeline had asked
itself for 6-12. Two independent leaks, both in the chain that derives
the clip count.

The scoring pass SELECTED instead of ranking: "choose up to 3 windows
from this batch" put the shortlist ceiling at 3 * n_batches rather than
shortlist_target, so 9 windows batched 8 + 1 shortlisted 4 of a target
of 8, and clip_count_targets then asked the detail pass for 4-8 clips
instead of 6-12. Every source under ~30 min was starved the same way,
which is the mechanism behind "95% of jobs deliver 3 clips or fewer" —
the clip count D2 retention hangs on (0.4% for 1-3 clips, 16.1% for
4-9). It also discarded the ranking it was computing: a batch holding
five great moments could still contribute only three, while a batch of
filler contributed its own three. The prompt now scores every window it
is given and the shortlist is the global top N.

Batches are near-equal instead of "full ones plus the remainder": a
trailing batch of one window came back with that window whatever its
score, because a cap of 3 cannot filter a batch of 1, so the tail of the
video entered the shortlist by arithmetic. Same call count as before.

And the floor was only a sentence in the detail prompt, with nothing in
code checking it, so a pass that returned half shipped half. When it
comes back under min_clips the shortlist windows that produced nothing
get one more call for the difference; an empty answer is accepted,
because padding is worse than a short list.

Measured on that source, same transcript, three runs: shortlist 4 -> 8,
clips 4 -> 6, cost unchanged (~$0.005, 3 calls).
2026-09-23 00:27:14 +02:00
juancarlos.cavero
36dba9b3b1 feat(selection): say why each clip was picked, drop clips that overlap a better one
The detail pass now returns a one-sentence `why` per clip (what makes this
moment a clip, not the topic), stored in the metadata and shown under the
title in the dashboard card: the score said how much, nothing said why.
Defaulted in the schema so a small local model that skips it keeps the clip.

After the word snap, clips overlapping an already-kept clip by half the
shorter one are dropped in favour of the higher predicted_score. The prompt's
DIVERSITY rule was the only thing preventing the same moment twice; in ~330
clips over 8 talks it never fired, so this is a guard, not a fix.

Each clip also keeps the model's raw `proposed` boundaries before the snap,
which is what made boundary accuracy measurable: p90 0.4-0.5 s from a word
on 8 talks (21-sep-2026), inside snap_clip_to_words' 1.5 s reach.

Two ideas borrowed from AutoClip were measured with a blind judge on the
same corpus and NOT adopted: quoting per-sentence timestamps in the detail
pass lost 24%/23% (p<0.001, two seeds — it shortens clips and drops the
payoff), and an "end on the reaction, not the line" rule was inert
(47%/53%, p=0.71).
2026-09-21 22:47:55 +02:00
juancarlos.cavero
4a137005ca fix(selection): trim the detail pass by score, not by position
The detail pass returns its clips in transcript order, batch after batch, and
the overflow was cut with shorts[:max_clips] — which keeps the EARLIEST clips
and drops the tail. On a 9m19s walkthrough, three runs of the same source put
every surviving clip inside the first 2m40s, 4m39s and 8m55s respectively; the
demo, the MCP walkthrough and the close were simply the part of the list that
fell off the end. The failure scales the wrong way, too: the more clips the
model proposes, the more of the video disappears (output tokens 2067 -> 8m55s
of coverage, 3407 -> 2m40s).

It also undoes the windowing. get_viral_clips builds scoring windows precisely
because "a single call over the whole transcript clusters picks near the
start", and a positional slice puts that clustering straight back. Pass 1
already sorts by score before its own cut; pass 2 just never did.

trim_to_best ranks by predicted_score, which the detail prompt has always
asked for and nothing here was reading, and returns the survivors in
transcript order so clip numbering still runs front to back.

Claude-Session: https://claude.ai/code/session_01KeQYCfUX2E9Q2fDgZMKEaJ
2026-08-29 01:42:45 +02:00
juancarlos.cavero
b81125c572 feat(generate): manual clip count and duration controls (discussion #65)
/api/process (and the process_video MCP tool) now accept optional
target_clips (1-15) and clip_min_seconds / clip_max_seconds (5-180),
surfaced in the dashboard as a collapsed 'advanced options' section.
Blank means the AI decides, keeping the default request byte-identical.

Plumbed through the same env overrides the A/B harness already reads:
CLIP_TARGET_MIN/MAX (existing) and a new clip_duration_bounds() in
clip_selection.py backing CLIP_MIN_SECONDS/MAX_SECONDS. The detail and
visual prompts take the band as template placeholders instead of the
hardcoded 15-60, and word-snapping enforces the same bounds. All three
knobs are honest targets, not guarantees: the model still returns fewer
clips when the material doesn't hold them, and the UI copy says so.

Verified live: target_clips=2 + band 8-15s on the demo video returned
exactly 2 clips of 13.3s and 13.7s (the uncontrolled run gave one 41.7s
clip); out-of-range values 400 with a named reason.
2026-08-18 19:21:42 +02:00
juancarlos.cavero
18f2cf4dbd feat(selection): put a floor under the clip count
Prod measurement, 3-ago-2026: 408 of 429 jobs (95%) delivered three clips or
fewer, the mode being ONE. Cross-referenced against retention on the cohort
that signed up 3-7 days ago (old enough to have returned, recent enough that
the 7-day purge has not deleted their user_videos rows):

    clips delivered   users   came back a 2nd day
    1-3                 251   0.4%
    4-9                  31   16.1%

Forty times the retention on the far side of a boundary that 95% of jobs never
crossed. That is the mechanism behind the 96.7% of users who only ever use the
product on a single day.

The shortlist was not the constraint — a 5-minute video already shortlists 5
windows. The detail prompt was: it asked to "prefer one great clip per
candidate window", and both the 2-second rule and STANDS ALONE end in "or skip
it" with no lower bound, as does DIVERSITY's "drop the other". Three rules
pushing down and nothing holding the count up collapses to one clip.

clip_count_targets() now derives a floor and a ceiling from the shortlist size
(3 windows -> 3-6, 5 -> 4-10, 10+ -> 6-12) and the prompt states it. Every
quality rule is untouched — they are validated at 82% against random windows
and this change does not spend that.

A/B on 8 real prod transcripts (3.5-18 min, all of which delivered 1-3 clips in
production), sharing the score pass between variants so only the detail prompt
differs:

    OLD  mean 2.75  median 2.5  <=3 clips: 6/8
    NEW  mean 4.00  median 4.0  <=3 clips: 3/8
    better on 7 of 8, worse on none, one tie (sign test p = 0.016)

The ceiling never bound: the most any video produced was 5 against a ceiling of
8-12, so the model is not padding to hit a number — the floor and the removal
of the one-per-window bias are doing the work. That is the outcome to want.

Read the limits honestly. Three of eight still land at three or fewer, and the
sample under-represents the sub-5-minute videos that are 54% of real jobs and
the hardest case here: both short videos in the set shortlisted only 2 windows
out of the 3-4 that existed, because the SCORE pass returned fewer usable
windows than it was given. That is the next thing to look at, and it caps this
change on exactly the videos that matter most.

CLIP_TARGET_MIN / CLIP_TARGET_MAX override both bounds for further A/B runs
without a deploy.
2026-08-03 11:17:33 +02:00
juancarlos.cavero
b3e44643cc feat: 2-pass Gemini clip pipeline (score windows -> detail shortlist)
Replaces the single whole-transcript call with windowed scoring + focused
detailing (from PR #50), for better clip coverage on long videos:

- clip_selection.py: build_transcript_windows (sentence-aligned overlapping
  windows), snap_clip_to_words (cuts land in pauses, not mid-word), model
  price table.
- gemini_worker.py: score/detail prompts + Pydantic response schemas + robust
  JSON parsing and multi-stage cost accounting (incl. thinking tokens).
- main.py get_viral_clips: pass 1 scores windows in batches and shortlists the
  top (scaled by duration); pass 2 details the shortlist; every clip is snapped
  to word boundaries. Cost is summed across both passes. Falls back to
  whole-video conversion (caller) if it yields nothing.
- 13 clip_selection unit tests (63 total).
2026-07-17 22:32:04 +02:00