Skip to content

feat: optional TwelveLabs Pegasus clip selection - #7

Open
mohit-twelvelabs wants to merge 1 commit into
leamsigc:mainfrom
mohit-twelvelabs:feat/twelvelabs-integration
Open

feat: optional TwelveLabs Pegasus clip selection#7
mohit-twelvelabs wants to merge 1 commit into
leamsigc:mainfrom
mohit-twelvelabs:feat/twelvelabs-integration

Conversation

@mohit-twelvelabs

Copy link
Copy Markdown

Hi! I'm Mohit, I work at TwelveLabs (@mohit-twelvelabs).

This PR adds an optional content-selection step that uses TwelveLabs' Pegasus video-understanding model to pick the best B-roll for a Short.

What it adds

  • Backend/twelvelabs_select.py — a small provider module (rerank_clips) that scores each candidate Pexels clip 0-100 for how well it visually matches the video subject and script, then reorders them best-first.
  • Wired into Shorts.DownloadVideos: right after the candidate URLs are gathered (and before download), the list is reranked. Pegasus reads the public Pexels URLs server-side, so there's no upload/index step.
  • Docs: README.md, EnvironmentVariables.md, .env.example, and requirements.txt (twelvelabs>=1.2.8).
  • Tests: Backend/test_twelvelabs_select.py — stdlib unittest, four no-network unit tests plus one live smoke test gated on TWELVELABS_API_KEY.

Why it helps

Today every clip Pexels returns for a search term is treated equally. Pegasus actually watches each candidate and ranks them by relevance to your subject/script, so the most on-topic footage ends up in the Short — better than keyword-match ordering alone.

Opt-in / non-breaking

Disabled unless TWELVELABS_API_KEY is set. When the key is absent (or the SDK/network is unavailable), rerank_clips is a graceful no-op and the original Pexels ordering is used, so existing behaviour is unchanged. It follows the same env-gated optional-provider pattern already used for the TTS engines.

Tested

  • python -m unittest Backend/test_twelvelabs_select.py — 4 unit tests pass (live smoke skipped without a key).
  • Live round-trip against the real API verified: a public ocean-waves Pexels clip scored 90/100 against the subject "ocean waves" with pegasus1.5.

Note on process

The README asks to open an issue first for major changes. This is a small, self-contained, opt-in addition, so I went straight to a PR — happy to open a tracking issue or adjust anything if you'd prefer.

You can grab a free API key at https://twelvelabs.io — there's a generous free tier.

Rerank the Pexels stock-video candidates with the Pegasus
video-understanding model so the most relevant B-roll is used first.
Opt-in via TWELVELABS_API_KEY; when unset the original Pexels ordering
is kept, so existing behaviour is unchanged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant